import java.util.*; /** * This class decides whether a Boolean Expression of the form (A1^A2^...^An) is satisfiable * Atoms A1,A2... are of the form (x op c) or (x op y) * The algorithm is adopted from Rosenkrantz and Hunt's algo. given in "Processing conjunctive predicates and queries" * * Brief steps: * It adjusts the lower and upper bounds of all variable involved in the expression * Creates a hierarchal graph of variables based on the operators "<", ">" present between two variables in an Atom A1 * */ public class Satisfy { private Vector type1; private Vector type2; public Satisfy() {} public Satisfy(Vector type1, Vector type2) {this.type1 = type1; this.type2 = type2;} public Satisfy(Vector type0) { // we need to seggregate type1 and type2 vectors type1 = new Vector(); type2 = new Vector(); for(int i=0;i= m * Output a Vector of Atoms with range defined (lower and upper bound) * Number of output atoms = m (one entry per variable) */ public Vector adjustRange(Vector inputVector ) { /* get a list of unique variables present in the inputVector and put them in a Hashtable * to do this, iterate over the inputVector. if variable already present in Hashtable, adjust range * else add the new variable to the hashtable */ Hashtable lookupTable = new Hashtable(); Atom tempAtom,listAtom ; for(int i=0;i")).hashCode(); 1983 int ge = (new String(">=")).hashCode(); 1922 int ne = (new String("<>")).hashCode(); // this may create problem.. just added here 1444 int n = (new String("-1")).hashCode(); */ tempAtom = (Atom)lookupTable.remove(listAtom.getOperand1()); switch(listAtom.getOperator().hashCode()) { case 61: //System.out.println("matches = "); tempAtom.setRange(listAtom.getConstant(),listAtom.getConstant()); break; case 60 : //System.out.println("matches < "); tempAtom.setRange(tempAtom.getLeft(),min(tempAtom.getRight(),listAtom.getConstant()-1)); break; case 1921: //System.out.println("matches <= "); tempAtom.setRange(tempAtom.getLeft(),min(tempAtom.getRight(),listAtom.getConstant())); break; case 62 : //System.out.println("matches > "); tempAtom.setRange(max(tempAtom.getLeft(),listAtom.getConstant()+1),tempAtom.getRight()); break; case 1983: //System.out.println("matches >= "); tempAtom.setRange(max(tempAtom.getLeft(),listAtom.getConstant()),tempAtom.getRight()); break; default: System.out.println("Invalid operator: AdjustRange method : in class Satisfy. Will use default range defined in class Atom"); break; } lookupTable.put(tempAtom.getOperand1(),tempAtom); } else { lookupTable.put(listAtom.getOperand1(),listAtom); i--; // this is the biggest gamble // essentially we process the list element again. // first time we enter the Atom in the Hashtable and second time we adjust its range } } Vector outputVector = new Vector(); outputVector.addAll((Collection) lookupTable.values()); return outputVector; } public int min(int a, int b) { if(a<=b) return a; else return b; } public int max(int a, int b) { if(a>=b) return a; else return b; } // check if the range is valid ... meaning (Left <= Right) public boolean checkRange(Vector in) { Atom at; for(int i=0;i at.getRight()) return false; } return true; } public void PRINT(Vector printout) { for(int i=0;i= y) Atom dupl = (Atom) lookupTable.get(listAtom.getOperand1()); if(listAtom.getOperand2() == dupl.getOperand2()) { // here we have 2 predicates having the same operands selectOne(listAtom,dupl); } } else { lookupTable.put(listAtom.getOperand1(),listAtom); //operandInt.put(listAtom.getOperand1(),new Integer(dim)); //dim++; } if(lookupTable.containsKey(listAtom.getOperand2())) { } else { lookupTable.put(listAtom.getOperand2(),listAtom); //operandInt.put(listAtom.getOperand2(),new Integer(dim)); //dim++; } } // iterate over the type1 vector and copy its range to the Atoms present in lookupTable // NOTE: there could be variables in type1 not in type2...... we accomodate this condition for(int i=0;i")); String le = (new String("<=")); String ge = (new String(">=")); String op1,op2,oper; for(int i=0;i" current.setRange(lower, current.getRight()); intAtom.put(new Integer(i),current); //set bound // continue } } mark[i] = 1; // set mark } } }