/* * CSP Project * Authors: * Jay Bernardo * Matt Rancourt * * File: SolveState.java * * Contains the SolveState class. This is a transition that determines whether * the formula is solved or not * */ class SolveState extends Transition{ /** * Basic constructor * @param M - assignment * @param F - formula */ public SolveState(TransitionAssignment M, CSP F){ super(M, F); } /** * Determines if every Relation in F is satisfied by the assignment * in M * * @return -1 if not Solved * 1 if Solved * */ public int doTransition() throws InvalidVariableValueException, RelationNumberOutOfBoundsException, RankOutOfBoundsException, InvalidVariableNamesLengthException, VariablePositionOutOfBoundsException{ // Assign every variable int i = 0; for(; i < M.numberOfVariables(); i ++){ F.setVariable(M.getVariableAt(i).getName(), M.getVariableAt(i).getValue()); } // If any of them are not satisfied then the entire formula // is not satisfied -- immediately return the failure code for(i = 0; i < F.numberOfRelations(); i ++){ Relation r = F.getRelationAt(i); if(r.isSatisfied() == false){ return -1; } } return 1; } }