ilog.cplex
Class IloCplex.HeuristicCallback

java.lang.Object
  |
  +--ilog.cplex.IloCplex.Callback
        |
        +--ilog.cplex.IloCplex.MIPCallback
              |
              +--ilog.cplex.IloCplex.ControlCallback
                    |
                    +--ilog.cplex.IloCplex.HeuristicCallback
All Implemented Interfaces:
java.lang.Cloneable
Enclosing class:
IloCplex

public abstract static class IloCplex.HeuristicCallback
extends IloCplex.ControlCallback

The base class for user-written callbacks that allows you to inject integer-feasible solutions during the branch-and-cut search.

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.

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(ilog.concert.IloNumVar[] var, double[] lb, double[] ub)
          Changes the upper and lower bounds of variables in the array var.
protected  void setBounds(ilog.concert.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(ilog.concert.IloNumVar var, double lb, double ub)
          Changes the upper and lower bounds of variable var.
protected  void setSolution(ilog.concert.IloNumVar[] vars, double[] vals)
          Injects a solution to be used as the potential new incumbent.
protected  void setSolution(ilog.concert.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.
 
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, getMyThreadNum, getNcliques, getNcovers, getNdisjunctiveCuts, getNflowCovers, getNflowPaths, getNfractionalCuts, getNGUBcovers, getNimpliedBounds, getNiterations, getNMIRs, getNnodes, getNremainingNodes, getObjCoef, getObjCoefs, getObjCoefs, getPriority, getUserThreads, 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(ilog.concert.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.

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

setBounds

protected void setBounds(ilog.concert.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.

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].
IloException

setBounds

protected void setBounds(ilog.concert.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.

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 variables in var for which the bounds are to be set.
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.
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.
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).

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

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.

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.

IloException

setSolution

protected void setSolution(ilog.concert.IloNumVar[] vars,
                           double[] vals,
                           int start,
                           int num)
                    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].

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

setSolution

protected void setSolution(ilog.concert.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].

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].
IloException