public class BalasHook extends ZeroOneILPProblem implements edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
ILPSolver
implements Egon Balas' zero-one ILP solving algorithm. It is a branch and
bound algorithm that can return the best solution found so far if stopped early. For more
information on the original algorithm, see E. Balas. 1965. An Additive Algorithm for Solving Linear Programs with Zero-One Variables. Operations Research, 13(4):517–546.
Modifier and Type | Field and Description |
---|---|
protected boolean |
first
Whether or not the algorithm will halt upon finding its first feasible solution.
|
protected int |
verbosity
Verbosity level.
|
Ac, Av, bounds, boundTypes, boundTypeSymbols, EQUALITY, GREATER_THAN, LESS_THAN, maximize, objectiveCoefficients, TOLERANCE
Constructor and Description |
---|
BalasHook()
Default constructor.
|
BalasHook(boolean f)
Creates a new ILP solver that halts at the first feasible solution found, if the parameter to
this constructor is
true . |
BalasHook(boolean f,
int v)
Creates a new ILP solver that halts at the first feasible solution found, if the first
parameter to this constructor is
true . |
BalasHook(int v)
Creates a new ILP solver with the specified verbosity.
|
BalasHook(String name)
Creates a new ILP solver with the problem represented in the named file loaded and ready to
solve.
|
BalasHook(String name,
boolean f)
Creates a new ILP solver with the problem represented in the named file loaded and ready to
solve.
|
BalasHook(String name,
boolean f,
int v)
Creates a new ILP solver with the problem represented in the named file loaded and ready to
solve.
|
BalasHook(String name,
int v)
Creates a new ILP solver with the problem represented in the named file loaded and ready to
solve.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addConstraint(int[] i,
double[] a,
int t,
double b)
Simply overrides
ZeroOneILPProblem.addConstraint(int[],double[],int,double) so that
it calls ZeroOneILPProblem.addConstraint(int[],double[],double) thereby ignoring the
constraint's type. |
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.
|
int |
addIntegerVariable(double c) |
void |
addLessThanConstraint(int[] i,
double[] a,
double b)
Adds a new upper bounded constraint to the problem.
|
int |
addRealVariable(double c) |
boolean |
getBooleanValue(int index)
When the problem has been solved, use this method to retrieve the value of any Boolean
inference variable.
|
int |
getIntegerValue(int index) |
double |
getRealValue(int index) |
boolean |
isSolved()
Tests whether the problem represented by this
ILPSolver instance has been solved
already. |
double |
objectiveValue()
When the problem has been solved, use this method to retrieve the value of the objective
function at the solution.
|
void |
reset()
This method clears the all constraints and variables out of the ILP solver's problem
representation, bringing the
ILPSolver instance back to the state it was in when
first constructed. |
void |
setFirst(boolean f)
Sets the value of
first . |
boolean |
solve()
Solves the ILP problem, saving the solution internally.
|
boolean |
solve(double z)
Implements the meat of the Balas algorithm recursively.
|
void |
write(StringBuffer buffer)
Creates a textual representation of the ILP problem in an algebraic notation.
|
addBooleanVariable, addConstraint, addDiscreteVariable, addDiscreteVariable, columns, constraintsSatisfied, evaluate, getBoundType, getConstraintBound, getConstraintCoefficient, getMaximize, getObjectiveCoefficient, rows, setBoundType, setConstraintBound, setConstraintCoefficient, setMaximize, setObjectiveCoefficient, toString
protected boolean first
protected int verbosity
ILPInference.VERBOSITY_NONE
produces no incidental output. If set to
ILPInference.VERBOSITY_LOW
, only variable and constraint counts are reported on
STDOUT
. If set to ILPInference.VERBOSITY_HIGH
, a textual representation
of the entire optimization problem is also generated on STDOUT
.public BalasHook()
public BalasHook(int v)
v
- Setting for the verbosity
level.public BalasHook(boolean f)
true
.f
- Whether or not to stop at the first feasible solution.public BalasHook(boolean f, int v)
true
.f
- Whether or not to stop at the first feasible solution.v
- Setting for the verbosity
level.public BalasHook(String name)
name
- The name of the file containing the textual representation of a 0-1 ILP problem.public BalasHook(String name, boolean f)
name
- The name of the file containing the textual representation of a 0-1 ILP problem.f
- Whether or not to stop at the first feasible solution.public BalasHook(String name, int v)
name
- The name of the file containing the textual representation of a 0-1 ILP problem.v
- Setting for the verbosity
level.public BalasHook(String name, boolean f, int v)
name
- The name of the file containing the textual representation of a 0-1 ILP problem.f
- Whether or not to stop at the first feasible solution.v
- Setting for the verbosity
level.public void setFirst(boolean f)
first
.public void reset()
ILPSolver
instance back to the state it was in when
first constructed.reset
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
reset
in class ZeroOneILPProblem
protected void addConstraint(int[] i, double[] a, int t, double b)
ZeroOneILPProblem.addConstraint(int[],double[],int,double)
so that
it calls ZeroOneILPProblem.addConstraint(int[],double[],double)
thereby ignoring the
constraint's type. Overriding this method in this way ensures that types are not stored when
reading in a textual problem representation, as happens when constructing an instance with
BalasHook(String)
.addConstraint
in class ZeroOneILPProblem
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 int addRealVariable(double c)
addRealVariable
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
public int addIntegerVariable(double c)
addIntegerVariable
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
public void addEqualityConstraint(int[] i, double[] a, double b)
ZeroOneILPProblem.addBooleanVariable(double)
or ZeroOneILPProblem.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.addEqualityConstraint
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
addEqualityConstraint
in class ZeroOneILPProblem
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)
ZeroOneILPProblem.addBooleanVariable(double)
or ZeroOneILPProblem.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.addGreaterThanConstraint
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
addGreaterThanConstraint
in class ZeroOneILPProblem
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)
ZeroOneILPProblem.addBooleanVariable(double)
or ZeroOneILPProblem.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.addLessThanConstraint
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
addLessThanConstraint
in class ZeroOneILPProblem
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 boolean solve() throws Exception
solve
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
true
iff a solution was found successfully.Exception
public boolean solve(double z)
z
- The value of the objective function with the current variable settings.true
iff a solution was found successfully.public boolean isSolved()
ILPSolver
instance has been solved
already.isSolved
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
public boolean getBooleanValue(int index)
getBooleanValue
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
index
- The index of the variable whose value is requested.public int getIntegerValue(int index)
getIntegerValue
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
public double getRealValue(int index)
getRealValue
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
public double objectiveValue()
objectiveValue
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
public void write(StringBuffer buffer)
write
in interface edu.illinois.cs.cogcomp.infer.ilp.ILPSolver
write
in class ZeroOneILPProblem
buffer
- The created textual representation will be appended here.Copyright © 2016. All rights reserved.