/* * CSP Project * Authors: * Jay Bernardo * Matt Rancourt * * File: TransitionAssignment.java * * Contains the TransitionAssignment class. This class functions for the purpose * of representing what we call "M". It contains a list of TransitionAssignmentVariables * and is able to determine whether it contains a decided variable or not * */ import java.util.*; class TransitionAssignment{ ArrayList M; boolean containsADecidedVariable; /** * Basic constructor */ public TransitionAssignment(){ M = new ArrayList(); containsADecidedVariable = false; } /** * Returns how many variables are contained within the assignment * @return number of variables in the assignment as int */ public int numberOfVariables(){ return M.size(); } /** * Returns a list of the decision variables in M, but negated (as Variable type) * @return negated list of decision variables in M as Variable type * @throws InvalidVariableValueException */ public ArrayList getNegatedDecidedVariables() throws InvalidVariableValueException{ ArrayList list = new ArrayList(); Iterator it = M.iterator(); while(it.hasNext()){ TransitionAssignmentVariable v = it.next(); if(v.decided == true){ boolean pos; if(v.getValue() == 0){ pos = true; } else{ pos = false; } list.add(new Variable(v.getName(), -1, pos)); } } return list; } /** * Returns the TransitionVariableAssignment at a given position (indexing starts at 0) * @param index - variable position * @return TransitionAssignmentVariable at the given position */ public TransitionAssignmentVariable getVariableAt(int index){ return M.get(index); } /** * Adds the given TransitionAssignmentVariable to the list of variables in * the assignment * @param a - TransitionVariableAssignment to add to the overall assignment */ public void add(TransitionAssignmentVariable a){ M.add(a); if(a.decided == true){ containsADecidedVariable = true; } } /** * Resets the assignment, removing all variables and setting the * state of containing a decided variable to false */ public void reset(){ M = new ArrayList(); containsADecidedVariable = false; } }