|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ilog.cplex.IloCplex.Goal
Goals can be used to control the branch-and-cut search in
IloCplex
. Goals are implemented in subclasses of class
IloCplex.Goal
. Thus, this is the base class for
user-written implementation classes of CPLEX goals.
To implement your own goal, you need to create a subclass of
IloCplex.Goal
and implement its pure virtual method
execute
. After implementing your goal class, you use it
by calling the method IloCplex.solve(goal)
instead of
the standard IloCplex.solve
without parameter.
The execute
method is called by IloCplex
at each branch-and-cut node (referred to as the current node) after the
node relaxation has been
solved. Every node maintains a stack of goals, and the top goal from this
stack is popped and executed until the stack becomes empty or some
special goal is encountered as described below. When the goal stack of
a node becomes empty, IloCplex continues with its built-in search for that
subtree. When calling IloCplex.solve(goal)
,
goal
is simply pushed on the goal stack of the root node
before commencing the branch-and-cut search.
The method IloCplex.Goal.execute
is where you
can control the branch-and-cut search of IloCplex
. Class
IloCplex.Goal
provides several methods for querying
information about the current node. It is, however, the goal returned
by the execute
method that determines how to proceed with
the search. IloCplex
provides several methods that create
special goals that can be used to define the ongoing search in addition
to any user-written goal:
IloCplex.or
creates a goal that will create child
nodes when executed. One child will be created for every
parameter passed to method IloCplex.or
. Each
child node will be initialized with a copy of the goal stack of
the current node. Goals provided to the
IloCplex.or
method as parameters are then
pushed onto the goal stack of the
corresponding child. Finally, the current node will be
deleted and a new node will be picked from the tree for evaluation.
IloCplex.constraintGoal
with a constraint as its
parameter as a local cut. When executed, the constraint will be
added to the node problem for all nodes in that subtree. It will
not, however, be added to nodes outside the subtree; use the method
IloCplex.globalCutGoal
for doing this.
Other methods for creating
constraint goals more conveniently are IloCplex.leGoal
,
IloCplex.geGoal
, and IloCplex.eqGoal
.IloCplex.globalCutGoal
. When executed, they add a
global cut to the model being solved.IloCplex.and
takes several goals as
parameters.
When executed, it simply pushes these goals on the goal stack in
reverse order so that they will be executed in the order they have
been provided as parameters.IloCplex.solutionGoal
returns a goal that
attempts to inject a solution into the branch-and-cut search.IloCplex.branchAsCplex
will cause
IloCplex
to
continue with its own branching decision. This is different from
continuing with an empty goal stack in that goals can still be
executed at every node, thus maintaining the possibility of
taking control at any time.IloCplex.failGoal
is executed, the current node will be pruned. That is, the search
will be discontinued below the current node. If available, one of
the remaining nodes from the branch-and-cut tree will be chosen for
evaluation.null
, which
will simply be ignored.Goals returned by IloCplex.or
and
IloCplex.and
allow you to combine goals.
IloCplex.and
allows you to execute different goals at
one node, while IloCplex.or
allows you to execute
different goals on different newly, created nodes. A typical use of
these two goals in a return statement of a user written goal is:
return cplex.and ( cplex.or (branch1, branch2), this);
The IloCplex.and
goal first pushes this
,
that is, the goal currently being executed, on the goal stack and then it
pushes the IloCplex.or
goal. Thus the
IloCplex.or
goal is on top of the stack and will be
executed next. When the IloCplex.or
is executed, it
creates two new nodes and copies the remaining goal stack to both of
them. Thus both new nodes will have IloCplex.or
proceeds to
push branch1
on the goal stack of the first child node and
branch2
on the goal stack of the second goal child node.
Typically, branch1
and branch2
would
eventually contain constraint goals so by executing branch1
and branch2
at the respective child nodes, the child nodes
will be restricted to represent smaller subproblems than their parent.
After branch1
and branch2
have been executed
this
is on top of the node stack of both child nodes, that
is, both child nodes will continue branching according to the same rule.
In summary, the above example creates branches described
branch1
and branch2
and continues in both
branches to control the same search strategy this
.
If the default implementation of method clone
is not
adequate and the goal is to be used for parallel optimization,
this method also needs to be implemented by the user. Recall that the
default clone
method performs a shallow copy, so
typically a user implementation would perform a deep copy for
objects that should be local to threads or use the
synchronize
keyword where synchronization is required.
For more information about goals see the chapter in the ILOG CPLEX User's Manual.
Constructor Summary | |
IloCplex.Goal()
|
Method Summary | |
abstract IloCplex.Goal |
execute(ilog.cplex.IloCplex cplex)
This method must be implemented by the user to specify the logic of the goal. |
protected double |
getBestObjValue()
Returns a bound on the optimal solution value of the active problem. |
protected double[] |
getBranches(ilog.concert.IloNumVar[][] vars,
double[][] bounds,
IloCplex.BranchDirection[][] dirs)
Queries the branches IloCplex would create at the current
node unless overridden by the invoking goal. |
protected IloCplex.BranchType |
getBranchType()
Returns the type of branching IloCplex is going to do at
the current node unless overridden by the invoking goal. |
protected double |
getCutoff()
Returns the cutoff for the objective value when nodes are being solved during branch-and-cut search. |
protected IloCplex.BranchDirection |
getDirection(ilog.concert.IloNumVar var)
Returns the branch direction for variable var . |
protected double |
getDownPseudoCost(ilog.concert.IloNumVar var)
Returns the pseudo cost for branching down on variable var . |
protected IloCplex.IntegerFeasibilityStatus[] |
getFeasibilities(ilog.concert.IloNumVar[] var)
Indicates whether the variables in array var are integer feasible, integer infeasible, or implied
integer feasible in the current node solution. |
protected IloCplex.IntegerFeasibilityStatus[] |
getFeasibilities(ilog.concert.IloNumVar[] var,
int start,
int num)
Indicates whether the specified variables in array var are integer feasible, integer infeasible, or implied
integer feasible in the current node solution. |
protected IloCplex.IntegerFeasibilityStatus |
getFeasibility(ilog.concert.IloNumVar var)
Indicates whether the variable var is integer feasible,
integer infeasible, or implied integer feasible in the current node
solution. |
protected double |
getIncumbentObjValue()
Returns the objective value of the current best integer solution. |
protected double |
getIncumbentValue(ilog.concert.IloNumVar var)
Returns the value of variable var for the current best
integer solution. |
protected double[] |
getIncumbentValues(ilog.concert.IloNumVar[] vars)
Returns incumbent solution values for an array of variables. |
protected double[] |
getIncumbentValues(ilog.concert.IloNumVar[] vars,
int start,
int num)
Returns the incumbent solution values for a set of variables. |
protected double |
getLB(ilog.concert.IloNumVar var)
Returns the current lower bound for variable var . |
protected double[] |
getLBs(ilog.concert.IloNumVar[] var)
Returns the current lower bounds for an array of variables. |
protected double[] |
getLBs(ilog.concert.IloNumVar[] var,
int start,
int num)
Returns the current lower bounds for a set of variables. |
protected int |
getNbranches()
Returns the number of branches IloCplex is going to create
at the current node unless overridden by the invoking goal. |
protected int |
getNcliques()
Returns the number of clique cuts that have been added to the model during the current optimization. |
protected int |
getNcovers()
Returns the number of cover cuts that have been added to the model during the current optimization. |
protected int |
getNdisjunctiveCuts()
Returns the number of disjunctive cuts that have been added to the model during the current optimization. |
protected int |
getNflowCovers()
Returns the number of flow cover cuts that have been added to the model during the current optimization. |
protected int |
getNflowPaths()
Returns the number of flow path cuts that have been added to the model during the current optimization. |
protected int |
getNfractionalCuts()
Returns the number of fractional cuts that have been added to the model during the current optimization. |
protected int |
getNGUBcovers()
Returns the number of GUB cover cuts that have been added to the model during the current optimization. |
protected int |
getNimpliedBounds()
Returns the number of implied bound cuts that have been added to the model during the current optimization. |
protected int |
getNiterations()
Returns the total number of iterations for solving node problems during the current optimization. |
protected int |
getNMIRs()
Returns the number of mixed integer rounding (MIR) cuts that have been added to the model during the current optimization. |
protected int |
getNnodes()
Returns the number of nodes processed so far in the active branch-and-cut search. |
protected IloCplex.NodeId |
getNodeId()
Returns the node identifier of the current node. |
protected int |
getNremainingNodes()
Returns the number of nodes remaining to be processed, or, equivalently, the number of active nodes in the tree. |
protected double |
getObjCoef(ilog.concert.IloNumVar var)
Returns the linear objective function coefficient for variable var in the model being solved. |
protected double[] |
getObjCoefs(ilog.concert.IloNumVar[] vars)
Returns the linear objective function coefficients for an array of variables in the model being solved. |
protected double[] |
getObjCoefs(ilog.concert.IloNumVar[] vars,
int start,
int num)
Returns the linear objective function coefficients for a set of variables in the model being solved. |
protected double |
getObjValue()
Returns the objective function value of the solution of the continuous relaxation of the current node. |
protected int |
getPriority(ilog.concert.IloNumVar var)
Returns the branch priority for variable var . |
protected double |
getSlack(ilog.concert.IloRange rng)
Returns the slack value of a constraint for the solution of the continuous relaxation of the current node. |
protected double[] |
getSlacks(ilog.concert.IloRange[] rng)
Returns the slack values for an array of constraints for the solution of the current node. |
protected double[] |
getSlacks(ilog.concert.IloRange[] rng,
int start,
int num)
Returns the slack values for a set of constraints for the solution of the current node. |
protected IloCplex.IntegerFeasibilityStatus |
getSOSFeasibility(ilog.concert.IloSOS1 sos)
Indicates whether the special ordered set of type 1 is integer feasible, integer infeasible, or implied integer feasible in the current node solution. |
protected IloCplex.IntegerFeasibilityStatus |
getSOSFeasibility(ilog.concert.IloSOS2 sos)
Indicates whether the special ordered set of type 2 is integer feasible, integer infeasible, or implied integer feasible in the current node solution. |
protected double |
getUB(ilog.concert.IloNumVar var)
Returns the current upper bound for variable var . |
protected double[] |
getUBs(ilog.concert.IloNumVar[] var)
Returns the current upper bounds for an array of variables. |
protected double[] |
getUBs(ilog.concert.IloNumVar[] var,
int start,
int num)
Returns the current upper bounds for a set of variables. |
protected double |
getUpPseudoCost(ilog.concert.IloNumVar var)
Returns the pseudo cost for branching up on variable var . |
protected double |
getValue(ilog.concert.IloNumExpr expr)
Returns the value expr takes for the solution of the
current node relaxation. |
protected double |
getValue(ilog.concert.IloNumVar var)
Returns the solution value of a variable at the current node. |
protected double[] |
getValues(ilog.concert.IloNumVar[] var)
Returns the solution values for an array of variables at the current node. |
protected double[] |
getValues(ilog.concert.IloNumVar[] var,
int start,
int num)
Returns the solution values for a set of variables at the current node. |
protected boolean |
hasIncumbent()
Returns true if an incumbent solution has been found. |
protected boolean |
isIntegerFeasible()
Returns true if current solution is integer feasible |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public IloCplex.Goal()
Method Detail |
public abstract IloCplex.Goal execute(ilog.cplex.IloCplex cplex) throws IloException
IloCplex.Goal
returned by this method
will be pushed on the goal stack and will thus be executed next.
cplex
- The IloCplex
object calling this method.
IloCplex.Goal
that will be
pushed on to the goal stack of the current.
IloException
protected double getBestObjValue() throws IloException
When a model has been solved to optimality, this value matches the optimal solution value. Before optimality has been proven, this value is computed for a minimization (maximization) problem as the minimum (maximum) objective function value of all remaining unexplored nodes.
IloException
- If the method fails, an exception
of type IloException
, or
one of its derived classes, is thrown.protected final double getCutoff() throws IloException
IloException
protected final double getIncumbentObjValue() throws IloException
IloException
protected final double getIncumbentValue(ilog.concert.IloNumVar var) throws IloException
var
for the current best
integer solution.
This method returns the value of variable var
in the
current incumbent solution (that is, the best integer solution found so
far).
var
- The variable whose incumbent solution value is being queried.
var
in the current
incumbent solution.
IloException
protected final double[] getIncumbentValues(ilog.concert.IloNumVar[] vars) throws IloException
vars
- The array of variables whose
incumbent solution values are being queried.
var
.
The solution value for variable var[j]
is
returned as element j
of the returned array.
IloException
protected final double[] getIncumbentValues(ilog.concert.IloNumVar[] vars, int start, int num) throws IloException
vars
- An array containing the variables whose
incumbent solution values are being queried.start
- The index of the first variable in vars
for which to return the incumbent solution value.num
- The number of variables in vars
for which
to return the incumbent solution values.
var
. The solution for variable
var[j+start]
is returned as element
j
of the returned array.
IloException
protected final boolean isIntegerFeasible() throws IloException
true
if current solution is integer feasible
true
if current solution is integer feasible
IloException
protected final boolean hasIncumbent() throws IloException
true
if an incumbent solution has been found.
true
if an incumbent solution has been found.
IloException
protected final int getNnodes() throws IloException
IloException
protected final int getNremainingNodes() throws IloException
IloException
protected final int getNiterations() throws IloException
IloException
protected final int getNcliques() throws IloException
IloException
protected final int getNcovers() throws IloException
IloException
protected final int getNflowCovers() throws IloException
IloException
protected final int getNflowPaths() throws IloException
IloException
protected final int getNGUBcovers() throws IloException
IloException
protected final int getNfractionalCuts() throws IloException
IloException
protected final int getNdisjunctiveCuts() throws IloException
IloException
protected final int getNMIRs() throws IloException
IloException
protected final int getNimpliedBounds() throws IloException
IloException
protected final IloCplex.BranchDirection getDirection(ilog.concert.IloNumVar var) throws IloException
var
.
var
- The variable whose branch direction is being queried.
var
.
IloException
protected final int getPriority(ilog.concert.IloNumVar var) throws IloException
var
.
var
- The variable whose branch priority is being queried.
var
IloException
protected final double getLB(ilog.concert.IloNumVar var) throws IloException
var
. This
may be different from the bound the variable has in the active model,
since branching or bound strengthening may have been applied to it.
var
- The variable whose current lower bound is being queried.
var
at the
current node.
IloException
protected final double[] getLBs(ilog.concert.IloNumVar[] var) throws IloException
var
- An array of variables whose current
lower bounds are being queried.
lb
, lb[j] contains the
lower bound of variable var[j]
at the
current node.
IloException
protected final double[] getLBs(ilog.concert.IloNumVar[] var, int start, int num) throws IloException
var
- An array containing the variables whose
current lower bounds are being queried.start
- The index of the first variable in var
for
which to query the current lower bound.num
- The number of variables in var
for which
to query the current lower bounds.
lb
, lb[j]
contains the lower bound of variable
var[j+start]
at the current node,
for j = 0, ..., num-1
.
IloException
protected final double getUB(ilog.concert.IloNumVar var) throws IloException
var
. This
may be different from the bound the variable has in the active model,
since branching or bound strengthening may have been applied to it.
var
- The variable whose current upper bound is being queried.
var
at the
current node.
IloException
protected final double[] getUBs(ilog.concert.IloNumVar[] var) throws IloException
var
- An array of variables whose current
upper bounds is being queried.
ub
, ub[j] contains the
upper bound of variable var[j]
at the
current node.
IloException
protected final double[] getUBs(ilog.concert.IloNumVar[] var, int start, int num) throws IloException
var
- An array containing the variables whose
current upper bounds are being queried.start
- The index of the first variable in var
for
which to query the current upper bound.num
- The number of variables in var
for which
to query the current upper bounds.
ub
, ub[j]
contains the upper bound of variable
var[j+start]
at the current node,
for j = 0, ..., num-1
.
IloException
protected final double getObjValue() throws IloException
IloException
protected final double getValue(ilog.concert.IloNumVar var) throws IloException
var
- The variable whose current solution
value is being queried.
var
at
the current node.
IloException
protected final double[] getValues(ilog.concert.IloNumVar[] var) throws IloException
var
- An array of variables whose current
solution values are being queried.
x
,
x[j]
contains the current solution value
for variable var[j]
.
IloException
protected final double[] getValues(ilog.concert.IloNumVar[] var, int start, int num) throws IloException
var
- An array containing the variables whose
current solution values are being queried.start
- The index of the first variable in var
for
which to query the current solution values.num
- The number of variables in var
for which to
query the current solution values.
x
,
x[j]
is the current solution value
for variable var[j+start]
.
IloException
protected final double getSlack(ilog.concert.IloRange rng) throws IloException
rng
- The constraint whose current slack
value is being queried.
rng
for
the solution of the continuous relaxation of the
current node.
IloException
protected final double[] getSlacks(ilog.concert.IloRange[] rng) throws IloException
rng
- An array of constraints whose current
slack values are being queried.
s
,
s[i]
contains the current slack value
for constraint rng[i]
.
IloException
protected final double[] getSlacks(ilog.concert.IloRange[] rng, int start, int num) throws IloException
rng
- An array containing the constraints whose
current slack values are being queried.start
- The index of the first constraint in rng
for which to query the current slack values.num
- The number of constraints in rng
for which
to query the current slack values.
s
is the returned array,
s[i]
contains the current slack value
for constraint rng[i+start]
.
IloException
protected final double getValue(ilog.concert.IloNumExpr expr) throws IloException
expr
takes for the solution of the
current node relaxation.
expr
- The expression for which to evaluate the current solution.
expr
takes for the solution of the
continuous relaxation of the current node.
IloException
protected final double getObjCoef(ilog.concert.IloNumVar var) throws IloException
var
in the model being solved.
var
- The variable whose linear objective
coefficient is being queried.
var
in the model being solved.
IloException
protected final double[] getObjCoefs(ilog.concert.IloNumVar[] vars) throws IloException
vars
- An array of variables whose linear
objective function coefficients are being queried.
obj
, obj[j]
is the linear objective function coefficient for
variable var[j]
.
IloException
protected final double[] getObjCoefs(ilog.concert.IloNumVar[] vars, int start, int num) throws IloException
vars
- An array containing the variables whose
linear objective function coefficients are being queried.start
- The index of the first variable in var
for
which to query the linear objective function coefficients.num
- The number of variables in var
for which to
query the linear objective function coefficients.
obj
is the returned array, obj[j]
is the
linear objective function coefficient for variable
var[j+start]
, for
j = 0, ..., num-1
.
IloException
protected final double getDownPseudoCost(ilog.concert.IloNumVar var) throws IloException
var
.
var
- The variable whose down pseudo cost is being queried.
var
.
IloException
protected final double getUpPseudoCost(ilog.concert.IloNumVar var) throws IloException
var
.
var
- The variable whose up pseudo cost is being queried.
var
.
IloException
protected final IloCplex.IntegerFeasibilityStatus getFeasibility(ilog.concert.IloNumVar var) throws IloException
var
is integer feasible,
integer infeasible, or implied integer feasible in the current node
solution.
var
- The variable whose integer feasibility status is being
queried.
var
.
IloException
protected final IloCplex.IntegerFeasibilityStatus[] getFeasibilities(ilog.concert.IloNumVar[] var) throws IloException
var
are integer feasible, integer infeasible, or implied
integer feasible in the current node solution.
var
- An array of variables for which the integer feasibility
status is queried.
var
at the current node. The
integer feasibility status of variable var[j]
will be returned as element j
of the returned
array.
IloException
protected final IloCplex.IntegerFeasibilityStatus[] getFeasibilities(ilog.concert.IloNumVar[] var, int start, int num) throws IloException
var
are integer feasible, integer infeasible, or implied
integer feasible in the current node solution.
var
- An array containing the variables whose integer
feasibility status is being queried.start
- The index of the first variable in the array
var
for which the integer feasibility status
is queried.num
- The number of variables in the array var
,
for which the integer infeasibility statuses are
queried.
var
at the current
node. If the returned array is inf
, the
feasibility status for variable var[start+j]
will be returned as inf[j]
.
IloException
protected final IloCplex.IntegerFeasibilityStatus getSOSFeasibility(ilog.concert.IloSOS1 sos) throws IloException
sos
- The SOS1 for which the integer feasibility status is
queried.
sos
.
IloException
protected final IloCplex.IntegerFeasibilityStatus getSOSFeasibility(ilog.concert.IloSOS2 sos) throws IloException
sos
- The SOS2 for which the integer feasibility status is
queried.
sos
.
IloException
protected final IloCplex.NodeId getNodeId() throws IloException
IloException
protected final int getNbranches() throws IloException
IloCplex
is going to create
at the current node unless overridden by the invoking goal.
IloCplex
is going to create
at the current node.
IloException
protected final IloCplex.BranchType getBranchType() throws IloException
IloCplex
is going to do at
the current node unless overridden by the invoking goal.
IloCplex
is going to do at
the current node.
IloException
protected double[] getBranches(ilog.concert.IloNumVar[][] vars, double[][] bounds, IloCplex.BranchDirection[][] dirs) throws IloException
IloCplex
would create at the current
node unless overridden by the invoking goal. The returned branch
will be performed if the callback does not call the method
makeBranch
or prune
.
vars
- An array of length at least getNbranches
of arrays, where the variables the bounds of which
would be changed for each branch will be stored.
Upon completion vars[i]
will contain an
array with the list of variables used for branch
i
.bounds
- An array of length at least getNbranches
of arrays where the new bounds for the variables
IloCplex
would branch on each branch will
be stored. Upon completion bounds[i]
will
contain an array with the list of new bounds used
for branch i
. One bound of variable
vars[i][j]
will be set to
bounds[i][j]
for all possible
pairs i, j
.dirs
- An array of length at least getNbranches
of arrays where the branch directions for each branch
will be stored. Upon completion of this method
dirs[i] will contain an array with the list of branch
directions used for branch i
. If
dirs[i][j]
is
IloCplex.BranchDirection.Up
the lower
bound of variable vars[i][j]
will be set
to bounds[i][j]
for all possible pairs
i, j
. Similarly, if dirs[i][j]
is IloCplex.BranchDirection.Down
the upper
bound of variable vars[i][j]
will be set
to bounds[i][j]
for all possible pairs
i, j
.
IloException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |