LBJ2.infer
Class ILPInference

java.lang.Object
  extended by LBJ2.infer.Inference
      extended by LBJ2.infer.ILPInference

public class ILPInference
extends Inference

This class employs an ILPSolver to solve a constrained inference problem. When constructing an instance of this class in an LBJ source file, use one of the constructors that does not specify a head object. The generated code will fill in the head object automatically. The other constructor parameters are used to specify the ILP algorithm and enable textual output of ILP variable descriptions to STDOUT. Textual output of the ILP problem itself is controlled by the ILPSolver.


Field Summary
protected  int ID
          The identification number for this object, used in debug file names.
protected  java.util.HashMap indexMap
          Used during ILP constraint generation.
protected static int nextID
          Keeps the next ID number for objects of this class.
protected  int returnIndex
          Used during ILP constraint generation.
protected  boolean returnNegation
          Used during ILP constraint generation.
protected  ILPSolver solver
          The ILP algorithm.
protected  boolean tautology
          This flag is set if the constraints turn out to be true in all cases.
protected  boolean topLevel
          Used during ILP constraint generation.
protected  int verbosity
          Verbosity level.
protected static int VERBOSITY_HIGH
          A possible setting for verbosity.
protected static int VERBOSITY_LOW
          A possible setting for verbosity.
protected static int VERBOSITY_NONE
          A possible setting for verbosity.
 
Fields inherited from class LBJ2.infer.Inference
constraint, head, variables
 
Constructor Summary
ILPInference()
          Don't use this constructor, since it doesn't set an ILP algorithm.
ILPInference(ILPSolver a)
          Initializes the ILP algorithm, but not the head object.
ILPInference(ILPSolver a, int v)
          Initializes the ILP algorithm, but not the head object.
ILPInference(java.lang.Object h)
          Don't use this constructor, since it doesn't set an ILP algorithm.
ILPInference(java.lang.Object h, ILPSolver a)
          Sets the head object and the ILP algorithm.
ILPInference(java.lang.Object h, ILPSolver a, int v)
          Sets the head object and the ILP algorithm.
 
Method Summary
 void addConstraint(FirstOrderConstraint c)
          Adds a constraint to the inference.
protected  int createVariable(java.lang.String d)
          Creates a new Boolean variable to represent the value of a subexpression of some constraint.
 boolean equals(java.lang.Object o)
          Two Inference objects are equal when they have the same run-time type and store the same head object.
protected  void infer()
          Uses the provided ILP algorithm to solve the ILP proglem if it hasn't already been solved.
 java.lang.String valueOf(Learner c, java.lang.Object o)
          Retrieves the value of the specified variable as identified by the classifier and the object that produce that variable.
 void visit(PropositionalAtLeast c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalConjunction c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalConstant c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalDisjunction c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalDoubleImplication c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalImplication c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalNegation c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalVariable c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 
Methods inherited from class LBJ2.infer.Inference
exampleToString, getHead, getHeadFinderTypes, getHeadType, getNormalizer, getVariable, getVariable, satisfied, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSITY_NONE

protected static final int VERBOSITY_NONE
A possible setting for verbosity.

See Also:
Constant Field Values

VERBOSITY_LOW

protected static final int VERBOSITY_LOW
A possible setting for verbosity.

See Also:
Constant Field Values

VERBOSITY_HIGH

protected static final int VERBOSITY_HIGH
A possible setting for verbosity.

See Also:
Constant Field Values

nextID

protected static int nextID
Keeps the next ID number for objects of this class.


ID

protected int ID
The identification number for this object, used in debug file names.


solver

protected ILPSolver solver
The ILP algorithm.


tautology

protected boolean tautology
This flag is set if the constraints turn out to be true in all cases.


returnIndex

protected int returnIndex
Used during ILP constraint generation. When a propositional constraint finishes generating any ILP constraints that may be associated with it, it sets this variable to its own index.


returnNegation

protected boolean returnNegation
Used during ILP constraint generation. This flag is set iff the variable corresponding to returnIndex is negated in its current context.


indexMap

protected java.util.HashMap indexMap
Used during ILP constraint generation. This map associates each variable index with a representation of the expression whose value is represented by the variable. The keys associated with indexes of variables that were originally part of the inference problem are PropositionalVariable objects. The keys associated with indexes of temporary variables created during constraint translation are strings.


topLevel

protected boolean topLevel
Used during ILP constraint generation. Constraints are treated differently if they are part of another constraint expression than if they are a term in the top level conjunction.


verbosity

protected int verbosity
Verbosity level. VERBOSITY_NONE produces no incidental output. If set to VERBOSITY_LOW, only timing information is printed on STDOUT. If set to VERBOSITY_HIGH, information mapping the generated ILP variables to the first order variables they were generated from and their settings in the ILP problem's solution is printed to STDOUT.

Constructor Detail

ILPInference

public ILPInference()
Don't use this constructor, since it doesn't set an ILP algorithm.


ILPInference

public ILPInference(ILPSolver a)
Initializes the ILP algorithm, but not the head object.

Parameters:
a - The ILP algorithm.

ILPInference

public ILPInference(ILPSolver a,
                    int v)
Initializes the ILP algorithm, but not the head object.

Parameters:
a - The ILP algorithm.
v - Sets the value of verbosity.

ILPInference

public ILPInference(java.lang.Object h)
Don't use this constructor, since it doesn't set an ILP algorithm.


ILPInference

public ILPInference(java.lang.Object h,
                    ILPSolver a)
Sets the head object and the ILP algorithm.

Parameters:
h - The head object.
a - The ILP algorithm.

ILPInference

public ILPInference(java.lang.Object h,
                    ILPSolver a,
                    int v)
Sets the head object and the ILP algorithm.

Parameters:
h - The head object.
a - The ILP algorithm.
v - Sets the value of verbosity.
Method Detail

addConstraint

public void addConstraint(FirstOrderConstraint c)
Adds a constraint to the inference.

Parameters:
c - The constraint to add.

infer

protected void infer()
              throws java.lang.Exception
Uses the provided ILP algorithm to solve the ILP proglem if it hasn't already been solved.

Specified by:
infer in class Inference
Throws:
java.lang.Exception

valueOf

public java.lang.String valueOf(Learner c,
                                java.lang.Object o)
                         throws java.lang.Exception
Retrieves the value of the specified variable as identified by the classifier and the object that produce that variable.

Specified by:
valueOf in class Inference
Parameters:
c - The classifier producing the variable.
o - The object from which the variable is produced.
Returns:
The current value of the requested variable. If the variable does not exist in this inference, the result of the Learner's discreteValue(Object) method applied to the Object is returned.
Throws:
java.lang.Exception

equals

public boolean equals(java.lang.Object o)
Two Inference objects are equal when they have the same run-time type and store the same head object. I.e., the == operator must return true when comparing the two head objects for this method to return true.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare to this object.
Returns:
true iff this object equals the argument object as defined above.

createVariable

protected int createVariable(java.lang.String d)
Creates a new Boolean variable to represent the value of a subexpression of some constraint.

Parameters:
d - A textual description of the subexpression whose value is represented by the new variable.
Returns:
The index of the new variable.

visit

public void visit(PropositionalDoubleImplication c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalImplication c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalConjunction c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalDisjunction c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalAtLeast c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalNegation c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalVariable c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.

visit

public void visit(PropositionalConstant c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Overrides:
visit in class Inference
Parameters:
c - The constraint to process.