Basically i need to read in a proposition from a file - ie abc*~a~b~c where * is an and (&) sign ~ is a not (!) sign and the letters are all or(ed) (||) so basically i need to find out whether the above sentence is true or false. in this case it would be: a or b or c and not a or not b or not c The textfile that we must use looks like this: 3 2 abc*~a~b~c*
where 3 is the number of variables and 2 the number of clauses.
here is my code so far:
import java.io.*;
public class SATProblem{
private int variable; private int clause; private char[] data;
private void Stringreader(){
String line = "";
String file = "testfile.txt";
try { FileReader fr = new FileReader(file); BufferedReader inFile = new BufferedReader(fr);
for (int pos = 0; pos < variable; pos++){ test [pos] = getBoolean(n,pos); System.out.println(test[pos]); }
if (validateSent(test)){ answer = true; break; } } } public boolean validateSent(boolean test[]){
int count = 0;
while (count <= variable){
for (int i = 0; i <= data.length; i++){
if (data[i] != '~'){ if (test[count]) data[i] = true;
}
} } }
public static void main (String[] args){
SATProblem abc = new SATProblem(); abc.Stringreader(); abc.startAnalysis(); }
}
startAnalysis and getBoolean basically construct the truth table where for three variables when n = 0,test[0] = false, test[1] = false, test[2] = false when n = 1,test[0] = false, test[1] = false, test[2] = true when n = 1,test[0] = false, test[1] = true, test[2] = true ETC you get the idea. Do u think u could help? Thanks a lot again COurtz