Overview | Group | Tree | Graph | Deprecated | Index | Concepts |
This is an advanced class. Advanced classes typically demand a profound understanding of the algorithms used by CPLEX. Thus they incur a higher risk of incorrect behavior in your application, behavior that can be difficult to debug. Therefore, the team encourages you to consider carefully whether you can accomplish the same task by means of other classes instead.
An instance of the class IloCplex::HeuristicCallbackI
represents a user-written callback in an application that uses an instance
of IloCplex
to solve a mixed integer programming problem
(MIP). When you derive a user-defined class of callbacks,
this class offers protected methods for you to:
IloCplex
a potential new incumbent
solution;IloCplex
about the solution status
for the current node;IloCplex
about the variable bounds
at the current node;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.
In short, this callback allows you to attempt to construct an integer
feasible solution at a node and pass it to the invoking instance of
IloCplex
to use as its new incumbent. The API supports you in
finding such a solution by allowing you iteratively to change bounds of the
variables and re-solve the node relaxation. Changing the bounds in the
heuristic callback has no effect on the search beyond the termination of
the callback.
If an attempt is made to access information not available
at the node for
the invoking instance of IloCplex
, an exception is thrown.
See Also:
IloCplex, IloCplex::Callback, IloCplex::CallbackI, IloCplex::ControlCallbackI, IloCplex::MIPCallbackI, IloCplex::OptimizationCallbackI, ILOHEURISTICCALLBACK0
Method Summary | |
---|---|
public IloCplex::CplexStatus | getCplexStatus() const |
public IloAlgorithm::Status | getStatus() const |
protected Callback::Type | getType() const |
public IloBool | isDualFeasible() const |
public IloBool | isPrimalFeasible() const |
public void | setBounds(const IloIntVarArray var, const IloNumArray lb, const IloNumArray ub) |
public void | setBounds(const IloNumVarArray var, const IloNumArray lb, const IloNumArray ub) |
public void | setBounds(const IloIntVar var, IloNum lb, IloNum ub) |
public void | setBounds(const IloNumVar var, IloNum lb, IloNum ub) |
public void | setSolution(const IloIntVarArray vars, const IloNumArray vals, IloNum obj) |
public void | setSolution(const IloIntVarArray vars, const IloNumArray vals) |
public void | setSolution(const IloNumVarArray vars, const IloNumArray vals, IloNum obj) |
public void | setSolution(const IloNumVarArray vars, const IloNumArray vals) |
public IloBool | solve(IloCplex::Algorithm alg=Dual) |
Inherited Methods from MIPCallbackI |
---|
getObjCoef, getObjCoef, getObjCoefs, getObjCoefs, getType, getUserThreads, MIPCallbackI |
Inherited Methods from OptimizationCallbackI |
---|
getModel, getNcols, getNQCs, getNrows |
Inherited Methods from CallbackI |
---|
abort, duplicateCallback, getCplexTime, getDetTime, getEndDetTime, getEndTime, getEnv, getStartDetTime, getStartTime, getType, main |
Method Detail |
---|
This method returns the CPLEX status of the instance of
IloCplex
at the current node (that is, the state of the
optimizer at the node) during the last call to
HeuristicCallbackI::solve
(which may have been called directly in the callback
or by IloCplex
when processing the node).
The enumeration IloCplex::CplexStatus
lists the possible status values.
This method returns the status of the solution found by the
instance of IloCplex
at the current node during the last call
to HeuristicCallbackI::solve
(which may have been called
directly in the callback or by IloCplex
when processing the
node).
The enumeration IloAlgorithm::Status
lists the possible
status values.
This method returns IloTrue
if the solution provided
by the last solve
call is dual feasible. Note that an
IloFalse
return value does not necessarily mean that the
solution is not dual feasible. It simply means that the relevant
algorithm was not able to conclude it was dual feasible when it
terminated.
This method returns IloTrue
if the solution provided
by the last solve
call is primal feasible. Note that an
IloFalse
return value does not necessarily mean that the
solution is not primal feasible. It simply means that the relevant
algorithm was not able to conclude it was primal feasible when it
terminated.
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
, provided var
has not been removed by presolve.
Setting bounds has no effect beyond the scope
of the current invocation of the callback.
When using this method, you must avoid changing the bounds of a
variable that has been removed by presolve.
To check whether presolve is off, consider the
parameter IloCplex::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
IloCplex::ControlCallback::getFeasibilities
.
A variable that has been removed by presolve will have the status
ImpliedFeasible
.
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
, provided the variable has not been removed
by presolve. Setting bounds has no effect beyond the scope
of the current invocation of the callback.
This method sets the lower bound to lb
and the
upper bound to ub
for the variable var
at the
current node, provided
var
has not been removed by presolve.
Setting bounds has no effect beyond the scope of the current
invocation of the callback.
When using this method, you must avoid changing the bounds of a
variable that has been removed by presolve.
To check whether presolve is off, consider the
parameter IloCplex::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
IloCplex::ControlCallback::getFeasibilities
.
A variable that has been removed by presolve will have the status
ImpliedFeasible
.
This method sets the lower bound to lb
and the
upper bound to ub
for the variable var
at the
current node, provided
var
has not been removed by presolve.
Setting bounds has no effect beyond the scope of the
current invocation of the callback.
When using this method, you must avoid changing the bounds of a
variable that has been removed by presolve.
To check whether presolve is off, consider the
parameter IloCplex::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
IloCplex::ControlCallback::getFeasibilities
.
A variable that has been removed by presolve will have the status
ImpliedFeasible
.
For each variable in the array vars
, this method uses
the value in the corresponding element of the array vals
to define a heuristic solution to be considered as a new incumbent.
If the user heuristic was successful in finding a new candidate for an
incumbent, setSolution
can be used to pass it over to
IloCplex
. IloCplex
then 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]
.
The argument obj
is used to tell IloCplex
the objective value of the injected solution. This allows
IloCplex
to skip the computation of that value, but care
must be taken not to provide an incorrect value.
Do not call this method multiple times. Calling it again will overwrite any previously specified solution.
For each variable in the array vars
, this method uses
the value in the corresponding element of the array vals
to define a heuristic solution to be considered as a new incumbent.
If the user heuristic was successful in finding a new candidate for an
incumbent, setSolution
can be used to pass it over to
IloCplex
. IloCplex
then 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]
.
Do not call this method multiple times. Calling it again will overwrite any previously specified solution.
For each variable in the array vars
, this method uses
the value in the corresponding element of the array vals
to define a heuristic solution to be considered as a new incumbent.
If the user heuristic was successful in finding a new candidate for an
incumbent, setSolution
can be used to pass it over to
IloCplex
. IloCplex
then 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]
.
The argument obj
is used to tell IloCplex
the objective value of the injected solution. This allows
IloCplex
to skip the computation of that value, but care
must be taken not to provide an incorrect value.
Do not call this method multiple times. Calling it again will overwrite any previously specified solution.
For each variable in the array vars
, this method uses
the value in the corresponding element of the array vals
to define a heuristic solution to be considered as a new incumbent.
If the user heuristic was successful in finding a new candidate for an
incumbent, setSolution
can be used to pass it over to
IloCplex
. IloCplex
then analyzes the solution
and, if it is both feasible and better than the current incumbent,
IloCplex
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]
.
Do not call this method multiple times. Calling it again will overwrite any previously specified solution.
This method can be used to solve the current node relaxation, usually
after some bounds have been changed by
HeuristicCallbackI::setBounds
.
By default it uses the dual simplex algorithm,
but this behavior can be overridden by the
optional parameter alg
.
See the enumeration IloCplex::Algorithm
for a list of the available optimizers.
This method returns the callback type of the invoking callback object.