ilog.cplex
Class IloCplex.HeuristicCallback

java.lang.Object
  extended byilog.cplex.IloCplex.Callback
      extended byilog.cplex.IloCplex.MIPCallback
          extended byilog.cplex.IloCplex.ControlCallback
              extended byilog.cplex.IloCplex.HeuristicCallback
All Implemented Interfaces:
java.lang.Cloneable
Enclosing class:
IloCplex

public abstract static class IloCplex.HeuristicCallback
extends IloCplex.ControlCallback

Base class for user-written callbacks injecting integer-feasible solutions during search.

This is an advanced class.

Important:

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.

This is the base class for user-written callbacks allowing you to inject integer-feasible solutions during the branch-and-cut search. 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.

This callback class 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 after 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.

See Also:
IloCplex.ControlCallback

Constructor Summary
protected IloCplex.HeuristicCallback()
          Constructor for user-written heuristic callbacks.
 
Method Summary
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 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 from an array that may possibly contain other elements.
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.
 
Methods inherited from class ilog.cplex.IloCplex.ControlCallback
getDownPseudoCost, getFeasibilities, getFeasibilities, getFeasibility, getLB, getLBs, getLBs, getNodeData, getObjValue, getSlack, getSlacks, getSlacks, getSOSFeasibility, getSOSFeasibility, getUB, getUBs, getUBs, getUpPseudoCost, getValue, getValue, getValues, getValues
 
Methods inherited from class ilog.cplex.IloCplex.MIPCallback
getBestObjValue, getCutoff, getDirection, getIncumbentObjValue, getIncumbentValue, getIncumbentValues, getIncumbentValues, getNcliques, getNcovers, getNdisjunctiveCuts, getNflowCovers, getNflowPaths, getNfractionalCuts, getNGUBcovers, getNimpliedBounds, getNiterations, getNMIRs, getNnodes, getNremainingNodes, getObjCoef, getObjCoefs, getObjCoefs, getPriority, hasIncumbent
 
Methods inherited from class ilog.cplex.IloCplex.Callback
abort, getModel, getNcols, getNQCs, getNrows, main
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IloCplex.HeuristicCallback

protected IloCplex.HeuristicCallback()
Constructor for user-written heuristic callbacks. This constructor can be called only to construct objects of derived user-written callback classes, but not to construct IloCplex.HeuristicCallback objects directly.

Method Detail

setBounds

protected void setBounds(IloNumVar var,
                         double lb,
                         double ub)
                  throws IloException
Changes the upper and lower bounds of variable 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.

Parameters:
var - 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.
Throws:
IloException

setBounds

protected void setBounds(IloNumVar[] var,
                         double[] lb,
                         double[] ub)
                  throws IloException
Changes the upper and lower bounds of variables in the array 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.

Parameters:
var - 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].
Throws:
IloException

setBounds

protected void setBounds(IloNumVar[] var,
                         double[] lb,
                         double[] ub,
                         int start,
                         int num)
                  throws IloException
Changes the upper and lower bounds of the specified variables in the array 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.

Parameters:
var - 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 consecutive variables in var for which the bounds are to be set.
Throws:
IloException

solve

protected boolean solve(int alg)
                 throws IloException
Solves the current node relaxation using a chosen algorithm. This method can be used to solve the current node, usually after some bounds have been changed, for example, by the method setBounds. The algorithm alg will be used to solve the node.

Parameters:
alg - The algorithm to use to solve the node relaxation.
Returns:
This method returns true if a feasible solution has been found and false otherwise.
Throws:
IloException
See Also:
IloCplex.Algorithm

solve

protected boolean solve()
                 throws IloException
Solves the current node relaxation using the default algorithm. This method can be used to solve the current node, usually after some bounds have been changed, for example, by the method setBounds.

Returns:
This method returns true if a feasible solution has been found and false otherwise.
Throws:
IloException
See Also:
IloCplex.Algorithm

getStatus

protected IloCplex.Status getStatus()
                             throws IloException
Returns the solution status for the current node. This method returns the status 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).

Throws:
IloException
See Also:
IloCplex.Status

getCplexStatus

protected IloCplex.CplexStatus getCplexStatus()
                                       throws IloException
Returns the 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).

Throws:
IloException
See Also:
IloCplex.CplexStatus

isDualFeasible

public boolean isDualFeasible()
                       throws IloException
Returns 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.

Throws:
IloException

isPrimalFeasible

public boolean isPrimalFeasible()
                         throws IloException
Returns 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.

Throws:
IloException

setSolution

protected void setSolution(IloNumVar[] vars,
                           double[] vals,
                           int start,
                           int num)
                    throws IloException
Injects a solution to be used as the potential new incumbent from an array that may possibly contain other elements.

The injected solution is specified by providing solution values for all variables in the model. The array used to specify the values may contain more elements; in that case, use the argument start to specify the starting element and the argument num to specify the number of consecutive elements to use.

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, 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 overwrites any previously specified solution.

Parameters:
vars - 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 consecutive elements to consider in arrays vars and vals.
Throws:
IloException

setSolution

protected void setSolution(IloNumVar[] vars,
                           double[] vals)
                    throws IloException
Injects a solution to be used as the potential new incumbent.

The injected solution is specified by providing solution values for all variables. 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].

Do not call this method multiple times. Calling it again overwrites any previously specified solution.

Parameters:
vars - 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].
Throws:
IloException