Skip to main content
FRAMES NO FRAMES

Class IloCplex::BranchCallbackI

Definition file: ilcplex/ilocplexi.h
Map of IloCplex::BranchCallbackIIloCplex::BranchCallbackIIloCplex::BranchCallbackIIloCplex::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::BranchCallbackI represents a user-written callback in an application that invokes an instance of IloCplex to solve a mixed integer program (MIP). The user-written callback is called prior to branching at a node in the branch-and-cut tree during the optimization of a MIP. It allows the user to query how the invoking instance of IloCplex is about to create subnodes at the current node and gives the user the option to override the selection made by the invoking instance of IloCplex. The user can create zero, one, or two branches.

The methods of this class are for use in deriving a user-written callback class and in implementing the main method there.

If an attempt is made to access information not available to an instance of this class, an exception is thrown.

The user must be careful when using this class. Pruning a valid node can prune the optimal solution. Also, choosing a different branching variable can result in placing an invalid bound on a variable, in case the variable was already restricted to other bounds before.

In particular, the user must not branch on variables that are implied feasible, as defined in IloCplex::ControlCallbackI::IntegerFeasibility. Branching on such variables can cut off feasible solutions.

If the user intends to branch on continuous variables, the user must disable dual presolve reductions. To disable dual presolve reductions, set the parameter to control primal and dual reduction type, IloCplex::Param::Preprocessing::Reduce, either to the value 1 (one) (that is, CPX_PREREDUCE_PRIMALONLY) or to the value 0 (zero) (that is, CPX_PREREDUCE_NOPRIMALORDUAL).

Also, if the user intends to branch on continuous variables, the user must turn off the linear reduction switch, IloCplex::Param::Preprocessing::Linear.

By design, the CPLEX branch callback calculates and provides the branching decisions that CPLEX would make in case the user does not create any branches in the callback. Depending on variable selection and other features of your model, the computation of these candidate branches can be time-consuming. Consequently, if you know that you will never use the branching candidates suggested by CPLEX, then you can save time by disabling such features as strong branching.

See Also:

Method Summary
protected BranchCallbackI(IloEnv env)
public IloNumgetBranch(IloNumVarArray vars, IloNumArray bounds, IloCplex::BranchDirectionArray dirs, IloInt i) const
public BranchCallbackI::BranchTypegetBranchType() const
public IloIntgetNbranches() const
protected Callback::TypegetType() const
public IloBoolisIntegerFeasible() const
public NodeIdmakeBranch(const IloConstraintArray cons, const IloIntVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloConstraintArray cons, const IloNumVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloConstraint con, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloConstraintArray cons, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloIntVar var, IloNum bound, IloCplex::BranchDirection dir, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloNumVar var, IloNum bound, IloCplex::BranchDirection dir, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloIntVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(const IloNumVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)
public NodeIdmakeBranch(IloInt num, NodeData * data=0)
public voidprune()
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
getCurrentNodeDepth, 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
Inner Enumeration
BranchCallbackI::BranchType
Method Detail

BranchCallbackI

protected BranchCallbackI(IloEnv env)

This constructor creates a branch callback, that is, a control callback for splitting a node into two branches.


getBranch

public IloNum getBranch(IloNumVarArray vars, IloNumArray bounds, IloCplex::BranchDirectionArray dirs, IloInt i) const

This method accesses branching information for the i-th branch that the invoking instance of IloCplex is about to create. The argument i must be between 0 (zero) and (getNbranches - 1); that is, it must be a valid index of a branch; normally, it will be zero or one.

A branch is normally defined by a set of variables and the bounds for these variables. Branches that are more complex cannot be queried. The return value is the node estimate for that branch.

dir[j] == IloCplex::BranchUp

means that bounds[j] specifies a lower bound for vars[j].

dirs[j] == IloCplex::BranchDown

means that bounds[j] specifies an upper bound for vars[j].


getBranchType

public BranchCallbackI::BranchType getBranchType() const

This method returns the type of branching IloCplex is going to do for the current node.


getNbranches

public IloInt getNbranches() const

This method returns the number of branches IloCplex is going to create at the current node.


isIntegerFeasible

public IloBool isIntegerFeasible() const

This method returns IloTrue if the solution of the current node is integer feasible.


makeBranch

public NodeId makeBranch(const IloConstraintArray cons, const IloIntVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)

This method offers the same facilities as the other methods IloCplex::BranchCallbackI::makeBranch, but for a branch specified by a set of constraints and a set of variables.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloConstraintArray cons, const IloNumVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)

This method offers the same facilities as the other methods IloCplex::BranchCallbackI::makeBranch, but for a branch specified by a set of constraints and a set of variables.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloConstraint con, IloNum objestimate, NodeData * data=0)

This method offers the same facilities for a branch specified by only one constraint as IloCplex::BranchCallbackI::makeBranch does for a branch specified by a set of constraints.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloConstraintArray cons, IloNum objestimate, NodeData * data=0)

This method overrides the branch chosen by an instance of IloCplex, by specifying a branch on constraints. A method named makeBranch can be called zero, one, or two times in every invocation of the branch callback. If you call it once, it creates one node; it you call it twice, it creates two nodes (one node at each call). If you call it more than twice, it throws an exception.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloIntVar var, IloNum bound, IloCplex::BranchDirection dir, IloNum objestimate, NodeData * data=0)

For a branch specified by only one variable, this method offers the same facilities as IloCplex::BranchCallbackI::makeBranch for a branch specified by a set of variables.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloNumVar var, IloNum bound, IloCplex::BranchDirection dir, IloNum objestimate, NodeData * data=0)

For a branch specified by only one variable, this method offers the same facilities as IloCplex::BranchCallbackI::makeBranch for a branch specified by a set of variables.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloIntVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)

This method overrides the branch chosen by an instance of IloCplex. A method named makeBranch can be called zero, one, or two times in every invocation of the branch callback. If you call it once, it creates one node; it you call it twice, it creates two nodes (one node at each call). If you call it more than twice, it throws an exception.

Each call specifies a branch; in other words, it instructs the invoking IloCplex object how to create a subnode from the current node by specifying new, tighter bounds for a set of variables.

dir[j] == IloCplex::BranchUp

means that bounds[j] specifies a lower bound for vars[j].

dirs[j] == IloCplex::BranchDown

means that bounds[j] specifies an upper bound for vars[j].

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(const IloNumVarArray vars, const IloNumArray bounds, const IloCplex::BranchDirectionArray dirs, IloNum objestimate, NodeData * data=0)

This method overrides the branch chosen by an instance of IloCplex. A method named makeBranch can be called zero, one, or two times in every invocation of the branch callback. If you call it once, it creates one node; if you call it twice, it creates two nodes (one node at each call). If you call it more than twice, it throws an exception.

Each call specifies a branch; in other words, it instructs the invoking IloCplex object how to create a subnode from the current node by specifying new, tighter bounds for a set of variables.

dir[j] == IloCplex::BranchUp

means that bounds[j] specifies a lower bound for vars[j].

dirs[j] == IloCplex::BranchDown

means that bounds[j] specifies an upper bound for vars[j].

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


makeBranch

public NodeId makeBranch(IloInt num, NodeData * data=0)

This method overrides the branch chosen by an instance of IloCplex. A method named makeBranch can be called zero, one, or two times in every invocation of the branch callback. If you call it once, it creates one node; if you call it twice, it creates two nodes (one node at each call). If you call it more than twice, it throws an exception.

Each call creates a child node for the current node that is identical to the branch number that CPLEX is executing and attaches the user object data to the new child node.

The same index num must not be used with more than one call of the function.

See MIPCallbackI::NodeId and MIPCallbackI::NodeData.


prune

public void prune()

By calling this method, you instruct the CPLEX branch-and-cut search not to create any child nodes from the current node, or, in other words, to discard nodes below the current node; it does not revisit the discarded nodes below the current node. In short, it creates no branches. It is an error to call both prune and makeBranch in one invocation of a callback.

Pruning nodes in this way is not compatible with the method IloCplex::populate because that method retains fathomed nodes for subsequent use.


getType

protected Callback::Type getType() const

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


Inner Enumeration Detail

Enumeration BranchType

Definition file: ilcplex/ilocplexi.h

IloCplex::BranchCallbackI::BranchType is an enumeration limited in scope to the class IloCplex::BranchCallbackI. This enumeration is used by the method IloCplex::BranchCallbackI::getBranchType to tell what kind of branch IloCplex is about to do:

See Also:

Fields

BranchOnVariable = CPX_TYPE_VAR 
BranchOnSOS1 = CPX_TYPE_SOS1 
BranchOnSOS2 = CPX_TYPE_SOS2 
BranchOnAny = CPX_TYPE_ANY