package OT; import java.util.*; /** * Abstract constraint. * @version 1999-03-31 * @author Andrea Heiberg, University of Arizona */ public abstract class Constraint implements Cloneable { protected boolean global; protected Edge edge; protected FeatureType featureType1; protected FeatureType featureType2; public Constraint(FeatureType featureType1, FeatureType featureType2, Edge edge, boolean global) { this.featureType1 = featureType1; this.featureType2 = featureType2; this.edge = edge; this.global = global; } //end constructor /** Culls Gen operations as appropriate for this constraint. **/ abstract Gen cullGen(Gen gen); /** Calculates the number of times that candidate violates this constraint. */ abstract Integer evaluate(Representation candidate, Representation input); /** Returns the optimal candidates on this constraint from currentCandidates. **/ public Vector getOptimalCandidates(Vector currentCandidates, RepresentationSet allCandidates) { Vector newOptimalCandidates = new Vector(); int violations; int candidateViolations; Vector optimalCandidates = (Vector)currentCandidates.clone(); //if there is only one candidate, it's the optimal candidate if (optimalCandidates.size()>1) { violations = 1000000; //set to a really big number for (Enumeration e = optimalCandidates.elements(); e.hasMoreElements();) { String key = (String)e.nextElement(); Representation candidate = (Representation)allCandidates.get(key); candidateViolations = candidate.getViolations(this).intValue(); if (candidateViolations==-1) { candidate.debug.write(this + ", c" + key + ": " + candidateViolations); } else if (candidateViolations==violations) { //tie; add to set newOptimalCandidates.addElement(key); } else if (candidateViolations < violations) { //this one is better than the ones we're already collected newOptimalCandidates.removeAllElements(); newOptimalCandidates.addElement(key); violations = candidateViolations; } //end if } //end for optimalCandidates = (Vector)newOptimalCandidates.clone(); } //end if optimalCandidates.trimToSize(); return optimalCandidates; } //end getOptimalCandidates }