Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
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     
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     
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 
00074 
00075 
00076 
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 
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 
00121 
00122     public final Collection getModesDF() {
00123         return dfModes.values();
00124     }
00125 
00126     
00127 
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 
00178 
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     } 
00217 
00218 }