PropositionalTheoremProver.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 
00036 package theoremprover;
00037 
00038 import java.lang.*;    // Java language classes 
00039 import java.awt.*;     // User Interface components
00040 import java.io.*;      // IO specific classes (File, Stream,..)
00041 import java.awt.event.*;   // Event handling
00042 import java.util.*;    // Java util
00043 
00044 import theoremprover.*;
00045 
00046 
00047 public class PropositionalTheoremProver extends Object
00048 {
00049 
00050   // Instance variables ...
00051 
00052   protected ArrayList rules;
00053   protected ArrayList facts;
00054   protected ArrayList propositions;
00055   protected Proposition contradiction;
00056 
00057   // Instance creation and initialization
00058 
00059   PropositionalTheoremProver ()
00060   {
00061     rules = new ArrayList();
00062 
00063 
00064     facts = new ArrayList();
00065     propositions = new ArrayList();
00066     contradiction = new Proposition();
00067     contradiction.setIdentifier("false");
00068   }
00069 
00070   // Accessing
00071 
00072   public ArrayList rules ()
00073   {
00074     return rules;
00075   }
00076 
00077   public ArrayList facts ()
00078   {
00079     return facts;
00080   }
00081 
00082   public ArrayList propositions ()
00083   {
00084     return propositions;
00085   }
00086 
00087   public Proposition contradiction ()
00088   {
00089     return contradiction;
00090   }
00091 
00092   // Accessing and maintaining structure
00093 
00094   public void addRule(PropositionalRule r)
00095   {
00096     rules.add(r);
00097   }
00098 
00099   public void addFact(PropositionalRule r)
00100   {
00101     facts.add(r);
00102   }
00103 
00104   public void addProposition(Proposition p)
00105   {
00106     propositions.add(p);
00107   }
00108 
00109   // Testing
00110 
00111   public boolean isConsistent ()
00112   {
00113     return (contradiction.getLabel() == false);
00114   }
00115 
00116 
00117   // Printing...
00118 
00119   public String toString()
00120   {
00121     StringBuffer str = new StringBuffer();
00122     Iterator e = facts.iterator();
00123     str.append("Facts:\r\n");
00124     while (e.hasNext()) {
00125       str.append((e.next()).toString());
00126       str.append("\r\n");
00127     }
00128     e = rules.iterator();
00129     str.append("Rules:\r\n");
00130     while (e.hasNext()) {
00131       str.append((e.next()).toString());
00132       str.append("\r\n");
00133     }
00134     return str.toString();
00135   }
00136 
00137   // Public accessing
00138 
00139   // Add a new rule or fact to the theorem prover and check consistency
00140   // It is assumed that all propositions used are added to my
00141   // list of propositions before calling the add method.
00142   public void add(ArrayList a, Proposition p)
00143   {
00144     PropositionalRule newRule = new PropositionalRule();
00145     int i = a.size();
00146 
00147     if(i > 0) {
00148       addRule(newRule);
00149     } else {
00150       addFact(newRule);
00151     }
00152     p.addSuccedence(newRule);
00153     newRule.succedence(p);
00154     Iterator e = a.iterator();
00155     while (e.hasNext()) {
00156       Proposition ap = (Proposition)e.next();
00157       ap.addAntecedence(newRule);
00158       newRule.addToAntecedence(ap);
00159       if (ap.getLabel() == true) {
00160         i = i - 1;
00161       }
00162     }
00163     newRule.counter(i);
00164     if (i == 0) {
00165       if (p.getLabel() != true) {
00166         p.setLabel(true);
00167         p.activeRule(newRule);
00168         // Propagate truth value
00169         p.propagateTrue();
00170       }
00171     }
00172   }
00173 
00174 
00175   // Remove rule or fact requires a recomputation of the truth values
00176   public void remove (PropositionalRule r)
00177   {
00178     // Remove rule or fact from my collections...
00179     if ((r.antecedence()).size() == 0) {
00180       facts.remove(r);
00181     } else {
00182       rules.remove(r);
00183     }
00184 
00185     // Remove related links...
00186     Proposition s = (Proposition)r.succedence();
00187     (s.succedence()).remove(r);
00188     s.removeSupport(r);
00189     Iterator e = (r.antecedence()).iterator();
00190     while (e.hasNext()) {
00191       Assumption a = (Assumption)e.next();
00192       (a.getAntecedence()).remove(r);
00193     }
00194 
00195     // Change truth values if necessary...
00196     if (s.activeRule() == r) {
00197       ArrayList v = new ArrayList();
00198       v = s.propagateFalse(v);
00199       Iterator ve = v.iterator();
00200       while (ve.hasNext()) {
00201         Proposition p = (Proposition)ve.next();
00202         p.correctLabels();
00203       }
00204     }
00205   }
00206 
00207   // Checks consistency 
00208   public boolean checkConsistency ()
00209   {
00210     return isConsistent();
00211   }
00212 
00213 }


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