NO FRAMES

Class IloCplex::HeuristicCallbackI

Definition file: ilcplex/ilocplexi.h
Note

This is an advanced class. Advanced classes typically demand a profound understanding of the algorithms used by ILOG CPLEX. Thus they incur a higher risk of incorrect behavior in your application, behavior that can be difficult to debug. Therefore, ILOG 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:

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:

Method Summary
protected IloCplex::CplexStatusgetCplexStatus() const
protected IloAlgorithm::StatusgetStatus() const
protected IloBoolisDualFeasible() const
protected IloBoolisPrimalFeasible() const
protected voidsetBounds(const IloIntVarArray var, const IloNumArray lb, const IloNumArray ub)
protected voidsetBounds(const IloNumVarArray var, const IloNumArray lb, const IloNumArray ub)
protected voidsetBounds(const IloIntVar var, IloNum lb, IloNum ub)
protected voidsetBounds(const IloNumVar var, IloNum lb, IloNum ub)
protected voidsetSolution(const IloIntVarArray vars, const IloNumArray vals, IloNum obj)
protected voidsetSolution(const IloIntVarArray vars, const IloNumArray vals)
protected voidsetSolution(const IloNumVarArray vars, const IloNumArray vals, IloNum obj)
protected voidsetSolution(const IloNumVarArray vars, const IloNumArray vals)
protected IloBoolsolve(IloCplex::Algorithm alg=Dual)
Inherited Methods from ControlCallbackI
getDownPseudoCost, getDownPseudoCost, getFeasibilities, getFeasibilities, getFeasibility, getFeasibility, getFeasibility, getFeasibility, getLB, getLB, getLBs, getLBs, getNodeData, getObjValue, getSlack, getSlacks, getUB, getUB, getUBs, getUBs, getUpPseudoCost, getUpPseudoCost, getValue, getValue, getValue, getValues, getValues, isSOSFeasible, isSOSFeasible
Inherited Methods from MIPCallbackI
getNcliques, getNcovers, getNdisjunctiveCuts, getNflowCovers, getNflowPaths, getNfractionalCuts, getNGUBcovers, getNimpliedBounds, getNMIRs, getObjCoef, getObjCoef, getObjCoefs, getObjCoefs, getUserThreads
Inherited Methods from MIPInfoCallbackI
getBestObjValue, getCutoff, getDirection, getDirection, getIncumbentObjValue, getIncumbentSlack, getIncumbentSlacks, getIncumbentValue, getIncumbentValue, getIncumbentValues, getIncumbentValues, getMyThreadNum, getNiterations, getNnodes, getNremainingNodes, getPriority, getPriority, hasIncumbent
Inherited Methods from OptimizationCallbackI
getModel, getNcols, getNQCs, getNrows
Inherited Methods from CallbackI
abort, duplicateCallback, getEnv, main
Method Detail

getCplexStatus

protected IloCplex::CplexStatus getCplexStatus() const

This method returns the ILOG 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.


getStatus

protected IloAlgorithm::Status getStatus() const

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.


isDualFeasible

protected IloBool isDualFeasible() const

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.


isPrimalFeasible

protected IloBool isPrimalFeasible() const

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.


setBounds

protected void setBounds(const IloIntVarArray var, const IloNumArray lb, const IloNumArray ub)

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.


setBounds

protected void setBounds(const IloNumVarArray var, const IloNumArray lb, const IloNumArray ub)

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.


setBounds

protected void setBounds(const IloIntVar var, IloNum lb, IloNum ub)

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.


setBounds

protected void setBounds(const IloNumVar var, IloNum lb, IloNum ub)

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.


setSolution

protected void setSolution(const IloIntVarArray vars, const IloNumArray vals, IloNum obj)

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 analyses 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 parameter 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.


setSolution

protected void setSolution(const IloIntVarArray vars, const IloNumArray vals)

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 analyses 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.


setSolution

protected void setSolution(const IloNumVarArray vars, const IloNumArray vals, IloNum obj)

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 analyses 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 parameter 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.


setSolution

protected void setSolution(const IloNumVarArray vars, const IloNumArray vals)

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 analyses 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.


solve

protected IloBool solve(IloCplex::Algorithm alg=Dual)

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.