|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLBJ2.infer.XpressMPHook
public class XpressMPHook
This interface to Xpress-MP from
Dash Optimization is
designed to work with Xpress-Optimizer 15.25.02. Make sure the file
xprs.jar is on your CLASSPATH and that the
Xpress-MP libraries are installed appropriately on your system before
attempting to compile and use this class.
Note to users: When invoking a classifier in your
application that calls this algorithm to do inference, files whose names
start with xmp and end with .sol or
.glb will be created in the directory from which you invoked
your application. These files are created by the Xpress-MP library, and I
haven't found a way to avoid it.
Xpress-MP represents an ILP problem as a coefficient matrix in which rows represent constraints and columns represent variables. In the documentation below, the terms "row" and "constraint" are used interchangeably, as are the terms "column" and "variable".
| Nested Class Summary | |
|---|---|
protected static class |
XpressMPHook.Vector2D
A two dimensional vector representation implemented here because we are not assuming Java 5. |
protected static class |
XpressMPHook.Vector2DDouble
A two dimensional vector representation implemented here because we are not assuming Java 5. |
protected static class |
XpressMPHook.Vector2DInt
A two dimensional vector representation implemented here because we are not assuming Java 5. |
| Field Summary | |
|---|---|
private XpressMPHook.Vector2DDouble |
coefficients
Contains one vector for each added variable representing a list of non-zero coefficients associated with the variable in the various constraints in the problem. |
private boolean |
maximize
Remembers whether the objective function should be maximized or minimzed. |
private static int |
nextID
Keeps track of the next ID number for an instance of this class. |
private XpressMPHook.Vector2DDouble |
objective
Contains one value for each added variable representing that variable's coefficient in the objective function. |
private boolean |
printProblem
If true, the parameters to be sent to
XPRSloadglobal will be printed to STDOUT just
before XPRSloadglobal is called in the solve()
method. |
private com.dashoptimization.XPRSprob |
problem
Xpress-MP's ILP problem representation is stored here for easy access to the solution values of variables. |
private int |
problemID
The ID of an instance is used in the name of the solution file. |
private XpressMPHook.Vector2DDouble |
rhs
Contains one value for each added constraint representing its constant right hand side. |
private static int |
ROWEQUAL
Index into the typeCodes array representing "equal". |
private static int |
ROWGREATERTHAN
Index into the typeCodes array representing "greater than". |
private XpressMPHook.Vector2DInt |
rowIndexes
Contains one vector for each added variable representing a list of row indexes at which the associated variable has a non-zero coefficient. |
private static int |
ROWLESSTHAN
Index into the typeCodes array representing "less than". |
private XpressMPHook.Vector2DInt |
rowTypes
Contains one integer for each added constraint representing its type. |
private XpressMPHook.Vector2DInt |
setColumns
Contains one vector for each SOS1 in the ILP problem representing the list of columns involved in the set. |
private static byte[] |
typeCodes
The elements of this array are suitable for use as elements of the qrtype array parameter of the XPRSloadglobal
method. |
private double[] |
x
The values of the primal variables after solving the problem. |
| Constructor Summary | |
|---|---|
XpressMPHook()
Default constructor. |
|
XpressMPHook(boolean p)
Use this constructor to control printing of the problem's representation before its solution is carried out. |
|
| Method Summary | |
|---|---|
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. |
void |
addConstraint(int[] i,
double[] a,
double b,
int t)
Adds a new constraint to the problem with the specified type. |
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. |
private static java.lang.String |
arrayToString(byte[] a)
Generates a string representation of the given array. |
private static java.lang.String |
arrayToString(double[] a)
Generates a string representation of the given array. |
private static java.lang.String |
arrayToString(int[] a)
Generates a string representation of the given array. |
boolean |
getBooleanValue(int index)
When the problem has been solved, use this method to retrieve the value of any Boolean inference variable. |
boolean |
isSolved()
Tests whether the problem represented by this ILPSolver
instance has been solved already. |
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 |
setMaximize(boolean d)
Sets the direction of the objective function. |
boolean |
solve()
Solves the ILP problem, saving the solution internally. |
void |
write(java.lang.StringBuffer buffer)
Creates a textual representation of the ILP problem in an algebraic notation. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final byte[] typeCodes
qrtype array parameter of the XPRSloadglobal
method.
private static final int ROWLESSTHAN
typeCodes array representing "less than".
private static final int ROWEQUAL
typeCodes array representing "equal".
private static final int ROWGREATERTHAN
typeCodes array representing "greater than".
private static int nextID
private int problemID
private boolean printProblem
true, the parameters to be sent to
XPRSloadglobal will be printed to STDOUT just
before XPRSloadglobal is called in the solve()
method.
private com.dashoptimization.XPRSprob problem
private double[] x
private boolean maximize
private XpressMPHook.Vector2DDouble objective
XpressMPHook.Vector2DDouble to mitigate the need to cast
things.
private XpressMPHook.Vector2DInt rowTypes
XpressMPHook.Vector2DInt to mitigate the need to cast things.
private XpressMPHook.Vector2DDouble rhs
XpressMPHook.Vector2DDouble to mitigate the need to cast things.
private XpressMPHook.Vector2DInt rowIndexes
private XpressMPHook.Vector2DDouble coefficients
rowIndexes array.
private XpressMPHook.Vector2DInt setColumns
| Constructor Detail |
|---|
public XpressMPHook()
public XpressMPHook(boolean p)
p - If true, a textual representation of the ILP
problem will be printed to STDOUT just before
XPRSloadglobal is called in the solve()
method.| Method Detail |
|---|
public void reset()
ILPSolver
instance back to the state it was in when first constructed.
reset in interface ILPSolverpublic void setMaximize(boolean d)
setMaximize in interface ILPSolverd - true if the objective function is to be
maximized.public int addBooleanVariable(double c)
addBooleanVariable in interface ILPSolverc - The objective function coefficient for the new Boolean
variable.
public int[] addDiscreteVariable(double[] c)
true at any given time.
addDiscreteVariable in interface ILPSolverc - The objective function coefficients for the new Boolean
variables.
public int[] addDiscreteVariable(Score[] c)
true at any given time.
addDiscreteVariable in interface ILPSolverc - An array of Scores containing the
objective function coefficients for the new Boolean variables.
public void addConstraint(int[] i,
double[] a,
double b,
int t)
add*Constraint() methods.
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.t - The type of linear inequality constraint to add.
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.
addEqualityConstraint in interface ILPSolveri - 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.
addGreaterThanConstraint in interface ILPSolveri - 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.
addLessThanConstraint in interface ILPSolveri - 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 java.lang.Exception
solve in interface ILPSolvertrue iff a solution was found successfully.
java.lang.Exceptionprivate static java.lang.String arrayToString(byte[] a)
a - The array to represent as a string.
a.private static java.lang.String arrayToString(int[] a)
a - The array to represent as a string.
a.private static java.lang.String arrayToString(double[] a)
a - The array to represent as a string.
a.public boolean isSolved()
ILPSolver
instance has been solved already.
isSolved in interface ILPSolverpublic boolean getBooleanValue(int index)
getBooleanValue in interface ILPSolverindex - The index of the variable whose value is requested.
public void write(java.lang.StringBuffer buffer)
write in interface ILPSolverbuffer - The created textual representation will be appended here.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||