获取CPLEX求解MIP时添加的cutting planes (C program)

源代码:https://www.ibm.com/support/pages/sample-c-program-retrieve-cuts-added-cplex-during-mip-optimization

通过macOS的终端(terminal)编译:

CPX_PATH = /Applications/CPLEX_Studio_Community2211/cplex/
CC = g++
ARCH = x86-64_osx
cpx: 
	$(CC) -g -L $(CPX_PATH)/lib/$(ARCH)/static_pic/ -L lib/ -I $(CPX_PATH)/include/ilcplex/ -o get_cuts get_cuts.cpp -lm -lpthread -lcplex -ldl

对应修改CPX_PATH和ARCH: 

gcc -g -L /Applications/CPLEX_Studio_Community2211/cplex/lib/x86-64_osx/static_pic/ -L lib/ -I /Applications/CPLEX_Studio_Community2211/cplex/include/ilcplex/ -o wrtnode wrtnode.c -lm -lpthread -lcplex -ldl

编译完成后运行:

./wrtnode example.lp

example.lp来自:https://www.math.cuhk.edu.hk/course_builder/1415/math3220/L5.pdf

运行代码后显示:

Node files written starting with node -1, ending with node 2100000000
Version identifier: 22.1.1.0 | 2022-11-28 | 9160aff4d
CPXPARAM_MIP_Interval                            1
Legacy callback                                  S
Warning: Control callbacks may disable some MIP features.
Found incumbent of value 0.000000 after 0.00 sec. (0.00 ticks)
Tried aggregator 1 time.
Reduced MIP has 3 rows, 5 columns, and 9 nonzeros.
Reduced MIP has 0 binaries, 5 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.01 ticks)
Tried aggregator 1 time.
Reduced MIP has 3 rows, 5 columns, and 9 nonzeros.
Reduced MIP has 0 binaries, 5 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.00 ticks)
MIP emphasis: balance optimality and feasibility.
MIP search method: traditional branch-and-cut.
Parallel mode: none, using 1 thread.
Root relaxation solution time = 0.00 sec. (0.01 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap         Variable B NodeID Parent  Depth

*     0+    0                            0.0000       -9.0000              --- 
*     0+    0                           -6.0000       -9.0000            50.00%
      0     0       -7.5000     2       -6.0000       -7.5000        1   25.00%
*     0     0      integral     0       -7.0000       Cuts: 4        2    0.00%
      0     0        cutoff             -7.0000       -7.0000        2    0.00%                        0             0
Elapsed time = 0.01 sec. (0.04 ticks, tree = 0.01 MB, solutions = 3)

Mixed integer rounding cuts applied:  1
Zero-half cuts applied:  1
Gomory fractional cuts applied:  1

Root node processing (before b&c):
  Real time             =    0.01 sec. (0.04 ticks)
Sequential b&c:
  Real time             =    0.00 sec. (0.00 ticks)
                          ------------
Total (root+branch&cut) =    0.01 sec. (0.04 ticks)
Solution status 101.
Objective value -7
Column 0:  Value =                 3
Column 1:  Value =                 1
Column 2:  Value =                 1
Column 3:  Value =                 2
Column 4:  Value =                 1

运行后,最终的MILP formulation(包含所有generate的cut)储存在“nodelp7_0.lp”中:

\ENCODING=ISO-8859-1
\Problem name: 

Minimize
 obj1: - 2 x1 - x2
Subject To
 c1: x1 + x2 + x3  = 5
 c2: - x1 + x2 + x4  = 0
 c3: 6 x1 + 2 x2 + x5  = 21
 z1: x1 + 0.5 x2 <= 3.5
 m2: - x1 - 0.5 x5 <= -3.5
 r3: - x3 - 0.5 x5 <= -1.5
Bounds
 2 <= x1 <= 3
 1 <= x2 <= 3
 0 <= x3 <= 2
 0 <= x4 <= 2
 1 <= x5 <= 7
End

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值