package edu.neu.ccs.evergreen.model; /** * Tracks all of the constraints that have been reduced in the system. */ public class Reductions { private int reductions[]; private int constraintCount; /** * Create a new reduction holder with the given size. * * @param constraintCount * Number of constraints to track. */ public Reductions(int constraintCount) { this.constraintCount = constraintCount; reductions = new int[constraintCount]; } /** * @see java.lang.Object#clone() */ public Reductions clone() { Reductions newReductions = new Reductions(constraintCount); System.arraycopy(reductions, 0, newReductions.reductions, 0, reductions.length); return newReductions; } /** * Add another reduction mapping. * * @param constraint * Reduction to add * @param reducedRelationNumber * New relation number for the constraint */ public void addReduction(Constraint constraint, int reducedRelationNumber) { if (reducedRelationNumber == 0) { reducedRelationNumber = -1; } reductions[constraint.getID()] = reducedRelationNumber; } /** * Return the reduction in play for the given constraint. * * @param constraint * Constraint to find reduction for * @return Relation number for the constraint */ public int getRelationNumber(Constraint constraint) { int reducedRelationNumber = reductions[constraint.getID()]; if (reducedRelationNumber == 0) { return constraint.getRelationNumber(); } if (reducedRelationNumber == -1) { return 0; } return reducedRelationNumber; } }