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 00037 package theoremprover; 00038 00039 import java.lang.*; // Java language classes 00040 import java.util.*; // Java util.. 00041 00042 import theoremprover.*; 00043 00044 public class Proposition extends Assumption 00045 implements PropositionInterface 00046 { 00047 00048 // Instance variables ... 00049 00050 protected ArrayList succedence; 00051 protected PropositionalRule activeRule; 00052 protected ArrayList support; 00053 00054 // Instance creation and initialization 00055 00056 Proposition () 00057 { 00058 super(); 00059 identifier = null; 00060 succedence = new ArrayList(); 00061 antecedence = new ArrayList(); 00062 label = false; 00063 activeRule = null; 00064 support = new ArrayList(); 00065 } 00066 00067 // Accessing 00068 00069 public ArrayList succedence () 00070 { 00071 return succedence; 00072 } 00073 00074 public PropositionalRule activeRule () 00075 { 00076 return activeRule; 00077 } 00078 00079 public ArrayList support () 00080 { 00081 return support; 00082 } 00083 00084 00085 // Accessing and maintaining structure 00086 00087 public void addSuccedence(PropositionalRule r) 00088 { 00089 succedence.add(r); 00090 } 00091 00092 public void activeRule(PropositionalRule r) 00093 { 00094 activeRule = r; 00095 } 00096 00097 public void addSupport (PropositionalRule r) 00098 { 00099 support.add(r); 00100 } 00101 00102 public void removeSupport (PropositionalRule r) 00103 { 00104 support.remove(r); 00105 } 00106 00107 public boolean updateActiveRule() { 00108 if (support.size() > 0) { 00109 activeRule = (PropositionalRule)support.get(0); 00110 return true; 00111 } else { 00112 return false; 00113 } 00114 } 00115 00116 // Testing... 00117 00118 public boolean isAssumption () 00119 { 00120 return false; 00121 } 00122 00123 // Theorem proving... 00124 00125 public ArrayList propagateFalse(ArrayList v) 00126 { 00127 if (label == true) { 00128 label = false; 00129 activeRule = null; 00130 v.add(this); 00131 Iterator e = antecedence.iterator(); 00132 while (e.hasNext()) { 00133 PropositionalRule r = (PropositionalRule)e.next(); 00134 r.counter(r.counter()+1); 00135 Proposition p = (Proposition)r.succedence(); 00136 p.removeSupport(r); 00137 if (p.activeRule() == r) { 00138 v = p.propagateFalse(v); 00139 } 00140 } 00141 } 00142 return v; 00143 } 00144 00145 public void correctLabels() 00146 { 00147 if (label == false) { 00148 if (support.size() > 0) { 00149 PropositionalRule r = (PropositionalRule)support.get(0); 00150 activeRule = r; 00151 label = true; 00152 propagateTrue(); 00153 } 00154 } 00155 } 00156 00157 // Return the set of assumptions causing self to be true. 00158 public ArrayList collectAssumptions() { 00159 ArrayList result = new ArrayList(); 00160 if (label == true) { 00161 return collectAssumptions(result); 00162 } else { 00163 return result; 00164 } 00165 } 00166 00167 public ArrayList collectAssumptions(ArrayList assumptions) { 00168 if (activeRule != null) { 00169 Iterator e = (activeRule.antecedence()).iterator(); 00170 while (e.hasNext()) { 00171 ((Assumption)e.next()).collectAssumptions(assumptions); 00172 } 00173 } 00174 return assumptions; 00175 } 00176 00177 public TreeSet collectAllAssumptions() { 00178 TreeSet result = new TreeSet(); 00179 if (label == true) { 00180 return collectAllAssumptions(result); 00181 } else { 00182 return result; 00183 } 00184 } 00185 00186 public TreeSet collectAllAssumptions(TreeSet assumptions) { 00187 00188 Iterator itRule = support.iterator(); 00189 while(itRule.hasNext()) { 00190 PropositionalRule r = (PropositionalRule)itRule.next(); 00191 Iterator e = (r.antecedence()).iterator(); 00192 while (e.hasNext()) { 00193 ((Assumption)e.next()).collectAllAssumptions(assumptions); 00194 } 00195 } 00196 00197 return assumptions; 00198 } 00199 }