Cplex: MIP Control Callback Methods

*本文主要记录和分享学习到的知识,算不上原创

*参考文献见链接

本文主要归纳了Cplex的Control callback常用的方法。

目录

    NodeCallback

    SolveCallback

    UserCutCallback

    LazyConstraintCallback

    HeuristicCallback

    BranchCallback

    IncumbentCallback

Control CallBack Interface

If you determine that your application needs to seize control, intervene in the search, and redirect the optimizer, then the following control callbacks are available to do so.

The node callback allows you to query and optionally overwrite the next node CPLEX will process during a branch & cut search.
  IloCplex.NodeCallback in the Java API
The solve callback allows you to specify and configure the optimizer option to be used for solving the LP at each individual node.   IloCplex.SolveCallback in the Java API
The user cut callback allows you to add problem-specific user-defined cuts at each node.   IloCplex.UserCutCallback in the Java API
The lazy constraint callback allows you to add lazy constraints; that is, constraints that are not evaluated unless they are violated.   IloCplex.LazyConstraintCallback in the Java API
The heuristic callback allows you to implement a heuristic that tries to generate a new incumbent from the solution of the LP relaxation at each node.   IloCplex.HeuristicCallback in the Java API
The branch callback allows you to query and optionally overwrite the way CPLEX will branch at each node.   IloCplex.BranchCallback in the Java API
The incumbent callback allows you to check and optionally reject incumbents found by CPLEX during the search.   IloCplex.IncumbentCallback in the Java API

In Java, there is no way of removing individual callbacks from yourIloCplexorCplexobject. Instead, you remove all callbacks by calling the methodIloCplex.clearCallbacksorCplexClearCallbacks.

Node Callback

getBranchVar(long node)                  Returns the variable that was branched upon to create the node specified by number node.

getDepth(long node)              Returns the depth of the node in the search tree.

getNodeId(long node)                        Returns the node identifier of the node specified by the node number node.

getNodeNumber(IloCplex.NodeId nodeid)              Returns the node number of the node specified by the node identifier.

getObjValue(long node)                   Returns the objective value of the node specified by the node number.

selectNode(long node)           Selects the next node to be processed by its number.

Solve Callback

setStart()                     Specifies a starting point for the next invocation of the method solve during the current solve callback.

solve()                   Solves the current node using the default algorithm (IloCplex.Algorithm.Auto).

solve(int alg)            Solves the current node using the algorithm alg.

useSolution()             Instructs IloCplex to use a solution.

                                                 ** This method instructs IloCplex to use the solution generated with this callback instead of solving the node itself.

Heuristic Callback

setBounds()                              Sets the bounds for a set of variables.

setSolution()                              Sets a solution to be used as the incumbent.

User Cut Callback

add()                                       Adds a linear global cut to the current subproblem.

                                               **This cut must be globally valid. It will not be removed by backtracking or any other means during the search. The cut must also not cut off any integer feasible solution.

addLocal()                              Adds a linear local cut to the current subproblem.

isAfterCutLoop()                     Returns True if called after the cut loop, False otherwise.

abortCutLoop()                       Terminate the cut loop and proceed with branching.

Lazy Constraint Callback

add(IloRange cut)                        Adds a linear consraint cut as a global lazy constraint to the problem being solved.

                                                                  ** As a lazy constraint, this cut must be globally valid. It will not be removed by backtracking or any other means during the search.

addLocal(IloRange cut)           Adds cut as a local lazy constraint to the problem being solved.

isUnboundedNode()                     This method indicates whether or not the callback was invoked when the LP relaxation is found to be unbounded and the user needs to test whether a lazy constraint cuts off the unbounded direction.

Branch Callback

getBranches()                 Returns one of the candidate branches at the current node if not overridden by the invoking callback.

getBranchType()                         Returns the type of the branch at the current node unless overridden by the invoking callback.

getNbranches()                Returns the number of branches CPLEX is going to create at the current node unless overridden by the invoking callback.

getNodeId()               Returns the node identifier of the current node.

isIntegerFeasible()         Returns true if the current node solution is considered to be integer feasible and thus potentially eligible as a new incumbent, but not suitable for branching.

makeBranch()                           Creates a child node for the current node

prune()                    Removes the current node from the search tree.

Incumbent Callback

getObjValue()             Returns the objective value of the potential incumbent.

reject()                   Rejects the proposed incumbent solution.

Some other methods

setBounds                               Sets the bounds for a set of variables.

setSolution                              Sets a solution to be used as the incumbent.

Abort                                       Aborts current optimization.

GetBestObjValue                    This method returns a bound on the optimal solution value of the active problem at the moment the callback is called.

GetCplexStatus                       Returns the Cplex.CplexStatus for the current node.

GetCplexTime                         This method returns a time stamp, useful in measuring elapsed time in seconds. elapsed time=end time-start time

GetCutoff                                 Returns the cutoff for the objective value when nodes are being solved during branch-and-cut search.

GetEndTime                            This method returns a time stamp specifying when the time limit will occur. remaining time=getEndTime-getCplexTime

GetIncumbentObjValue           Returns the objective value of the current best integer solution at the moment the callback is called. (incumbent: best integer feasible solution)

GetModel                                Returns the model being solved when the invoking callback is called, that is the active model.

GetNiterations                         Returns the total number of iterations for solving node relaxations during the current optimization.

GetNnodes                             Returns the number of nodes processed so far in the active branch-and-cut search.

GetNremainingNodes             Returns the number of nodes remaining to be processed, or, equivalently, the number of active nodes in the tree.

GetObjValue                           Returns the objective function value of the solution of the continuous relaxation of the current node.

GetStartTime                          This method returns a time stamp specifying when the solving process was started.

GetStatus                                Returns the solution status for the current node.

HasIncumbent                        Returns true if an incumbent solution has been found when the callback is called.

Main                                        The method to be implemented by user callback classes.

Solve                                     Solves the current node relaxation using the default algorithm.

 

转载于:https://www.cnblogs.com/liuyingsme/p/9929392.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值