2017-11-16 21 views
0

pyomo (Pyomo 5.3 (Linux 3.10.0-514.26.2.el7.x86_64)의 Pyomo 5.3 최적화 문제를 해결하기 위해 노력하고 있습니다. CBC 솔버 (버전 : 2.9.8)이며 솔버의 시간 제한을 60 초로 지정합니다. 해결사는 실현 가능한 솔루션을 얻고 있지만 (-1415.8392), 아래에서 볼 수 있듯이 최적이 아닙니다 (-1415.84).cbc solver로 pyomo 최적화를 실행하고 timelimit을 사용하는 중에 오류가보고되었습니다.

시간 제한이 끝난 후 모델은 오류 코드와 함께 종료됩니다. 나는 지정된 시간 내에 CBC를 사용하여 가능한 해결책의 모든 변수의 값을 인쇄하거나 얻고 싶습니다. 또는 Model이 최적 솔루션의 99 % 가치를 얻으면 실현 가능한 솔루션을 종료하고 인쇄 할 수있는 다른 방법이 있습니다.

오류 코드는 아래에 게시됩니다. 아래 그림과 같이

 
Cbc0004I Integer solution of -1415.8392 found after 357760 iterations and 29278 nodes (47.87 seconds) 
Cbc0010I After 30000 nodes, 6350 on tree, -1415.8392 best solution, best possible -1415.84 (48.87 seconds) 
Cbc0010I After 31000 nodes, 6619 on tree, -1415.8392 best solution, best possible -1415.84 (50.73 seconds) 
Cbc0010I After 32000 nodes, 6984 on tree, -1415.8392 best solution, best possible -1415.84 (52.49 seconds) 
Cbc0010I After 33000 nodes, 7384 on tree, -1415.8392 best solution, best possible -1415.84 (54.31 seconds) 
Cbc0010I After 34000 nodes, 7419 on tree, -1415.8392 best solution, best possible -1415.84 (55.73 seconds) 
Cbc0010I After 35000 nodes, 7824 on tree, -1415.8392 best solution, best possible -1415.84 (57.37 seconds) 
Traceback (most recent call last): 
    File "model_final.py", line 392, in 
    solver.solve(model, timelimit = 60*1, tee=True) 
    File "/home/aditya/0r/lib/python2.7/site-packages/pyomo/opt/base/solvers.py", line 655, in solve 
    default_variable_value=self._default_variable_value) 
    File "/home/aditya/0r/lib/python2.7/site-packages/pyomo/core/base/PyomoModel.py", line 242, in load_from 
    % str(results.solver.status)) 
ValueError: Cannot load a SolverResults object with bad status: error 

내가 수동으로도 정상적으로 종료 보인다 pyomo /usr/bin/cbc -sec 60 -printingOptions all -import /tmp/tmpJK1ieR.pyomo.lp -import -stat=1 -solve -solu /tmp/tmpJK1ieR.pyomo.soln과 같은 명령 줄 매개 변수를 사용 pyomo에 의해 생성 된 모델을 실행

솔루션을 기록합니다.

 
Cbc0010I After 35000 nodes, 7824 on tree, -1415.8392 best solution, best possible -1415.84 (57.06 seconds) 
Cbc0038I Full problem 205 rows 289 columns, reduced to 30 rows 52 columns 
Cbc0010I After 36000 nodes, 8250 on tree, -1415.8392 best solution, best possible -1415.84 (58.73 seconds) 
Cbc0020I Exiting on maximum time 
Cbc0005I Partial search - best objective -1415.8392 (best possible -1415.84), took 464553 iterations and 36788 nodes (60.11 seconds) 
Cbc0032I Strong branching done 15558 times (38451 iterations), fathomed 350 nodes and fixed 2076 variables 
Cbc0035I Maximum depth 203, 5019 variables fixed on reduced cost 
Cbc0038I Probing was tried 31933 times and created 138506 cuts of which 0 were active after adding rounds of cuts (4.431 seconds) 
Cbc0038I Gomory was tried 30898 times and created 99534 cuts of which 0 were active after adding rounds of cuts (4.855 seconds) 
Cbc0038I Knapsack was tried 30898 times and created 12926 cuts of which 0 were active after adding rounds of cuts (8.271 seconds) 
Cbc0038I Clique was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds) 
Cbc0038I MixedIntegerRounding2 was tried 30898 times and created 13413 cuts of which 0 were active after adding rounds of cuts (3.652 seconds) 
Cbc0038I FlowCover was tried 100 times and created 4 cuts of which 0 were active after adding rounds of cuts (0.019 seconds) 
Cbc0038I TwoMirCuts was tried 30898 times and created 15292 cuts of which 0 were active after adding rounds of cuts (2.415 seconds) 
Cbc0038I Stored from first was tried 30898 times and created 15734 cuts of which 0 were active after adding rounds of cuts (0.000 seconds) 
Cbc0012I Integer solution of -1411.9992 found by Reduced search after 467825 iterations and 36838 nodes (60.12 seconds) 
Cbc0020I Exiting on maximum time 
Cbc0005I Partial search - best objective -1411.9992 (best possible -1415.4522), took 467825 iterations and 36838 nodes (60.12 seconds) 
Cbc0032I Strong branching done 476 times (1776 iterations), fathomed 1 nodes and fixed 18 variables 
Cbc0035I Maximum depth 21, 39 variables fixed on reduced cost 
Cuts at root node changed objective from -1484.12 to -1415.45 
Probing was tried 133 times and created 894 cuts of which 32 were active after adding rounds of cuts (0.060 seconds) 
Gomory was tried 133 times and created 1642 cuts of which 0 were active after adding rounds of cuts (0.047 seconds) 
Knapsack was tried 133 times and created 224 cuts of which 0 were active after adding rounds of cuts (0.083 seconds) 
Clique was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.001 seconds) 
MixedIntegerRounding2 was tried 133 times and created 163 cuts of which 0 were active after adding rounds of cuts (0.034 seconds) 
FlowCover was tried 100 times and created 5 cuts of which 0 were active after adding rounds of cuts (0.026 seconds) 
TwoMirCuts was tried 133 times and created 472 cuts of which 0 were active after adding rounds of cuts (0.021 seconds) 
ImplicationCuts was tried 25 times and created 41 cuts of which 0 were active after adding rounds of cuts (0.003 seconds) 

Result - Stopped on time limit 

Objective value:    -1411.99922848 
Lower bound:     -1415.452 
Gap:       0.00 
Enumerated nodes:    36838 
Total iterations:    467825 
Time (CPU seconds):    60.13 
Time (Wallclock seconds):  60.98 

Total time (CPU seconds):  60.13 (Wallclock seconds):  61.01 

CBC는 솔루션 파일의 상위 몇 줄은 다음과 같습니다

 
Stopped on time - objective value -1411.99922848 
     0 c_e_x1454_       0      0 
     1 c_e_x1455_       0      0 
     2 c_e_x1456_       0      0 
     3 c_e_x1457_       0      0 
     4 c_e_x1458_       0      0 
     5 c_e_x1459_       0      0 
     6 c_e_x1460_       0      0 
     7 c_e_x1461_       0      0 
     8 c_e_x1462_       0      0 

내가 오류를 생성하지 않고이 값을 얻을 수있는 방법 누군가가 말해 줄래?

미리 감사드립니다.

답변

0

다른 답을 받아 들일 수 있도록 구속력 공차를 설정할 수 있습니다. 실현 가능한 해결책이 발견되면 솔버 상태가 오류로 다시 돌아 오는 것에 놀랐습니다. 전체 결과 개체를 인쇄 할 수 있습니까?

+0

감사합니다. Qi. 바운드 갭을 사용하여 해결책을 인쇄하기 위해 pyomo를 얻을 수있었습니다. 실제로 간격이 0.001 인 솔루션은 실행 시간이 불과 10 초 만에 인쇄됩니다. 그러나 적절한 폐쇄를 위해 모델이 합리적인 시간 내에 충분한 솔루션에 도달 할 수없는 경우를 처리하고 싶습니다. 그 주변에 다른 제안이 있습니까? –

+0

CBCplugin이이 종료 조건을 올바르게 처리하지 못하거나 CBC가 제한 시간으로 인해 중지 할 때 인쇄 내용을 변경했을 수 있습니다. https://github.com/Pyomo/pyomo/blob/master/pyomo/solvers/plugins/solvers/CBCplugin.py에는 트리거되지 않을 수도있는'SolutionStatus.stoppedByLimit'에 대한 테스트가 있습니다. –

+0

문제가 생겼습니다. 언제든지 다음 정보를 입력하여 원하는 세부 정보를 입력하실 수 있습니다. https://github.com/Pyomo/pyomo/issues/256 –

0

이 문제를 해결하기 위해 풀 요청을 https://github.com/Pyomo/pyomo/pull/265으로 만들었습니다.

파일에서

pyomo/해법/플러그인/해법/CBCplugin.py 제공 옵션에 비해

@@ -264,7 +264,8 @@ def _check_and_escape_options(options): 
      cmd.append('-AMPL') 

      if self._timelimit is not None and self._timelimit > 0.0: 
-    cmd.extend(['-sec', str(self._timelimit)]) 
+    cmd.extend(['-sec', str(self._timelimit - 1)]) 
+    cmd.extend(['-timeMode', "elapsed"]) 
      if "debug" in self.options: 
       cmd.extend(["-log","5"]) 
      for key, val in _check_and_escape_options(self.options): 
@@ -276,7 +277,8 @@ def _check_and_escape_options(options): 
         #"-stat"]) 
     else: 
      if self._timelimit is not None and self._timelimit > 0.0: 
-    cmd.extend(['-sec', str(self._timelimit)]) 
+    cmd.extend(['-sec', str(self._timelimit - 1)]) 
+    cmd.extend(['-timeMode', "elapsed"]) 
      if "debug" in self.options: 
       cmd.extend(["-log","5"]) 
      # these must go after options that take a value 
timelimit을 설정한다

초 1 이하 : 즉시 패치를 원하는 사람들을 위해

pyutilib 프로세스 프로세스가 종료 코드를 검사하기 전에 CBC 프로세스가 올바르게 종료 될 시간을 확보하도록 보장합니다. 내 테스트를 실행하면 프로세스 관리자가 T + 0.02 초에 종료 상태를 확인하고 CBC 프로세스가 T + 0.1 초 후에 종료되었습니다.

또한 프로세스 관리자가 동일하게 확인하므로 CBC 코드를 기본값 인 CPU 초에서 wallclock 초로 변경했습니다.