Package cplex :: Module callbacks :: Class BranchCallback
[frames] | no frames]
 

Class BranchCallback


Subclassable class for branch callback classes.

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 particular, the user must not branch on variables that are implied feasible. ImpliedFeasible specifies that the variable has been presolved out. It will be feasible when all other integer variables are integer feasible. 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, parameters.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, parameters.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. This callback will be used prior to branching at a node in the branch and cut tree.

Nested Classes
  branch_type
Constants defining types of branches.

Inherited from ControlCallback: feasibility_status

Inherited from MIPInfoCallback: cut_type, quality_metric

Instance Methods
 
get_branch(self, which_branch)
Returns one of the candidate branches at the current node.
 
get_branch_type(self)
Returns the type of the branch.
 
get_num_branches(self)
Return the number of nodes Cplex will create from this branch.
 
is_integer_feasible(self)
Return whether or not the current node is integer feasible.
 
make_branch(self, objective_estimate, variables=None, constraints=None, node_data=None)
Makes a new branch with the specified data.
 
make_cplex_branch(self, which_branch, node_data=None)
Replicates a CPLEX branch.
 
prune(self)
Removes the current node from the search tree.

Inherited from ControlCallback: get_SOS_feasibilities, get_feasibilities, get_linear_slacks, get_lower_bounds, get_node_ID, get_node_data, get_objective_value, get_pseudo_costs, get_quadratic_slacks, get_upper_bounds, get_values, set_node_data

Inherited from MIPCallback: get_objective_coefficients

Inherited from MIPInfoCallback: get_MIP_relative_gap, get_best_objective_value, get_cutoff, get_float_quality, get_incumbent_linear_slacks, get_incumbent_objective_value, get_incumbent_quadratic_slacks, get_incumbent_values, get_num_cols, get_num_cuts, get_num_iterations, get_num_nodes, get_num_quadratic_constraints, get_num_remaining_nodes, get_num_rows, has_incumbent

Inherited from Callback: abort, get_dettime, get_end_dettime, get_end_time, get_start_dettime, get_start_time, get_time

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

get_branch(self, which_branch)

 

Returns one of the candidate branches at the current node.

which_branch must be an integer such that 0 <= which_branch < self.get_num_branches().

The return value of get_branch is a tuple t with two entries. The first entry is the node estimate for the specified branch. The second entry is a list of (var, dir, bnd) triples, where var is the index of a variable whose bound will change, bnd is the new bound, and dir is one of "L", "U", and "B", indicating that the branch will change the lower bound, the upper bound, or both, respectively.

get_branch_type(self)

 

Returns the type of the branch.

One of the following: self.branch_type.any self.branch_type.SOS1 self.branch_type.SOS2 self.branch_type.variable

make_branch(self, objective_estimate, variables=None, constraints=None, node_data=None)

 

Makes a new branch with the specified data.

objective_estimate is a float representing the estimated objective value resulting from the specified branch.

variables is a sequence of (var, dir, bnd) triples specifying the variables on which to branch. var must be an index of a variable, dir must be one of "L" and "U", indicating that the bound is a lower or upper bound, respectively, and bnd is an integer specifying the new bound for the variable.

constraints is a sequence of (vec, sense, rhs) triples specifying the constraints with which to branch. vec must be either an instance of SparsePair or a sequence with two entries, the first of which specifies the indices and the second of which specifies the values of the constraint. rhs must be a float determining the righthand side of the constraint. sense must be one of "L", "G", or "E", specifying whether the constraint is a less-than, greater-than, or equality constraint.

node_data may be any object to be associated with the created node. It can be queried by the get_node_data methods of the IncumbentCallback class and the NodeCallback class.

make_cplex_branch(self, which_branch, node_data=None)

 

Replicates a CPLEX branch.

The function replicates the n-th branch that CPLEX would create at the current node. The purpose of this function is to branch exactly like CPLEX, but at the same time attach a user object to the newly created node.

which_branch must be an integer such that 0 <= which_branch < self.get_num_branches().

node_data may be any object to be associated with the created node. It can be queried by the get_node_data methods of various callback classes.

The function returns the sequence number of the newly created node.

prune(self)

 

Removes the current node from the search tree.

Note
Prune must not be called in combination with make_branch. Prune is not compatible with the populate_solution_pool method of the Cplex class because that method retains fathomed nodes for subsequent use.