Modifier and Type | Field and Description |
---|---|
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector2D |
Ac
Half of a sparse matrix representation of the constraints; this half contains the
coefficients on the variables whose indexes appear in
Av . |
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.IVector2D |
Av
Half of a sparse matrix representation of the constraints; this half contains the variable
indexes corresponding to the coefficients in
Ac . |
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector |
bounds
The vector of constraint bounds.
|
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.IVector |
boundTypes
Contains the types of the constraints.
|
static String[] |
boundTypeSymbols
Maps from the three constraint types to their operator symbols.
|
static int |
EQUALITY
Represents the constraint type "equality".
|
static int |
GREATER_THAN
Represents the constraint type "greater than or equal to".
|
static int |
LESS_THAN
Represents the constraint type "less than or equal to".
|
protected boolean |
maximize
Remembers whether the objective function should be maximized or minimzed.
|
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector |
objectiveCoefficients
Represents the coefficients of all inference variables in the objective function.
|
static double |
TOLERANCE
Used to mitigate floating point error in (in)equality comparisons.
|
Constructor and Description |
---|
ZeroOneILPProblem()
Default constructor.
|
ZeroOneILPProblem(String name)
Reads a textual representation of a 0-1 ILP problem from the specified file.
|
Modifier and Type | Method and Description |
---|---|
int |
addBooleanVariable(double c)
Adds a new Boolean variable (an integer variable constrained to take either the value 0 or
the value 1) with the specified coefficient in the objective function to the problem.
|
protected void |
addConstraint(int[] I,
double[] a,
double b)
Adds a typeless constraint to the problem.
|
protected void |
addConstraint(int[] i,
double[] a,
int t,
double b)
Adds a new constraint of the specified type to the problem.
|
int[] |
addDiscreteVariable(double[] c)
Adds a general, multi-valued discrete variable, which is implemented as a set of Boolean
variables, one per value of the discrete variable, with exactly one of those variables set
true at any given time. |
int[] |
addDiscreteVariable(Score[] c)
Adds a general, multi-valued discrete variable, which is implemented as a set of Boolean
variables, one per value of the discrete variable, with exactly one of those variables set
true at any given time. |
void |
addEqualityConstraint(int[] i,
double[] a,
double b)
Adds a new fixed constraint to the problem.
|
void |
addGreaterThanConstraint(int[] i,
double[] a,
double b)
Adds a new lower bounded constraint to the problem.
|
void |
addLessThanConstraint(int[] i,
double[] a,
double b)
Adds a new upper bounded constraint to the problem.
|
int |
columns()
Returns the number of variables in the ILP problem.
|
boolean |
constraintsSatisfied(int[] x)
Determines whether all constraints are satisfied by the given solution.
|
double |
evaluate(int[] x)
This method evaluates the objective function on a potential (not necessarily feasible)
solution.
|
int |
getBoundType(int i)
Returns the type of the specified constraint's bound.
|
double |
getConstraintBound(int i)
Returns the bound of the specified constraint.
|
double |
getConstraintCoefficient(int i,
int j)
Returns the specified constraint coefficient.
|
boolean |
getMaximize()
Returns
true iff the objective function is to be maximized. |
double |
getObjectiveCoefficient(int j)
Returns the specified objective coefficient.
|
void |
reset()
This method clears the all constraints and variables out of the problem representation,
bringing it back to the state it was in when first constructed.
|
int |
rows()
Returns the number of constraints in the ILP problem.
|
void |
setBoundType(int i,
int t)
Sets the bound type for the specified constraint.
|
void |
setConstraintBound(int i,
double bi)
Sets the bound on the specified constraint.
|
void |
setConstraintCoefficient(int i,
int j,
double aij)
Sets the specified coefficient in the constraint matrix.
|
void |
setMaximize(boolean d)
Sets the direction of the objective function.
|
void |
setObjectiveCoefficient(int j,
double cj)
Sets the specified coefficient in the objective function.
|
String |
toString()
Returns the representation created by
write(StringBuffer) . |
void |
write(StringBuffer buffer)
Creates a textual representation of the ILP problem in an algebraic notation.
|
public static final int EQUALITY
public static final int LESS_THAN
public static final int GREATER_THAN
public static final String[] boundTypeSymbols
public static final double TOLERANCE
protected boolean maximize
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector objectiveCoefficients
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.IVector2D Av
Ac
.protected edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector2D Ac
Av
.protected edu.illinois.cs.cogcomp.core.datastructures.vectors.IVector boundTypes
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector bounds
public ZeroOneILPProblem()
public ZeroOneILPProblem(String name)
name
- The name of the file from which to read the ILP problem's representation.public void reset()
public void setMaximize(boolean d)
d
- true
if the objective function is to be maximized.public boolean getMaximize()
true
iff the objective function is to be maximized.public int rows()
public int columns()
public void setObjectiveCoefficient(int j, double cj)
j
- The index of the variable whose coefficient will be set.cj
- The new value of the coefficient.public double getObjectiveCoefficient(int j)
public void setConstraintCoefficient(int i, int j, double aij)
i
- The index of the constraint.j
- The index of the variable.aij
- The new value of the coefficient.public double getConstraintCoefficient(int i, int j)
public void setBoundType(int i, int t)
i
- The constraint whose bound type will be set.t
- The new type for the constraint's bound.public int getBoundType(int i)
public void setConstraintBound(int i, double bi)
i
- The constraint whose bound will be set.bi
- The new value for the bound.public double getConstraintBound(int i)
public boolean constraintsSatisfied(int[] x)
x
- The settings of the variables.true
iff all constraints are satisfied.public int addBooleanVariable(double c)
c
- The objective function coefficient for the new Boolean variable.public int[] addDiscreteVariable(double[] c)
true
at any given time.c
- The objective function coefficients for the new Boolean variables.public int[] addDiscreteVariable(Score[] c)
true
at any given time.c
- An array of Score
s containing the objective function coefficients for the
new Boolean variables.protected void addConstraint(int[] I, double[] a, double b)
addConstraint(int[],double[],int,double)
.I
- The indexes of the variables with non-zero coefficients.a
- The coefficients of the variables with the given indexes.b
- The new constraint will enforce equality with this constant.protected void addConstraint(int[] i, double[] a, int t, double b)
addBooleanVariable(double)
or addDiscreteVariable(double[])
. The resulting
constraint has the form: xi * a ?= b
where
xi
represents the inference variables whose indexes are contained in
the array i
, *
represents dot product, and ?= stands for the type
of the constraint.
This method is called by the other constraint adding methods in this class. It sorts the
variables and their coefficients so that the presence of a given variable can be determined
with IVector2D.binarySearch(int,int)
.
i
- The indexes of the variables with non-zero coefficients.a
- The coefficients of the variables with the given indexes.t
- The type of comparison in this constraint.b
- The new constraint will enforce equality with this constant.public void addEqualityConstraint(int[] i, double[] a, double b)
addBooleanVariable(double)
or addDiscreteVariable(double[])
. The resulting
constraint has the form: xi * a = b
where
xi
represents the inference variables whose indexes are contained in
the array i
and *
represents dot product.i
- The indexes of the variables with non-zero coefficients.a
- The coefficients of the variables with the given indexes.b
- The new constraint will enforce equality with this constant.public void addGreaterThanConstraint(int[] i, double[] a, double b)
addBooleanVariable(double)
or addDiscreteVariable(double[])
. The resulting
constraint has the form: xi * a >= b
where xi
represents the inference variables whose indexes are
contained in the array i
and *
represents dot product.i
- The indexes of the variables with non-zero coefficients.a
- The coefficients of the variables with the given indexes.b
- The lower bound for the new constraint.public void addLessThanConstraint(int[] i, double[] a, double b)
addBooleanVariable(double)
or addDiscreteVariable(double[])
. The resulting
constraint has the form: xi * a <= b
where xi
represents the inference variables whose indexes are
contained in the array i
and *
represents dot product.i
- The indexes of the variables with non-zero coefficients.a
- The coefficients of the variables with the given indexes.b
- The upper bound for the new constraint.public double evaluate(int[] x)
x
- The current settings of the inference variables.public void write(StringBuffer buffer)
buffer
- The created textual representation will be appended here.public String toString()
write(StringBuffer)
.Copyright © 2016. All rights reserved.