diff --git "a/docs/2021-08-22-\344\275\234\344\270\232\350\275\246\351\227\264\350\260\203\345\272\246\351\227\256\351\242\230\346\261\202\350\247\243\346\241\206\346\236\266\357\274\232OR-Tools\347\272\246\346\235\237\346\261\202\350\247\243\345\231\250.md" "b/docs/2021-08-22-\344\275\234\344\270\232\350\275\246\351\227\264\350\260\203\345\272\246\351\227\256\351\242\230\346\261\202\350\247\243\346\241\206\346\236\266\357\274\232OR-Tools\347\272\246\346\235\237\346\261\202\350\247\243\345\231\250.md"
index 5d7e574..f300e10 100644
--- "a/docs/2021-08-22-\344\275\234\344\270\232\350\275\246\351\227\264\350\260\203\345\272\246\351\227\256\351\242\230\346\261\202\350\247\243\346\241\206\346\236\266\357\274\232OR-Tools\347\272\246\346\235\237\346\261\202\350\247\243\345\231\250.md"
+++ "b/docs/2021-08-22-\344\275\234\344\270\232\350\275\246\351\227\264\350\260\203\345\272\246\351\227\256\351\242\230\346\261\202\350\247\243\346\241\206\346\236\266\357\274\232OR-Tools\347\272\246\346\235\237\346\261\202\350\247\243\345\231\250.md"
@@ -143,51 +143,76 @@ def NewIntervalVar(self, start, size, end, name): pass
最后,求解几个标准问题。求解时间上限设定为300秒。
```python
+# benchmark.py
+import threading
+from queue import Queue
from jsp_fwk import (JSProblem, JSSolution)
from jsp_fwk.solver import GoogleORCPSolver
-# benchmarks
-names = ['ft06', 'la01', 'ft10', 'swv01', 'la38', \
- 'ta31', 'swv12', 'ta42', 'ta54', 'ta70']
-
-res = []
-res.append('name,num_job,num_machine,optimum,solution,time')
-for name in names:
- p = JSProblem(benchmark=name)
- s = GoogleORCPSolver(max_time=300) # set upper limit of solving time
- s.solve(problem=p, interval=None)
-
- # wait for termination
+# solving process in a child thread
+def solve(names_queue:Queue, res:list, thread_name:str):
while True:
- if not s.is_running: break
+ name = names_queue.get()
+ p = JSProblem(benchmark=name)
+ s = GoogleORCPSolver(max_time=300) # set upper limit of solving time
+ s.solve(problem=p, interval=None)
+ s.wait() # wait for termination
+
+ # collect results
+ items = [name, len(p.jobs), len(p.machines), p.optimum, \
+ p.solution.makespan, s.user_time]
+ res.append(','.join(map(str, items)))
+
+ names_queue.task_done()
+ print(f'{thread_name} processed {name}.')
+
+
+if __name__=='__main__':
+
+ # benchmarks
+ names = ['ft06', 'la01', 'ft10', 'swv01', 'la38', \
+ 'ta31', 'swv12', 'ta42', 'ta54', 'ta70']
+ names_queue = Queue(maxsize=20)
+ for name in names: names_queue.put(name)
+
+ # result
+ res = []
+ res.append('name,num_job,num_machine,optimum,solution,time')
+
+ # start child threads
+ for i in range(4):
+ thread = threading.Thread(target=solve, \
+ args=(names_queue, res, f'Child-{i}'))
+ thread.setDaemon(True) # terminate when main thread terminated
+ thread.start()
- # collect results
- items = [name, len(p.jobs), len(p.machines), p.optimum, \
- p.solution.makespan, s.user_time]
- res.append(','.join(map(str, items)))
+ # wait for termination
+ names_queue.join()
-print(res)
+ # final results
+ print()
+ for line in res: print(line)
```
结果如下表所示:
- 前5行变量总数300以内,`OR-Tools` 基本得到了最优解。例4虽然没能在规定时间内求得最优解,但是相对误差0.5%已经很小。
-- 后5行变量总数在$[450, 1000]$量级,都没能在300秒内求得最优解,并且精度随着问题复杂度(例如变量总数、工序数等)增加而急剧降低。
+- 后5行变量总数在$[450, 1000]$量级,除了例9有些反常外,其余都没能在300秒内求得最优解,并且精度随着问题复杂度(例如变量总数、工序数等)增加而降低。
| |name|num of
job|num of
machine|optimum|solution|err / %|time|
|---|---|---|---|---|---|---|---|
-|1|ft06|6|6|55|55|0.0|0.8
-|2|la01|10|5|666|666|0.0|6.8
-|3|ft10|10|10|930|930|0.0|20.6
-|4|swv01|20|10|1407|1414|0.5|300.1
-|5|la38|15|15|1196|1196|0|193.5
-|6|ta31|30|15|1764|1891|7.2|300.1
+|1|ft06|6|6|55|55|0.0|0.0
+|2|la01|10|5|666|666|0.0|0.2
+|3|ft10|10|10|930|930|0.0|3.8
+|4|swv01|20|10|1407|1414|0.5|300.0
+|5|la38|15|15|1196|1196|0|147.7
+|6|ta31|30|15|1764|1814|2.8|300.0
|7|swv12|50|10|(2972, 3003)|3339|11.8|300.1
-|8|ta42|30|20|(1867, 1956)|2546|33.2|300.1
-|9|ta54|50|15|2839|3192|12.4|299.7
-|10|ta70|50|20|2995|3948|31.8|299.0
+|8|ta42|30|20|(1867, 1956)|2096|9.6|300.1
+|9|ta54|50|15|2839|2863|0.8|300.1
+|10|ta70|50|20|2995|3307|10.4|300.1
-问题规模较小时,高效求出最优解;但随着问题规模的增大,求解效率急剧下降。这是整数规划等精确求解方法应用于实际大规模调度问题的限制所在。
+问题规模较小时,能高效求出最优解;但随着问题规模的增大,求解效率急剧下降。例如,上例中即便将计算时间上限增加到600秒,后5个例子的结果也没有显著改善。这是整数规划等精确求解方法应用于实际大规模调度问题的限制所在。
\ No newline at end of file