public class CLP
extends java.lang.Object
Java interface for the CLP linear solver. The implementation provides a light-weight wrapper that creates as little overhead as possible. If no variables or constraints are referenced, the memory footprint in Java heap is negligible.
Chunks of a model are buffered in heap for model building before
being sent to the native lib. The size of the buffer can be set with buffer(int)
. The buffer
helps to formulate models in a row-by-row fashion, without bothering about possible performance bottlenecks.
Models with millions of constraints can be generated quickly.
To update model coefficients, the model is accessed directly in native memory via direct byte buffers that are provided by the BridJ native interface. When the model gets gc'ed, native memory will be released automatically.
For debugging a model, use verbose(int)
to set the internal log level of CLP which will show some solution information
during the solution process. toString()
returns the model as string in .lp format (Xpress style),
and printModel()
sends it to standard out in the same format.
Modifier and Type | Class and Description |
---|---|
static class |
CLP.ALGORITHM
Solution algorithm
|
static class |
CLP.SCALING
Parameter scaling
|
static class |
CLP.STATUS
Solution status
|
Constructor and Description |
---|
CLP()
Create an new model instance.
|
Modifier and Type | Method and Description |
---|---|
CLPConstraint |
addConstraint(java.util.Map<CLPVariable,java.lang.Double> lhs,
CLPConstraint.TYPE type,
java.lang.Double rhs)
Add a new constraint to the model without using
CLP#buildExpression() . |
CLPObjective |
addObjective(java.util.Map<CLPVariable,java.lang.Double> terms,
java.lang.Double offset)
Set the objective function to the model without using
CLP#buildExpression() . |
CLPVariable |
addVariable()
Add a new variable to the model
|
CLPVariableSet |
addVariables(int size)
Create a set of variables.
|
CLP |
algorithm(CLP.ALGORITHM algorithm)
Set the solution
CLP.ALGORITHM (default=AUTO). |
CLP |
buffer(int size)
A number of constraints remain in heap space during model building and will be passed to the native methods when needed.
|
CLPExpression |
createExpression()
Create an expression builder to add a constraint or formulate the objective function.
|
CLP |
dualTolerance(double value)
Set the dual tolerance (default=1.e-7).
|
void |
finalize() |
double |
getDualSolution(CLPConstraint constraint) |
int |
getNumConstraints() |
int |
getNumVariables() |
double |
getObjectiveValue() |
double |
getSolution(CLPVariable variable) |
CLP |
maximization()
Solve as maximization problem.
|
CLP.STATUS |
maximize()
Solve the problem as maximization problem.
|
CLP |
maxIterations(int iter)
Set the maximum number of iterations of the solution algorithm.
|
CLP |
maxSeconds(int seconds)
Set the maximum number of seconds for the solution process.
|
CLP |
minimization()
Solve as maximization problem.
|
CLP.STATUS |
minimize()
Solve the problem as minimization problem.
|
CLP |
presolve(boolean on)
Turn presolve on (default=true).
|
CLP |
primalTolerance(double value)
Set the primal tolerance (default=1.e-7).
|
void |
printModel()
Print the model in lp format to standard output.
|
void |
reset()
Rebuild the model from scratch including
|
CLP |
scaling(CLP.SCALING scaling)
Define the parameter scaling defined by
CLP.SCALING (default=OFF). |
void |
setConstraintBounds(CLPConstraint constraint,
java.lang.Double lb,
java.lang.Double ub)
Set constraint bounds.
|
void |
setConstraintCoefficient(CLPConstraint constraint,
CLPVariable variable,
java.lang.Double value)
Set the left-hand side coefficient of a constraint.
|
void |
setConstraintLowerBound(CLPConstraint constraint,
java.lang.Double value)
Set constraint lower bound.
|
void |
setConstraintName(CLPConstraint constraint,
java.lang.String name) |
void |
setConstraintUpperBound(CLPConstraint constraint,
java.lang.Double value)
Set constraint upper bound.
|
void |
setObjectiveCoefficient(CLPVariable variable,
java.lang.Double value)
Set the objective coefficient of the given variable.
|
void |
setObjectiveOffset(java.lang.Double value)
Set objective constant term.
|
void |
setVariableBounds(CLPVariable variable,
java.lang.Double lb,
java.lang.Double ub)
Set variable bounds.
|
void |
setVariableLowerBound(CLPVariable variable,
java.lang.Double value)
Set variable lower bound.
|
void |
setVariableName(CLPVariable variable,
java.lang.String name) |
void |
setVariableUpperBound(CLPVariable variable,
java.lang.Double value)
Set variable upper bound.
|
CLP |
smallestCoefficient(double value)
Set the smallest coefficient value considered as non-zero (default=1.e-10).
|
CLP.STATUS |
solve()
Solve the optimization problem.
|
void |
storeModel(java.lang.String filename)
Store the model in a proprietary CLP format.
|
java.lang.String |
toString()
Return the model in lp format.
|
CLP |
verbose(int level)
Print log to standard out (default=0).
|
public void storeModel(java.lang.String filename)
filename
- public double getDualSolution(CLPConstraint constraint)
constraint
- public double getSolution(CLPVariable variable)
variable
- public void setVariableBounds(CLPVariable variable, java.lang.Double lb, java.lang.Double ub)
CLPVariable.bounds(double, double)
.variable
- lb
- ub
- public void setVariableLowerBound(CLPVariable variable, java.lang.Double value)
CLPVariable.lb(double)
.variable
- value
- public void setVariableUpperBound(CLPVariable variable, java.lang.Double value)
CLPVariable.ub(double)
.variable
- value
- public void setVariableName(CLPVariable variable, java.lang.String name)
variable
- name
- public void setConstraintCoefficient(CLPConstraint constraint, CLPVariable variable, java.lang.Double value)
CLPConstraint.setLhs(CLPVariable, double)
.constraint
- variable
- value
- public void setConstraintBounds(CLPConstraint constraint, java.lang.Double lb, java.lang.Double ub)
CLPConstraint.setRhs(double)
.constraint
- lb
- ub
- public void setConstraintLowerBound(CLPConstraint constraint, java.lang.Double value)
CLPConstraint.setRhs(double)
.constraint
- value
- public void setConstraintUpperBound(CLPConstraint constraint, java.lang.Double value)
CLPConstraint.setRhs(double)
.constraint
- value
- public void setConstraintName(CLPConstraint constraint, java.lang.String name)
constraint
- name
- public CLP verbose(int level)
level
- public CLP buffer(int size)
solve()
gets executed or when the maximum buffer size is reached (default=10000).public CLP maximization()
public CLP minimization()
public CLPVariable addVariable()
public CLPVariableSet addVariables(int size)
size
- public void setObjectiveCoefficient(CLPVariable variable, java.lang.Double value)
variable
- value
- public void setObjectiveOffset(java.lang.Double value)
value
- public CLPExpression createExpression()
public CLPObjective addObjective(java.util.Map<CLPVariable,java.lang.Double> terms, java.lang.Double offset)
CLP#buildExpression()
. Objective coefficients not set remain unchanged.lhs
- terms on the left-hand sidetype
- constraint typerhs
- right-hand side coefficientpublic CLPConstraint addConstraint(java.util.Map<CLPVariable,java.lang.Double> lhs, CLPConstraint.TYPE type, java.lang.Double rhs)
CLP#buildExpression()
.lhs
- terms on the left-hand sidetype
- constraint typerhs
- right-hand side coefficientpublic CLP.STATUS solve()
CLP.STATUS
public void reset()
public CLP.STATUS maximize()
CLP.STATUS
public CLP.STATUS minimize()
CLP.STATUS
public double getObjectiveValue()
public int getNumVariables()
public int getNumConstraints()
public CLP dualTolerance(double value)
value
- public CLP smallestCoefficient(double value)
value
- public CLP primalTolerance(double value)
value
- public CLP maxIterations(int iter)
iter
- public CLP maxSeconds(int seconds)
seconds
- public CLP scaling(CLP.SCALING scaling)
CLP.SCALING
(default=OFF).scaling
- public CLP presolve(boolean on)
on
- public CLP algorithm(CLP.ALGORITHM algorithm)
CLP.ALGORITHM
(default=AUTO).algorithm
- public void finalize()
finalize
in class java.lang.Object
public void printModel()
CLP#toString()}
public java.lang.String toString()
toString
in class java.lang.Object