Skip to main content
FRAMES NO FRAMES

Class IloCplex::HeuristicCallbackI

Definition file: ilcplex/ilocplexi.h
Map of IloCplex::HeuristicCallbackIIloCplex::HeuristicCallbackIIloCplex::HeuristicCallbackIIloCplex::ControlCallbackIIloCplex::MIPCallbackIIloCplex::MIPInfoCallbackIIloCplex::OptimizationCallbackIIloCplex::CallbackI
Note

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:

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
public IloCplex::CplexStatusgetCplexStatus() const
public IloAlgorithm::StatusgetStatus() const
protected Callback::TypegetType() const
public IloBoolisDualFeasible() const
public IloBoolisPrimalFeasible() const
public voidsetBounds(const IloIntVarArray var, const IloNumArray lb, const IloNumArray ub)
public voidsetBounds(const IloNumVarArray var, const IloNumArray lb, const IloNumArray ub)
public voidsetBounds(const IloIntVar var, IloNum lb, IloNum ub)
public voidsetBounds(const IloNumVar var, IloNum lb, IloNum ub)
public voidsetSolution(const IloIntVarArray vars, const IloNumArray vals, IloNum obj)
public voidsetSolution(const IloIntVarArray vars, const IloNumArray vals)
public voidsetSolution(const IloNumVarArray vars, const IloNumArray vals, IloNum obj)
public voidsetSolution(const IloNumVarArray vars, const IloNumArray vals)
public IloBoolsolve(IloCplex::Algorithm alg=Dual)
Inherited Methods from ControlCallbackI
getDownPseudoCost, getDownPseudoCost, getFeasibilities, getFeasibilities, getFeasibility, getFeasibility, getFeasibility, getFeasibility, getLB, getLB, getLBs, getLBs, getNodeData, getNodeId, getObjValue, getSlack, getSlacks, getUB, getUB, getUBs, getUBs, getUpPseudoCost, getUpPseudoCost, getValue, getValue, getValue, getValues, getValues, isSOSFeasible, isSOSFeasible, setNodeData
Inherited Methods from MIPCallbackI
getObjCoef, getObjCoef, getObjCoefs, getObjCoefs, getType, getUserThreads, MIPCallbackI
Inherited Methods from MIPInfoCallbackI
getBestObjValue, getCutoff, getDirection, getDirection, getIncumbentObjValue, getIncumbentSlack, getIncumbentSlacks, getIncumbentValue, getIncumbentValue, getIncumbentValue, getIncumbentValues, getIncumbentValues, getMIPRelativeGap, getMyThreadNum, getNcuts, getNiterations, getNiterations64, getNnodes, getNnodes64, getNremainingNodes, getNremainingNodes64, getPriority, getPriority, getQuality, getType, hasIncumbent, MIPInfoCallbackI
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

getCplexStatus

public IloCplex::CplexStatus getCplexStatus() const

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.


getStatus

public 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

public 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

public 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

public 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

public 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

public 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

public 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

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


setSolution

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


setSolution

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


setSolution

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


solve

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


getType

protected Callback::Type getType() const

This method returns the callback type of the invoking callback object.