|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLBJ2.jni.GLPKHook
public class GLPKHook
Native interface to the GNU Linear Programming Kit (GLPK), designed for
version 4.14. In order to use this class, GLPK 4.14 must be installed
such that the following statement would work in a C source
file:
#include <glpk.h>
and such that that C file could be compiled and linked with
-lglpk on the command line. Furthermore, the
GLPKHook library distributed with LBJ must be accessible in a
location where the JVM will search for it.
An object of this class represents a single integer linear programming problem. All columns added are assumed to represent Boolean variables (i.e., integer variables that may take either the value 0 or the value 1).
| Field Summary | |
|---|---|
private java.util.LinkedList |
constraints
If the appropriate methods are called below, this list will contain all the constraints that have been added to this solver. |
private java.lang.String |
debugFileName
Diagnostic messages are written to this file when an optimal solution cannot be found. |
private boolean |
generateCuts
Whether or not to generate Gomory cuts. |
private boolean |
maximize
If the appropriate methods are called below, this variable will be set iff this solver is solving a maximization. |
private int |
objectiveCoefficients
Represents the number of variables in the optimization problem. |
private java.lang.String |
objectiveFunction
If the appropriate methods are called below, this string will represent the objective function. |
private boolean |
printProblem
true if the ILP problem should be printed when invoking
solve(). |
private int |
problemPointer
A C pointer to the C problem structure. |
private boolean |
solved
Indicates whether this problem instance has been solved already. |
| Constructor Summary | |
|---|---|
GLPKHook()
Creates the problem object with a call to createProblem(). |
|
GLPKHook(boolean g)
Creates the problem object with a call to createProblem(). |
|
GLPKHook(boolean g,
boolean p)
Creates the problem object with a call to createProblem(). |
|
GLPKHook(java.lang.String s)
Creates the problem object with a call to createProblem(). |
|
GLPKHook(java.lang.String s,
boolean g)
Creates the problem object with a call to createProblem(). |
|
GLPKHook(java.lang.String s,
boolean g,
boolean p)
Creates the problem object with a call to createProblem(). |
|
| 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. |
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. |
protected void |
addFixedConstraint(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. |
protected void |
addLowerBoundedConstraint(int[] i,
double[] a,
double b)
Adds a new lower bounded constraint to the problem. |
protected void |
addObjectiveCoefficient(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 |
addUpperBoundedConstraint(int[] i,
double[] a,
double b)
Adds a new upper bounded constraint to the problem. |
double |
columnPrimalValueOf(int i)
Returns the value of the specified variable in the primal solution. |
protected int |
createProblem()
Instantiates the problem object in the C world. |
protected void |
deleteProblem()
Frees the problem object's memory in the C world. |
protected void |
finalize()
Deletes the problem object with a call to deleteProblem(). |
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. |
protected boolean |
nativeSolve()
Invokes the lpx_intopt GLPK library function to solve the
integer linear program. |
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. |
protected void |
setMaximize()
Sets the direction of the objective function to maximization. |
void |
setMaximize(boolean d)
Sets the direction of the objective function. |
protected void |
setMinimize()
Sets the direction of the objective function to minimization. |
boolean |
solve()
Simply calls nativeSolve(), saving the result in
solved. |
void |
write(java.lang.StringBuffer buffer)
Writes the optimization problem that this solver represents into the specified buffer, assuming the appropriate member methods were called to remember this information. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private boolean solved
private int problemPointer
C pointer to the C problem structure.
private boolean generateCuts
private java.lang.String debugFileName
private boolean printProblem
true if the ILP problem should be printed when invoking
solve().
private java.util.LinkedList constraints
private java.lang.String objectiveFunction
private int objectiveCoefficients
private boolean maximize
| Constructor Detail |
|---|
public GLPKHook()
createProblem().
createProblem()public GLPKHook(boolean g)
createProblem().
g - Whether or not to generate cuts.createProblem()
public GLPKHook(boolean g,
boolean p)
createProblem().
g - Whether or not to generate cuts.p - Set true to cause a textual representation of the
problem to be printed to STDOUT when invoking the
solve() method before the solution is carried out.createProblem()public GLPKHook(java.lang.String s)
createProblem().
s - A file name for the "debug" file, in which diagnostic messages
are written when an optimal solution cannot be found.createProblem()
public GLPKHook(java.lang.String s,
boolean g)
createProblem().
s - A file name for the "debug" file, in which diagnostic messages
are written when an optimal solution cannot be found.g - Whether or not to generate cuts.createProblem()
public GLPKHook(java.lang.String s,
boolean g,
boolean p)
createProblem().
s - A file name for the "debug" file, in which diagnostic messages
are written when an optimal solution cannot be found.g - Whether or not to generate cuts.p - Set true to cause a textual representation of the
problem to be printed to STDOUT when invoking the
solve() method before the solution is carried out.createProblem()| Method Detail |
|---|
public void reset()
ILPSolver
instance back to the state it was in when first constructed.
reset in interface ILPSolverpublic boolean isSolved()
ILPSolver
instance has been solved already.
isSolved in interface ILPSolver
protected void finalize()
throws java.lang.Throwable
deleteProblem().
finalize in class java.lang.Objectjava.lang.ThrowabledeleteProblem()protected int createProblem()
C world.
protected void deleteProblem()
C world.
public void setMaximize(boolean d)
setMaximize in interface ILPSolverd - true if the objective function is to be
maximized.protected void setMaximize()
protected void setMinimize()
public int[] addDiscreteVariable(double[] c)
true at any given time.
Since GLPK does not handle these sets of Boolean variables specially,
this method simply calls addBooleanVariable(double) repeatedly
and then adds an equality constraint.
addDiscreteVariable in interface ILPSolverc - The objective function coefficients for the new Boolean
variables.
public int[] addDiscreteVariable(Score[] c)
true at any given time.
Since GLPK does not handle these sets of Boolean variables specially,
this method simply calls addBooleanVariable(double) repeatedly
and then adds an equality constraint.
addDiscreteVariable in interface ILPSolverc - An array of Scores containing the
objective function coefficients for the new Boolean variables.
public int addBooleanVariable(double c)
addBooleanVariable in interface ILPSolverc - The objective function coefficient for the new Boolean
variable.
protected void addObjectiveCoefficient(double c)
c - The objective function coefficient for the new Boolean
variable.
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.
protected void addFixedConstraint(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.
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.
protected void addLowerBoundedConstraint(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.
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.
protected void addUpperBoundedConstraint(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 boolean solve()
throws java.lang.Exception
nativeSolve(), saving the result in
solved.
solve in interface ILPSolverjava.lang.Exceptionprotected boolean nativeSolve()
lpx_intopt GLPK library function to solve the
integer linear program. To produce diagnostic messages regarding a
return value of false from this method, use the constructor
of this class that takes a String argument.
true iff an optimal integer solution was found and
no problems were encountered while running the algorithms.public boolean getBooleanValue(int index)
getBooleanValue in interface ILPSolverindex - The index of the variable whose value is requested.
public double columnPrimalValueOf(int i)
i - The index of the variable whose value is to be returned.
public void write(java.lang.StringBuffer buffer)
write in interface ILPSolverbuffer - The buffer to write in.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||