Component.java
Go to the documentation of this file.
00001 /*
00002  * (c) copyright 2008, Technische Universitaet Graz and Technische Universitaet Wien
00003  *
00004  * This file is part of jdiagengine.
00005  *
00006  * jdiagengine is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * jdiagengine is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with jdiagengine. If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Authors: Joerg Weber, Franz Wotawa
00019  * Contact: jweber@ist.tugraz.at (preferred), or fwotawa@ist.tugraz.at
00020  *
00021  */
00022 
00023 
00024 package dfengine;
00025 
00026 import java.util.*;
00027 
00028 import utils.*;
00029 import theoremprover.Assumption;
00030 
00031 public class Component implements Comparable {
00032 
00033     protected String name;
00034 
00035     // internally used; assigned by DiagnosisProblem
00036     protected int id = -1;
00037 
00038     protected FailureDepNode fdNode;
00039 
00040     protected Mode mode_nab;
00041     protected Mode mode_ab;
00042     protected Mode mode_if;
00043 
00044     // map from Component to Mode
00045     protected TreeMap dfModes = new TreeMap();
00046 
00047     protected double prob_if = -1.0;
00048 
00049 
00050     public Component(String name, int id) {
00051         this.name = name;
00052         this.id = id;
00053     }
00054 
00055     public Component(String name, int id, double prob_if) {
00056         this(name, id);
00057         this.prob_if = prob_if;
00058     }
00059 
00060     public boolean equals(Object o) {
00061         return (this == o);
00062     }
00063 
00064     public final FailureDepNode getFDNode() {
00065         return fdNode;
00066     }
00067 
00068     public final double getProbIF() {
00069         return prob_if;
00070     }
00071 
00072     /*
00073      * Returns a mode of this component with the passed modeType.
00074      *
00075      * If modeType = Mode.MODE_DF, then a mode of the form DF(this, parent) is returned.
00076      * Otherwise, parent is ignored.
00077      */
00078     public final Mode getMode(int modeType, Component parent) {
00079         
00080         switch (modeType) {
00081             case Mode.MODE_AB: return mode_ab;
00082             case Mode.MODE_NAB: return mode_nab;
00083             case Mode.MODE_IF: return mode_if;
00084             case Mode.MODE_DF: {
00085                 Object res = dfModes.get(parent);
00086                 assert(res != null);
00087                 return (Mode)res;
00088             }
00089             default: assert(false); return null;
00090         }
00091     }
00092     
00093     public final Mode getModeAB() {
00094         return mode_ab;
00095     }
00096 
00097     public final Mode getModeNAB() {
00098         return mode_nab;
00099     }
00100 
00101     public final Mode getModeIF() {
00102         return mode_if;
00103     }
00104 
00105     /*
00106      * Returns a mode of the form DF(this, parent)
00107      */
00108     public final Mode getModeDF(Component parent) {
00109         Object res = dfModes.get(parent);
00110         assert(res != null);
00111 
00112         return (Mode)res;
00113     }
00114 
00115     public boolean hasFDGParent(Component parent) {
00116         return (dfModes.get(parent) != null);
00117     }
00118 
00119     /*
00120      * Returns modes DF(this, parent) for all FDG parents of this.
00121      */
00122     public final Collection getModesDF() {
00123         return dfModes.values();
00124     }
00125 
00126     /*
00127      * For debugging.
00128      */
00129     public String toString() {
00130         StringBuffer res = new StringBuffer("component \"" + name + "\":" + "\n");
00131         res.append("ID: " + id);
00132         res.append("\n");
00133         res.append(mode_nab.toString());
00134         res.append("\n");
00135         res.append(mode_ab.toString());
00136         res.append("\n");
00137         res.append(mode_if.toString());
00138         res.append("\n");
00139 
00140         if (dfModes != null) {
00141             Iterator it = dfModes.values().iterator();
00142             while (it.hasNext()) {
00143                 Mode m = (Mode)it.next();
00144                 res.append(m.toString());
00145                 res.append("\n");
00146             }
00147             
00148         }
00149         
00150         return res.toString();
00151     }
00152 
00153     public int compareTo(Object o) {
00154         Component other = (Component)o;
00155 
00156         assert(id >= 0);
00157         assert(other.id >= 0);
00158 
00159         if (this.id < other.id) return -1;
00160         else if (this.id == other.id) return 0;
00161         else return +1;
00162     }
00163 
00164     public final String getName() {
00165         return name;
00166     }
00167 
00168     public final int getID() {
00169         return id;
00170     }
00171 
00172     protected String createAss(String predicate) {
00173         return predicate + "(" + name + ")";
00174     }
00175 
00176     /*
00177      * Initializes the mode variables of this component. 
00178      * Parameter "assumptions" is a Map from String to Assumption
00179      */
00180     public void initFromFDG(Map assumptions, 
00181                             String assAB, String assNAB, String assIF,
00182                             String assDF) {
00183          
00184         String ass = createAss(assAB);
00185         Object o = assumptions.get(ass);
00186         Assumption a = null;
00187         if (o != null) a = (Assumption)o;
00188         mode_ab = new Mode(Mode.MODE_AB, this, a);
00189 
00190         ass = createAss(assNAB);
00191         o = assumptions.get(ass);
00192         a = null;
00193         if (o != null) a = (Assumption)o;
00194         mode_nab = new Mode(Mode.MODE_NAB, this, a);      
00195 
00196         ass = createAss(assIF);
00197         o = assumptions.get(ass);
00198         a = null;
00199         if (o != null) a = (Assumption)o;
00200         mode_if = new Mode(Mode.MODE_IF, this, a); 
00201 
00202         Iterator itPar = fdNode.getParentsIterator();
00203         while (itPar.hasNext()) {
00204             FailureDepNode parent = (FailureDepNode)itPar.next();
00205             Component parComp = parent.getComponent();
00206             ass = assDF + "(" + name + ", " + parComp.getName() + ")"; 
00207             ass = assDF + "(" + parComp.getName() + ", " + name + ")"; 
00208             o = assumptions.get(ass);
00209             a = null;
00210             if (o != null) a = (Assumption)o;
00211             
00212             Mode mode = new Mode(Mode.MODE_DF, this, parComp, a);
00213             dfModes.put(parComp, mode);
00214         }
00215     
00216     } // initFromFDG()
00217 
00218 }


tug_ist_diagnosis_engine
Author(s): Safdar Zaman, Gerald Steinbauer
autogenerated on Mon Jan 6 2014 11:51:16