The Artima Developer Community
Sponsored Link

Java Answers Forum
boolean error

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Courtenay

Posts: 23
Nickname: courtz
Registered: Apr, 2003

boolean error Posted: May 26, 2003 9:59 AM
Reply to this message Reply
Advertisement
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);




variable = Integer.parseInt(inFile.readLine());
clause = Integer.parseInt(inFile.readLine());

data = (inFile.readLine()).toCharArray();

//data = (inFile.readLine()).toCharArray();


inFile.close();
}

catch (FileNotFoundException e)
{
System.out.println(e);
}
catch (IOException e)
{
System.out.println(e);
}

System.out.println(data);
System.out.println(variable);
System.out.println(clause);
}

public boolean getBoolean(int n, int pos){
pos = variable - pos;
int temp = (int)(n/Math.pow(2,(pos-1))% 2);
if (temp == 1) return true;
else return false;
}

private void startAnalysis(){
boolean test[] = new boolean[variable];
boolean answer = false;

for (int n = 0; n < Math.pow(2, variable); n++){

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

Topic: Converting applet into standalone application Previous Topic   Next Topic Topic: Flicker with my gif image

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use