edu.washington.cs.supple.render.utility
Class FactorConstraint

java.lang.Object
  extended byedu.washington.cs.supple.render.utility.FactorConstraint

public class FactorConstraint
extends java.lang.Object

Author:
kgajos

Field Summary
protected  int[] factorIndices
           
protected  java.util.ArrayList factorNames
           
protected  java.util.Hashtable factors
           
protected  double[] factorValues
           
protected  java.lang.String lhsWidgetName
           
protected  java.lang.String rhsWidgetName
           
 
Constructor Summary
  FactorConstraint(Solution bad, Solution good, FactoredCostFunction costFunction)
           
protected FactorConstraint(java.lang.String lhsFactorName, double lhsFactorValue, java.lang.String rhsFactorName, double rhsFactorValue)
           
  FactorConstraint(SuppleType type, UiObject uiObject, java.util.Collection lhsFactors, WidgetDescriptor lhsWidget, java.util.Collection rhsFactors, WidgetDescriptor rhsWidget)
           
 
Method Summary
protected  void addFactor(java.lang.String name, double value, boolean isBad)
           
protected  void addFactor(SuppleType type, UiObject uiObject, WidgetDescriptor descriptor, Factor factor, boolean isBad)
           
protected  void addFactors(SuppleType type, UiObject uiObject, WidgetDescriptor descriptor, FactoredCostFunction costFunction, boolean isBad)
           
static int containsEquivalentConstraint(java.util.Vector constraints, FactorConstraint c)
          Checks if a constraint equivalent to c exist in vector constraints.
protected  void ensureFactorIndices(FactoredCostFunctionState state)
           
protected  double getConstraintValue(FactoredCostFunctionState state)
           
protected  double getFactorCoefficient(java.lang.String name)
           
 java.util.ArrayList getFactorNames()
          Returns a list of names of factors involved in this constraint
 double getLikelihood(FactoredCostFunctionState state)
          Returns the likelihood of a given state given this constraint
 double getTransitionPointForFactorWeight(java.lang.String factorName, FactoredCostFunctionState state)
          This method looks for the value for the weight for a factor with a given name that lies on the boundry of this constraint being satisfied or unsatisfied; all that assuming that other weights have values as represented by the state
 int hashCode()
           
 boolean isEmpty()
          Checks if there are any non-zero factors in this constraint
 boolean isEquivalent(FactorConstraint c)
          Two constraints are equivalent if they correspond to the same factor and factor values
 boolean isFactorUsed(java.lang.String factorName)
          Checks if a factor with a given name is involved in this constraint
 boolean isSatisfied(FactoredCostFunctionState state)
          Checks if the state satisfied this constraint
protected  void setupConstraint(Solution soln, FactoredCostFunction costFunction, boolean isBad)
           
protected  void setupConstraint(Solution bad, Solution good, FactoredCostFunction costFunction)
           
protected  void setupConstraint(SuppleType type, UiObject uiObject, java.util.Collection lhsFactors, WidgetDescriptor lhsWidget, java.util.Collection rhsFactors, WidgetDescriptor rhsWidget)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

factorIndices

protected transient int[] factorIndices

factorValues

protected double[] factorValues

factors

protected java.util.Hashtable factors

factorNames

protected java.util.ArrayList factorNames

lhsWidgetName

protected java.lang.String lhsWidgetName

rhsWidgetName

protected java.lang.String rhsWidgetName
Constructor Detail

FactorConstraint

public FactorConstraint(SuppleType type,
                        UiObject uiObject,
                        java.util.Collection lhsFactors,
                        WidgetDescriptor lhsWidget,
                        java.util.Collection rhsFactors,
                        WidgetDescriptor rhsWidget)

FactorConstraint

public FactorConstraint(Solution bad,
                        Solution good,
                        FactoredCostFunction costFunction)

FactorConstraint

protected FactorConstraint(java.lang.String lhsFactorName,
                           double lhsFactorValue,
                           java.lang.String rhsFactorName,
                           double rhsFactorValue)
Method Detail

setupConstraint

protected void setupConstraint(SuppleType type,
                               UiObject uiObject,
                               java.util.Collection lhsFactors,
                               WidgetDescriptor lhsWidget,
                               java.util.Collection rhsFactors,
                               WidgetDescriptor rhsWidget)

setupConstraint

protected void setupConstraint(Solution bad,
                               Solution good,
                               FactoredCostFunction costFunction)

setupConstraint

protected void setupConstraint(Solution soln,
                               FactoredCostFunction costFunction,
                               boolean isBad)

addFactors

protected void addFactors(SuppleType type,
                          UiObject uiObject,
                          WidgetDescriptor descriptor,
                          FactoredCostFunction costFunction,
                          boolean isBad)

addFactor

protected void addFactor(SuppleType type,
                         UiObject uiObject,
                         WidgetDescriptor descriptor,
                         Factor factor,
                         boolean isBad)

addFactor

protected void addFactor(java.lang.String name,
                         double value,
                         boolean isBad)

isEmpty

public boolean isEmpty()
Checks if there are any non-zero factors in this constraint

Returns:
true if there are any non-zero factors in this constraint; false otherwise

isFactorUsed

public boolean isFactorUsed(java.lang.String factorName)
Checks if a factor with a given name is involved in this constraint

Parameters:
factorName - the name of the factor
Returns:
true if the factor is involved; false otherwise

getFactorCoefficient

protected double getFactorCoefficient(java.lang.String name)

getLikelihood

public double getLikelihood(FactoredCostFunctionState state)
Returns the likelihood of a given state given this constraint

Parameters:
state - a complete state
Returns:
the likelihood

isSatisfied

public boolean isSatisfied(FactoredCostFunctionState state)
Checks if the state satisfied this constraint

Parameters:
state - the state to be checked
Returns:
true if it satisfies the constraint; false otherwise

getTransitionPointForFactorWeight

public double getTransitionPointForFactorWeight(java.lang.String factorName,
                                                FactoredCostFunctionState state)
This method looks for the value for the weight for a factor with a given name that lies on the boundry of this constraint being satisfied or unsatisfied; all that assuming that other weights have values as represented by the state

Parameters:
factorName - name of the factor corresponding to the weight we are investigating
state - the state of all the other weights
Returns:
the transition point or zero if the factor is not used in this constraint

getConstraintValue

protected double getConstraintValue(FactoredCostFunctionState state)

ensureFactorIndices

protected void ensureFactorIndices(FactoredCostFunctionState state)

getFactorNames

public java.util.ArrayList getFactorNames()
Returns a list of names of factors involved in this constraint

Returns:

hashCode

public int hashCode()

toString

public java.lang.String toString()

isEquivalent

public boolean isEquivalent(FactorConstraint c)
Two constraints are equivalent if they correspond to the same factor and factor values

Parameters:
c -
Returns:

containsEquivalentConstraint

public static int containsEquivalentConstraint(java.util.Vector constraints,
                                               FactorConstraint c)
Checks if a constraint equivalent to c exist in vector constraints.

Parameters:
constraints - a vector of existing constraints
c - a constraint to be checked
Returns:
an integer indicating how mfar from the end of the vector this particular constraint (or one equivalent to it) was registered (or -1 if it's not there)