public abstract static class IloCplex.HeuristicCallback extends IloCplex.ControlCallback
During branching, the heuristic callback is called after each node subproblem has been solved, including any cuts that may have been newly generated. Before branching, at the root node, the heuristic callback is also called before each round of cuts is added to the problem and re-solved.
The callback also provides support for implementing simplex-based heuristics for constructing solutions, by allowing you to change the bounds of variables and re-solve the node relaxation. Changing the bounds in the heuristic callback has no effect on the search once the callback has completed. This callback will be called after the node relaxation (including all cuts generated at that node) has been solved.
The constructor and methods of this class are protected to make sure that
they are used only to derive a user-written callback class or to implement
the main method in it.
IloCplex.ControlCallbackIloCplex.MIPCallback.NodeData| Modifier | Constructor and Description |
|---|---|
protected |
IloCplex.HeuristicCallback()
Constructor for user-written heuristic callbacks.
|
| Modifier and Type | Method and Description |
|---|---|
protected IloCplex.CplexStatus |
getCplexStatus()
Returns the
IloCplex.CplexStatus for the current node. |
protected IloCplex.Status |
getStatus()
Returns the solution status for the current node.
|
boolean |
isDualFeasible()
Returns
true if a dual feasible solution is available for the
current node. |
boolean |
isPrimalFeasible()
Returns
true if a primal feasible solution is available for the
current node. |
protected void |
setBounds(IloNumVar[] var,
double[] lb,
double[] ub)
Changes the upper and lower bounds of variables in the array
var. |
protected void |
setBounds(IloNumVar[] var,
double[] lb,
double[] ub,
int start,
int num)
Changes the upper and lower bounds of the specified variables in the array
var. |
protected void |
setBounds(IloNumVar var,
double lb,
double ub)
Changes the upper and lower bounds of the variable
var. |
protected void |
setSolution(IloNumVar[] vars,
double[] vals)
Injects a solution to be used as the potential new incumbent.
|
protected void |
setSolution(IloNumVar[] vars,
double[] vals,
int start,
int num)
Injects a solution to be used as the potential new incumbent.
|
protected boolean |
solve()
Solves the current node relaxation using the default algorithm.
|
protected boolean |
solve(int alg)
Solves the current node relaxation using a chosen algorithm.
|
getDownPseudoCost, getFeasibilities, getFeasibilities, getFeasibility, getLB, getLBs, getLBs, getNodeData, getObjValue, getSlack, getSlacks, getSlacks, getSOSFeasibility, getSOSFeasibility, getUB, getUBs, getUBs, getUpPseudoCost, getValue, getValue, getValues, getValues, setNodeDatagetObjCoef, getObjCoefs, getObjCoefs, getUserThreadsgetBestObjValue, getCutoff, getDirection, getIncumbentObjValue, getIncumbentValue, getIncumbentValue, getIncumbentValues, getIncumbentValues, getMIPRelativeGap, getMyThreadNum, getNiterations, getNnodes, getNremainingNodes, getPriority, hasIncumbentabort, getCplexTime, getDetTime, getEndDetTime, getEndTime, getEnvImpl, getModel, getNcols, getNQCs, getNrows, getStartDetTime, getStartTime, mainprotected IloCplex.HeuristicCallback()
IloCplex.HeuristicCallback objects
directly.protected void setBounds(IloNumVar var, double lb, double ub) throws IloException
var.
For the variable var, this method sets its upper bound to the
corresponding value ub and its lower bound to the value
lb. Setting bounds has no effect beyond the scope of the current
invocation of the callback.
Use this method only when presolve is turned off. Otherwise, you risk
attempting to change the bounds of a variable that has been removed during
the presolve. To check whether presolve is off, consider the parameter
IloCplex.BooleanParam.PreInd. Alternatively, you can check
whether a particular variable has been removed by presolve by checking the
status of the variable. To do so, call
IloControlCallback.getFeasibilities. A variable that has been
removed by presolve will have the status ImpliedFeasible.
IloExceptionvar - The variable whose bounds are to be changed.lb - The lower bound of var to be changed.ub - The upper bound of var to be changed.protected void setBounds(IloNumVar[] var, double[] lb, double[] ub) throws IloException
var.
For each variable in the array var, this method sets its upper
bound to the corresponding value in the array ub and its lower
bound to the corresponding value in the array lb. Setting bounds
has no effect beyond the scope of the current invocation of the callback.
Use this method only when presolve is turned off. Otherwise, you risk
attempting to change the bounds of a variable that has been removed during
the presolve. To check whether presolve is off, consider the parameter
IloCplex.BooleanParam.PreInd. Alternatively, you can check
whether a particular variable has been removed by presolve by checking the
status of the variable. To do so, call
IloControlCallback.getFeasibilities. A variable that has been
removed by presolve will have the status ImpliedFeasible.
IloExceptionvar - The array of variables for which the bounds are to be changed.lb - The array of lower bounds to be set. The lower bound of variable
var[j] will be set to lb[j].ub - The array of upper bounds to be set. The upper bound of variable
var[j] will be set to ub[j].protected void setBounds(IloNumVar[] var, double[] lb, double[] ub, int start, int num) throws IloException
var.
For each variable selected from array var, this method sets its
upper bound to the corresponding value in the array ub and its
lower bound to the corresponding value in the array lb. Setting
bounds has no effect beyond the scope of the current invocation of the
callback.
Use this method only when presolve is turned off. Otherwise, you risk
attempting to change the bounds of a variable that has been removed during
the presolve. To check whether presolve is off, consider the parameter
IloCplex.BooleanParam.PreInd. Alternatively, you can check
whether a particular variable has been removed by presolve by checking the
status of the variable. To do so, call
IloControlCallback.getFeasibilities. A variable that has been
removed by presolve will have the status ImpliedFeasible.
IloExceptionvar - The array containing the variables for which the bounds are to
be changed.lb - The array containing the lower bounds to be set. The lower bound
of variable var[j] will be set to
lb[j].ub - The array containing the upper bounds to be set. The upper bound
of variable var[j] will be set to
ub[j].start - The index of the first variable in var for which
the bounds are to be set.num - The number of variables in var for which the bounds
are to be set.protected boolean solve(int alg)
throws IloException
setBounds. The algorithm
alg will be used to solve the node.IloExceptionalg - The algorithm to use to solve the node relaxation.true if a feasible solution has been
found and false otherwise.IloCplex.Algorithmprotected boolean solve()
throws IloException
setBounds.IloExceptiontrue if a feasible solution has been
found and false otherwise.IloCplex.Algorithmprotected IloCplex.Status getStatus() throws IloException
IloCplex at the
current node during the last call to the method
IloCplex.HeuristicCallback.solve (which may have been called
directly in the callback or by IloCplex when processing the node
just before the callback is called).IloExceptionIloCplex.Statusprotected IloCplex.CplexStatus getCplexStatus() throws IloException
IloCplex.CplexStatus for the current node. This
method returns the IloCplex.CplexStatus of the solution found by
the instance of IloCplex at the current node during the last
call to the method IloCplex.HeuristicCallback.solve (which may
have been called directly in the callback or by IloCplex when
processing the node just before the callback is called).IloExceptionIloCplex.CplexStatuspublic boolean isDualFeasible()
throws IloException
true if a dual feasible solution is available for the
current node. If false is returned the solution may still be
dual feasible, but the algorithm has not determined the feasibility before it
terminated.IloExceptionpublic boolean isPrimalFeasible()
throws IloException
true if a primal feasible solution is available for the
current node. If false is returned the solution may still be
primal feasible, but the algorithm has not determined the feasibility before
it terminated.IloExceptionprotected void setSolution(IloNumVar[] vars, double[] vals, int start, int num) throws IloException
If a user heuristic is successful in finding a new candidate for an
incumbent, it can be passed to IloCplex by the method
setSolution. IloCplex analyzes the solution and, if
it is both feasible and better than the current incumbent, uses it as the new
incumbent. A solution is specified using arrays vars and
vals, where vals[i] specifies the solution value
for vars[i].
IloExceptionvars - An array containing variables whose solution values are
specified.vals - An array containing the solution values for the variables
specified in vars. vals[j] specifies
the solution value for vars[j] for j
in start through start+num-1.start - The index of the first element to consider in arrays
vars and vals.num - The number of elements to consider in arrays vars
and vals .protected void setSolution(IloNumVar[] vars, double[] vals) throws IloException
If a user heuristic is successful in finding a new candidate for an
incumbent, it can be passed to IloCplex by the method
setSolution. IloCplex analyzes the solution and, if
it is both feasible and better than the current incumbent, uses it as the new
incumbent. A solution is specified using arrays vars and
vals, where vals[i] specifies the solution value
for vars[i].
IloExceptionvars - An array of variables whose solution values are specified.vals - An array containing the solution values for the variables
specified in vars. vals[j] specifies
the solution value for vars[j].