1

CBC의 C++ API를 배우고 있으며 MPS 파일을로드하고 해결 한 컴파일 된 C++ 프로그램의 성능과 일치하지 않습니다. 그것은 단지 CBC 커맨드 라인 유틸리티를 열고, 동일한 파일을 가져오고 solve을 사용하는 것과 비교할 때 CbcModel 클래스를 사용합니다. cmd line 유틸리티는 MIP를 1 초로 해결하고 C++ 프로그램은 < 10 분 후에 종료되지 않습니다.코인 또는 CBC 해결사 성능 : 컴파일 된 C++ 프로그램

나는 C++ API를 사용할 때 명시 적으로 모든 매개 변수를 구성해야하고 cmd 라인 유틸리티에서 사용되는 기본 매개 변수가 평균 MIP 모델에 대해 꽤 잘 어울린다고 생각했습니다.

미리보기, 추론 및 커밋에 대한 기본 매개 변수 목록이 cmd line 유틸리티에서 사용되며 성능을 맞추기 위해 C++ 프로그램에서 활성화해야합니다. 어쩌면 누군가가 이러한 매개 변수를 가지고 놀았으며 경험적으로 훌륭한 매개 변수 집합을 발견했을 것입니다.

는 C++ 프로그램입니다 : 문제의

int main() 
{ 
    OsiClpSolverInterface solver1; 
    solver1.setLogLevel(0); 

    // Read in example model in MPS file format 
    // and assert that it is a clean model 
    int numMpsReadErrors = solver1.readMps("generic_mip.mps",""); 
    assert(numMpsReadErrors==0); 

    // Pass the solver with the problem to be solved to CbcModel 
    CbcModel model(solver1); 
    model.setLogLevel(0); 

    // Add clique cut generator 
    CglClique clique_generator; 
    model.addCutGenerator(&clique_generator,-1, "Clique"); 

    // Add rounding heuristic 
    CglMixedIntegerRounding mixedGen; 
    model.addCutGenerator(&mixedGen, -1, "Rounding"); 

    model.setNumberThreads(4); 

    model.messageHandler()->setPrefix(false); 

    model.branchAndBound(); 


    const double * solution = model.bestSolution(); 

    printf("Optimal value is %.2f", *solution); 

    return 0; 
} 

MIP 모델은 HERE에서 다운로드 할 수 있습니다. 최적 목표 값 : -771.2957. 아마 this part of the official code helps

Continuous objective value is -798.689 - 0.03 seconds 
Cgl0002I 21 variables fixed 
Cgl0003I 0 fixed, 175 tightened bounds, 1972 strengthened rows, 0 substitutions 
Cgl0004I processed model has 3731 rows, 3835 columns (3835 integer (3660 of which binary)) and 37873 elements 
Cbc0038I Initial state - 365 integers unsatisfied sum - 129.125 
Cbc0038I Pass 1: (0.18 seconds) suminf. 58.66667 (121) obj. -572.133 iterations 510 
Cbc0038I Pass 2: (0.18 seconds) suminf. 58.66667 (121) obj. -572.133 iterations 23 
Cbc0038I Pass 3: (0.18 seconds) suminf. 58.66667 (121) obj. -572.133 iterations 1 
Cbc0038I Pass 4: (0.20 seconds) suminf. 69.00000 (138) obj. -299.496 iterations 589 
Cbc0038I Pass 5: (0.20 seconds) suminf. 54.00000 (109) obj. -287.063 iterations 194 
Cbc0038I Pass 6: (0.21 seconds) suminf. 54.00000 (109) obj. -287.063 iterations 12 
Cbc0038I Pass 7: (0.21 seconds) suminf. 49.00000 (100) obj. -273.321 iterations 33 
Cbc0038I Pass 8: (0.22 seconds) suminf. 48.00000 (97) obj. -269.421 iterations 14 
Cbc0038I Pass 9: (0.22 seconds) suminf. 48.00000 (98) obj. -268.624 iterations 8 
Cbc0038I Pass 10: (0.23 seconds) suminf. 48.00000 (97) obj. -264.813 iterations 4 
Cbc0038I Pass 11: (0.23 seconds) suminf. 47.00000 (94) obj. -261.75 iterations 8 
Cbc0038I Pass 12: (0.24 seconds) suminf. 47.00000 (94) obj. -261.75 iterations 3 
Cbc0038I Pass 13: (0.24 seconds) suminf. 47.00000 (94) obj. -261.75 iterations 3 
Cbc0038I Pass 14: (0.25 seconds) suminf. 57.75000 (118) obj. -103.115 iterations 508 
Cbc0038I Pass 15: (0.26 seconds) suminf. 49.00000 (98) obj. -97.4793 iterations 163 
Cbc0038I Pass 16: (0.26 seconds) suminf. 49.00000 (98) obj. -97.4793 iterations 3 
Cbc0038I Pass 17: (0.27 seconds) suminf. 48.75000 (98) obj. -101.421 iterations 24 
Cbc0038I Pass 18: (0.27 seconds) suminf. 47.00000 (94) obj. -103.346 iterations 25 
Cbc0038I Pass 19: (0.28 seconds) suminf. 47.00000 (94) obj. -103.346 iterations 2 
Cbc0038I Pass 20: (0.28 seconds) suminf. 47.00000 (94) obj. -103.346 iterations 21 
Cbc0038I Pass 21: (0.29 seconds) suminf. 51.50000 (107) obj. 60.0315 iterations 469 
Cbc0038I Pass 22: (0.30 seconds) suminf. 40.00000 (80) obj. 59.913 iterations 168 
Cbc0038I Pass 23: (0.30 seconds) suminf. 40.00000 (80) obj. 59.913 iterations 2 
Cbc0038I Pass 24: (0.31 seconds) suminf. 39.50000 (79) obj. 59.913 iterations 27 
Cbc0038I Pass 25: (0.31 seconds) suminf. 39.00000 (78) obj. 59.913 iterations 23 
Cbc0038I Pass 26: (0.32 seconds) suminf. 39.00000 (78) obj. 59.913 iterations 13 
Cbc0038I Pass 27: (0.33 seconds) suminf. 50.00000 (101) obj. 124.699 iterations 504 
Cbc0038I Pass 28: (0.34 seconds) suminf. 41.00000 (82) obj. 118.624 iterations 174 
Cbc0038I Pass 29: (0.34 seconds) suminf. 41.00000 (82) obj. 118.624 iterations 5 
Cbc0038I Pass 30: (0.34 seconds) suminf. 41.00000 (82) obj. 118.624 iterations 19 
Cbc0038I No solution found this major pass 
Cbc0038I Before mini branch and bound, 2356 integers at bound fixed and 0 continuous 
Cbc0038I Mini branch and bound did not improve solution (0.41 seconds) 
Cbc0038I After 0.41 seconds - Feasibility pump exiting - took 0.25 seconds 
Cbc0031I 583 added rows had average density of 8.2024014 
Cbc0013I At root node, 583 cuts changed objective from -798.68913 to -771.29565 in 10 passes 
Cbc0014I Cut generator 0 (Probing) - 541 row cuts average 2.0 elements, 0 column cuts (0 active) in 0.044 seconds - new frequency is 1 
Cbc0014I Cut generator 1 (Gomory) - 751 row cuts average 116.6 elements, 0 column cuts (0 active) in 0.108 seconds - new frequency is 1 
Cbc0014I Cut generator 2 (Knapsack) - 451 row cuts average 2.0 elements, 0 column cuts (0 active) in 0.040 seconds - new frequency is 1 
Cbc0014I Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.004 seconds - new frequency is -100 
Cbc0014I Cut generator 4 (MixedIntegerRounding2) - 155 row cuts average 16.9 elements, 0 column cuts (0 active) in 0.028 seconds - new frequency is 1 
Cbc0014I Cut generator 5 (FlowCover) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.008 seconds - new frequency is -100 
Cbc0014I Cut generator 6 (TwoMirCuts) - 1171 row cuts average 20.0 elements, 0 column cuts (0 active) in 0.068 seconds - new frequency is 1 
Cbc0010I After 0 nodes, 1 on tree, 1e+50 best solution, best possible -771.29565 (1.18 seconds) 
Cbc0004I Integer solution of -771.29565 found after 2671 iterations and 1 nodes (1.24 seconds) 
Cbc0001I Search completed - best objective -771.2956521739131, took 2671 iterations and 1 nodes (1.24 seconds) 
Cbc0032I Strong branching done 22 times (542 iterations), fathomed 0 nodes and fixed 0 variables 
Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost 
Cuts at root node changed objective from -798.689 to -771.296 
Probing was tried 12 times and created 552 cuts of which 0 were active after adding rounds of cuts (0.044 seconds) 
Gomory was tried 12 times and created 756 cuts of which 0 were active after adding rounds of cuts (0.116 seconds) 
Knapsack was tried 12 times and created 456 cuts of which 0 were active after adding rounds of cuts (0.044 seconds) 
Clique was tried 10 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.004 seconds) 
MixedIntegerRounding2 was tried 12 times and created 155 cuts of which 0 were active after adding rounds of cuts (0.036 seconds) 
FlowCover was tried 10 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.008 seconds) 
TwoMirCuts was tried 12 times and created 1197 cuts of which 0 were active after adding rounds of cuts (0.084 seconds) 
ImplicationCuts was tried 2 times and created 11 cuts of which 0 were active after adding rounds of cuts (0.000 seconds) 

Result - Optimal solution found 

Objective value:    -771.29565217 
Enumerated nodes:    1 
Total iterations:    2671 
Time (CPU seconds):    1.27 
Time (Wallclock seconds):  1.30 

답변

1

: 전진 기능의 모든 종류를 나타내는

CBC 명령 행 유틸리티 로그 (전처리, 불안 휴리스틱 강한 분기)를 활성화한다. 그것은 linedoc라고 불린다 Set up likely cut generators and defaults

CBC의 코드는 읽기가 어렵고 시간을 투자하지 않고 어떤 종류의 기본 행동이 있는지 분석하기가 어렵다.

위의 링크 된 코드는 일부 cmd 호출 내에서 활성화 된 기본값과 비슷합니다.

+0

읽기가 어렵습니다. 행 1710-1858을 믿으시겠습니까? – ELEC

0

어떤 컴파일러를 사용합니까? 디버그를 사용할 수 있습니까? 최적화가 비활성화 되었습니까? 예. Visual Studio의 경우 성능에 큰 차이가 있으며 컴파일 된 코드가 훨씬 느려질 수 있습니다.

+0

GCC 6.3.0, Clion IDE를 사용한 완벽한 최적화. 나쁜 성능을 재현 할 수 있는지 확인하려면 mip 파일을 제 질문에 추가했습니다. – ELEC

+0

C++에서 사용중인 CBC 라이브러리 빌드에서 멀티 스레딩이 활성화되어 있습니까? – Reinhard

+0

멀티 스레딩이 10 초 대 1 초의 런타임을 설명 할 수 있다고 생각하십니까? – sascha