├── Installation ├── mip.py ├── picture │ ├── gurobi_logo.png │ ├── gurobi安裝 │ │ ├── request_license.PNG │ │ ├── 下載gurobi.png │ │ ├── 執行驗證License的程式.png │ │ ├── 測試gurobi.png │ │ ├── 申請license.png │ │ ├── 申請license畫面.png │ │ ├── 申請成功.png │ │ ├── 選擇適合版本.png │ │ └── 開啟Gurobi.png │ ├── gurobi註冊 │ │ ├── 啟動帳號.png │ │ ├── 安裝並註冊.png │ │ ├── 設定完成畫面.png │ │ ├── 設定密碼.png │ │ ├── 註冊成功畫面.jpg │ │ ├── 註冊畫面.png │ │ └── 開始註冊.png │ ├── python-logo.png │ ├── 安裝anaconda │ │ ├── mip_example執行畫面.PNG │ │ ├── spyder編譯器.png │ │ ├── spyder編譯器優點.png │ │ ├── 下載gurobi package.png │ │ ├── 環境設定.PNG │ │ └── 選擇版本.png │ └── 設定python路徑 │ │ ├── 新增路徑.png │ │ ├── 測試gurobi+python.png │ │ ├── 系統設定.png │ │ ├── 複製python路徑.png │ │ └── 設定路徑.png └── 安裝教學.md ├── LICENSE ├── README.md ├── gurobi_introduction.md └── python-gurobi model ├── Controlling Air Pollution_type1.md ├── Controlling Air Pollution_type2.md ├── Dual example.md ├── Dual+example.html ├── Netflow problem.md ├── Netflow_problem.py ├── Optimal Employee Work Schedule.md ├── Optimal Employee Work Schedule.py ├── Prototype example_type1.md ├── Prototype example_type2.md ├── Python+Gurobi基本架構.md ├── Python+Gurobi建模.md ├── Python+Gurobi特殊資料結構.ipynb ├── gurobi.log └── picture ├── Controlling Air Pollution example ├── .md ├── Controlling Air Pollution 12.png ├── Controlling Air Pollution 2.png └── Controlling Air Pollution1.png ├── Dual example ├── .md └── convertPintoD.png ├── Netflow problem ├── .md ├── netflow problem model.PNG ├── netflow problem picture.PNG └── netflow problem picture_final.PNG ├── Optimal Employee Work Schedule ├── .md ├── 參數設定.PNG ├── 員工班次排程圖.PNG ├── 員工資訊.PNG ├── 每小時最少所需人數.PNG ├── 每時段所需員工人數比較圖.PNG ├── 決策變數.PNG ├── 目標函數.PNG └── 限制式.PNG ├── Prototype example picture ├── Prototype example 數學式.png ├── Prototype example_type2_S.png ├── Prototype example_type2_數學式轉換.png ├── Prototype example_type2符號設定.png └── Prototype example題目.png ├── Python+gurobi 架構.png ├── Python+gurobi建模 ├── example.png ├── 建模範例.png └── 最佳化流程.png ├── Python+gurobi建模流程.png ├── m.addconstr.png ├── m.addvar.png ├── m.setobjective.png ├── mip_example執行畫面.PNG ├── python數學式子.png ├── quicksum_example.png └── 求解題目.png /Installation/mip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2016, Gurobi Optimization, Inc. 4 | 5 | # This example formulates and solves the following simple MIP model: 6 | # maximize 7 | # x + y + 2 z 8 | # subject to 9 | # x + 2 y + 3 z <= 4 10 | # x + y >= 1 11 | # x, y, z binary 12 | 13 | from gurobipy import * 14 | 15 | try: 16 | 17 | # Create a new model 18 | m = Model("mip1") 19 | 20 | # Create variables 21 | x = m.addVar(vtype=GRB.BINARY, name="x") 22 | y = m.addVar(vtype=GRB.BINARY, name="y") 23 | z = m.addVar(vtype=GRB.BINARY, name="z") 24 | 25 | # Integrate new variables 26 | m.update() 27 | 28 | # Set objective 29 | m.setObjective(x + y + 2 * z, GRB.MAXIMIZE) 30 | 31 | # Add constraint: x + 2 y + 3 z <= 4 32 | m.addConstr(x + 2 * y + 3 * z <= 4, "c0") 33 | 34 | # Add constraint: x + y >= 1 35 | m.addConstr(x + y >= 1, "c1") 36 | 37 | m.optimize() 38 | m.write('mip1.lp') 39 | 40 | for v in m.getVars(): 41 | print('%s %g' % (v.varName, v.x)) 42 | 43 | print('Obj: %g' % m.objVal) 44 | 45 | except GurobiError: 46 | print('Encountered a Gurobi error') 47 | -------------------------------------------------------------------------------- /Installation/picture/gurobi_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi_logo.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/request_license.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/request_license.PNG -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/下載gurobi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/下載gurobi.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/執行驗證License的程式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/執行驗證License的程式.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/測試gurobi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/測試gurobi.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/申請license.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/申請license.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/申請license畫面.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/申請license畫面.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/申請成功.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/申請成功.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/選擇適合版本.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/選擇適合版本.png -------------------------------------------------------------------------------- /Installation/picture/gurobi安裝/開啟Gurobi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi安裝/開啟Gurobi.png -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/啟動帳號.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/啟動帳號.png -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/安裝並註冊.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/安裝並註冊.png -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/設定完成畫面.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/設定完成畫面.png -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/設定密碼.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/設定密碼.png -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/註冊成功畫面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/註冊成功畫面.jpg -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/註冊畫面.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/註冊畫面.png -------------------------------------------------------------------------------- /Installation/picture/gurobi註冊/開始註冊.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/gurobi註冊/開始註冊.png -------------------------------------------------------------------------------- /Installation/picture/python-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/python-logo.png -------------------------------------------------------------------------------- /Installation/picture/安裝anaconda/mip_example執行畫面.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/安裝anaconda/mip_example執行畫面.PNG -------------------------------------------------------------------------------- /Installation/picture/安裝anaconda/spyder編譯器.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/安裝anaconda/spyder編譯器.png -------------------------------------------------------------------------------- /Installation/picture/安裝anaconda/spyder編譯器優點.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/安裝anaconda/spyder編譯器優點.png -------------------------------------------------------------------------------- /Installation/picture/安裝anaconda/下載gurobi package.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/安裝anaconda/下載gurobi package.png -------------------------------------------------------------------------------- /Installation/picture/安裝anaconda/環境設定.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/安裝anaconda/環境設定.PNG -------------------------------------------------------------------------------- /Installation/picture/安裝anaconda/選擇版本.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/安裝anaconda/選擇版本.png -------------------------------------------------------------------------------- /Installation/picture/設定python路徑/新增路徑.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/設定python路徑/新增路徑.png -------------------------------------------------------------------------------- /Installation/picture/設定python路徑/測試gurobi+python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/設定python路徑/測試gurobi+python.png -------------------------------------------------------------------------------- /Installation/picture/設定python路徑/系統設定.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/設定python路徑/系統設定.png -------------------------------------------------------------------------------- /Installation/picture/設定python路徑/複製python路徑.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/設定python路徑/複製python路徑.png -------------------------------------------------------------------------------- /Installation/picture/設定python路徑/設定路徑.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/Installation/picture/設定python路徑/設定路徑.png -------------------------------------------------------------------------------- /Installation/安裝教學.md: -------------------------------------------------------------------------------- 1 | 2 | # 安裝教學 3 | *POLab* 4 |
5 | *2017/09/27* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | #### ※注意 : 在此主要針對 Gurobi 6.5.2以上版本及Anaconda for python2.7 or python3.6版本 10 | ## (一)Gurobi註冊 11 | 12 | ### - 登入官網並註冊帳號 13 | - [Gurobi官網](https://www.gurobi.com/index)

14 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E5%AE%89%E8%A3%9D%E4%B8%A6%E8%A8%BB%E5%86%8A.png) 15 | 16 | ### - 註冊畫面

17 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E8%A8%BB%E5%86%8A%E7%95%AB%E9%9D%A2.png) 18 | 19 | ### - 開始註冊

20 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E9%96%8B%E5%A7%8B%E8%A8%BB%E5%86%8A.png) 21 | 22 | ### - 註冊成功畫面

23 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E8%A8%BB%E5%86%8A%E6%88%90%E5%8A%9F%E7%95%AB%E9%9D%A2.jpg) 24 | 25 | ### - 到註冊時填寫的信箱,啟動帳號 26 | 27 | #### *※需使用學術網路*
28 | 29 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E5%95%9F%E5%8B%95%E5%B8%B3%E8%99%9F.png) 30 | 31 | ### - 設定密碼

32 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E8%A8%AD%E5%AE%9A%E5%AF%86%E7%A2%BC.png) 33 | 34 | ### - 設定完成畫面

35 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E8%A8%BB%E5%86%8A/%E8%A8%AD%E5%AE%9A%E5%AE%8C%E6%88%90%E7%95%AB%E9%9D%A2.png) 36 | 37 | ## (二)Gurobi安裝 38 | 39 | ### - 註冊後下載Gurobi

40 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E5%AE%89%E8%A3%9D/%E4%B8%8B%E8%BC%89gurobi.png) 41 | 42 | ### - 選擇自己電腦適合的版本

43 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E5%AE%89%E8%A3%9D/%E9%81%B8%E6%93%87%E9%81%A9%E5%90%88%E7%89%88%E6%9C%AC.png) 44 | 45 | 46 | ## (二)申請License 47 | 48 | ### - 申請license

49 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E5%AE%89%E8%A3%9D/%E7%94%B3%E8%AB%8Blicense.png) 50 | 51 | ### - 申請畫面 52 | 53 | - 將兩個選項打勾,接著點選Request License

54 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E5%AE%89%E8%A3%9D/request_license.PNG) 55 | 56 | ### - 申請成功

57 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E5%AE%89%E8%A3%9D/%E7%94%B3%E8%AB%8B%E6%88%90%E5%8A%9F.png) 58 | 59 | ### - 驗證License 60 | 61 | #### *※需使用學術網路* 62 | 可依照下面步驟進行驗證或按**Windows+R**直接進入到執行程式畫面並貼上license

63 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/gurobi%E5%AE%89%E8%A3%9D/%E5%9F%B7%E8%A1%8C%E9%A9%97%E8%AD%89License%E7%9A%84%E7%A8%8B%E5%BC%8F.png) 64 | 65 | ## (三)安裝Anaconda 66 | 67 | ### - 選擇適合自己電腦的版本並安裝 68 | - 可至[Gurobi載點](http://www.gurobi.com/downloads/get-anaconda) or [Anaconda官網](https://www.anaconda.com/download/)下載

69 | 70 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/%E5%AE%89%E8%A3%9Danaconda/%E9%81%B8%E6%93%87%E7%89%88%E6%9C%AC.png) 71 | 72 | 73 | - 安裝過程中,請在此步驟時打勾,這樣可以節省之後去環境變數設定python/pip指令的時間

74 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/%E5%AE%89%E8%A3%9Danaconda/%E7%92%B0%E5%A2%83%E8%A8%AD%E5%AE%9A.PNG) 75 | 76 | ### - 點選Anaconda Prompt,並輸入以下兩道指令下載gurobi package 77 | conda config --add channels http://conda.anaconda.org/gurobi
78 | conda install gurobi

79 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/%E5%AE%89%E8%A3%9Danaconda/%E4%B8%8B%E8%BC%89gurobi%20package.png) 80 | 81 | ## (四)執行 82 | ### - Spyder編譯器

83 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/%E5%AE%89%E8%A3%9Danaconda/spyder%E7%B7%A8%E8%AD%AF%E5%99%A8.png) 84 | 85 | ### - 執行程式測試 86 | [執行程式碼](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/mip.py)測試系統是否正常運作

87 | ![](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/picture/%E5%AE%89%E8%A3%9Danaconda/mip_example%E5%9F%B7%E8%A1%8C%E7%95%AB%E9%9D%A2.PNG) 88 | 89 | 90 | ### 完成以上步驟後,Python+Gurobi環境就準備好了,接著我們來看看[Python+Gurobi基本架構](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Python%2BGurobi%E5%9F%BA%E6%9C%AC%E6%9E%B6%E6%A7%8B.md)吧! 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Cheng-Man Wu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python+Gurobi 2 | [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
3 | ### **內容概述** 4 | 5 | 此網頁為成功大學資訊系[作業研究課程](http://course-query.acad.ncku.edu.tw/crm/course_map/course.php?dept=F7&cono=F732800)Python+Gurobi的應用教學 6 | 7 | 授課教師為[李家岩](http://polab.imis.ncku.edu.tw/Bio.html)老師 8 | 9 | ### **助教** 10 | 11 | |擔任年份|助教|信箱 :mailbox_closed:| 12 | |----|----|----| 13 | |2017|吳承璊|P96064079@mail.ncku.edu.tw| 14 | 15 | ---------------------------------------- 16 | ### :triangular_flag_on_post: Gurobi介紹 17 | |更新時間|文章| 18 | |---|---| 19 | |2018-04-03|[Gurobi簡介](https://github.com/wurmen/Gurobi-Python/blob/master/gurobi_introduction.md)| 20 | ### :triangular_flag_on_post: 環境建置 21 | |更新時間|文章| 22 | |-----|-----| 23 | |2017-09-27|[安裝教學](https://github.com/wurmen/Gurobi-Python/blob/master/Installation/%E5%AE%89%E8%A3%9D%E6%95%99%E5%AD%B8.md)| 24 | |2017-11-03|[Linux安裝](https://github.com/PO-LAB/Python-Gurobi/blob/master/Installation/installation-for-linux.md)| 25 | 26 | ### :triangular_flag_on_post: Python+Gurobi建模 27 | |更新時間|文章| 28 | |-----|-----| 29 | |2017-09-27|[Python+Gurobi基本架構](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Python+Gurobi%E5%9F%BA%E6%9C%AC%E6%9E%B6%E6%A7%8B.md)| 30 | |2017-10-08|[Python+Gurobi建模](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Python+Gurobi%E5%BB%BA%E6%A8%A1.md)| 31 | |2017-10-30|[Python+Gurobi特殊資料結構](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Python%2BGurobi%E7%89%B9%E6%AE%8A%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B.ipynb)| 32 | 33 | ### :triangular_flag_on_post: 範例 34 | |更新時間|文章| 35 | |-----|-----| 36 | |2017-10-08|[Prototype example type1](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Prototype%20example_type1.md)| 37 | |2017-10-08|[Prototype example type2](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Prototype%20example_type2.md)| 38 | |2017-10-08|[Controlling Air Pollution type1](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Controlling%20Air%20Pollution_type1.md)| 39 | |2017-10-08|[Controlling Air Pollution type2](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Controlling%20Air%20Pollution_type2.md)| 40 | |2017-10-30|[Dual example](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Dual%20example.md)| 41 | |2017-10-30|[Optimal Employee Work Schedule](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Optimal%20Employee%20Work%20Schedule.md)| 42 | |2017-11-04|[Netflow problem](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Netflow%20problem.md)| 43 | 44 | -------------------------------------------------------------------------------- /gurobi_introduction.md: -------------------------------------------------------------------------------- 1 | # Gurobi 簡介 2 | 3 | [Gurobi](http://www.gurobi.com/index),又稱Gurobi Optimizer,是一個用來求解數學規劃的優化引擎,為目前市面上相當知名的數學規劃優化器,主要由[Zonghao **Gu**、Edward  **Ro**thberg、Robert **Bi**xby](http://www.gurobi.com/company/management-team)開發,Gurobi即由三位開發者的名子命名而來。 4 | ###### ※本文內容的相關連結會以:link:或藍色字體表示,可自行點擊查看 5 | ------- 6 | ### :black_nib: 支持的數學規劃類型 [:link:](http://www.gurobi.com/products/features-benefits) 7 | 目前Gurobi已經更新至7.5.2版本,並且能求解以下類型的數學規劃問題: 8 |
9 | 10 | - Linear Programming (LP) 11 | - Mixed-Integer Linear Programming (MILP) 12 | - Quadratic Programming (QP) 13 | - Mixed-Integer Quadratic Programming (MIQP) 14 | - Quadratically Constrained Programming (QCP) 15 | - Mixed-Integer Quadratically Constrained Programming (MIQCP) 16 | 17 | :zap: 因此Gurobi是能夠求解非線性問題,但僅限於二次規劃問題。 18 | 19 | ------------ 20 | ### :black_nib: 支持的程式語言(programming language)及建模語言(modeling language) [:link:](http://www.gurobi.com/products/features-benefits) 21 | Gurobi支援許多不同程式語言及建模語言的開發,如以下所示: 22 | 23 | :arrow_down_small: 程式語言 24 | - 物件導向(Object-oriented interfaces):C++, Java, .NET, and Python 25 | - 矩陣導向(Matrix-oriented interfaces):C, MATLAB, and R 26 | 27 | :arrow_down_small: 建模語言 28 | - AMPL, GAMS, AIMMS, and MPL 29 | 30 | :zap: 本repository主要著重於python-gurobi的應用 31 | 32 | 33 | ---------- 34 | ### :black_nib: License 35 | 要使用Gurobi,必須先取得[Gurobi License](http://www.gurobi.com/downloads/licenses/license-center)才能進行使用,Gurobi License主要分為兩個類型,[商業使用(Commercial Licenses)](http://www.gurobi.com/products/licensing-pricing/licensing-overview)及[學術使用(Academic Licenses)](http://www.gurobi.com/academia/academia-center),商業使用是必須付費的,不過Gurobi有提供測試License,讓公司進行Gurobi試用,而學術使用是完全免費的,並且在Gurobi使用上沒有任何限制,不管是在建模的大小或功能的使用等,但學術License僅有一年的有效期,一旦到期了,就必須重新申請新的License才可再次使用,不過以整體來說Gurobi算是非常好的數學規劃求解器,對於學術上的使用是非常大方的。 36 | -------------------------------------------------------------------------------- /python-gurobi model/Controlling Air Pollution_type1.md: -------------------------------------------------------------------------------- 1 | # Controlling Air Pollution example 2 | 3 | *POLab* 4 |
5 | *2017/10/08* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | ### ● 本範例為講義第三章p25.26題目
10 |
11 | 12 | # Import gurobipy 13 | 14 | 15 | ```python 16 | from gurobipy import* 17 | ``` 18 | 19 | # Model 20 | 21 | 22 | ```python 23 | m=Model("controlling air pollution") 24 | ``` 25 | 26 | # Add decision variable 27 | 28 | 29 | ```python 30 | x1=m.addVar(lb=0,ub=1,name="x1") 31 | x2=m.addVar(lb=0,ub=1,name="x2") 32 | x3=m.addVar(lb=0,ub=1,name="x3") 33 | x4=m.addVar(lb=0,ub=1,name="x4") 34 | x5=m.addVar(lb=0,ub=1,name="x5") 35 | x6=m.addVar(lb=0,ub=1,name="x6") 36 | ``` 37 | 38 | # Update 39 | 40 | 41 | ```python 42 | m.update() 43 | ``` 44 | 45 | # Add objective and constraints 46 | 47 |
48 | 49 | ```python 50 | m.setObjective(8*x1+10*x2+7*x3+6*x4+11*x5+9*x6,GRB.MINIMIZE) 51 | 52 | m.addConstr(12*x1+9*x2+25*x3+20*x4+17*x5+13*x6>=60,"c0") 53 | m.addConstr(35*x1+42*x2+18*x3+31*x4+56*x5+49*x6>=150,"c1") 54 | m.addConstr(37*x1+53*x2+28*x3+24*x4+29*x5+20*x6>=125,"c2") 55 | ``` 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | # Result 65 | 66 | 67 | ```python 68 | m.optimize() 69 | print("Obj:",m.objVal) 70 | for v in m.getVars(): 71 | print("%s:%.3f"%(v.varName,v.x)) 72 | ``` 73 | 74 | Optimize a model with 3 rows, 6 columns and 18 nonzeros 75 | Coefficient statistics: 76 | Matrix range [9e+00, 6e+01] 77 | Objective range [6e+00, 1e+01] 78 | Bounds range [1e+00, 1e+00] 79 | RHS range [6e+01, 2e+02] 80 | Presolve time: 0.00s 81 | Presolved: 3 rows, 6 columns, 18 nonzeros 82 | 83 | Iteration Objective Primal Inf. Dual Inf. Time 84 | 0 0.0000000e+00 6.171875e+00 0.000000e+00 0s 85 | 4 3.2154631e+01 0.000000e+00 0.000000e+00 0s 86 | 87 | Solved in 4 iterations and 0.01 seconds 88 | Optimal objective 3.215463133e+01 89 | ('Obj:', 32.154631330359486) 90 | x1:1.000 91 | x2:0.623 92 | x3:0.343 93 | x4:1.000 94 | x5:0.048 95 | x6:1.000 96 | 97 | 98 | 99 | ```python 100 | 101 | ``` 102 | -------------------------------------------------------------------------------- /python-gurobi model/Controlling Air Pollution_type2.md: -------------------------------------------------------------------------------- 1 | 2 | # Controlling Air Pollution example 3 | 4 | *POLab* 5 |
6 | *2017/10/08* 7 |
8 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 9 | 10 | ### ● 本範例為講義第三章p25.26題目 11 | 12 | 13 | # Import gurobipy 14 | 15 | 16 | ```python 17 | from gurobipy import* 18 | ``` 19 | 20 | # Model 21 | 22 | 23 | ```python 24 | m=Model("controlling air pollution_type2") 25 | ``` 26 | 27 | # Add parameters 28 | **c**:每個方法的成本
29 | **p**:每個方法可以減少的量
30 | **r**:每個汙染物至少要被減少的量
31 | 32 | 33 | ```python 34 | c=[8,10,7,6,11,9] 35 | p=[[12,9,25,20,17,13], 36 | [35,42,18,31,56,49], 37 | [37,53,28,24,29,20]] 38 | r=[60,150,125] 39 | ``` 40 | 41 | # Add decision variables 42 | 43 | 44 | ```python 45 | x={} 46 | for j in range(6): 47 | x[j]=m.addVar(lb=0,ub=1,name="x_%d"%j) 48 | ``` 49 | 50 | # Update 51 | 52 | 53 | ```python 54 | m.update() 55 | ``` 56 | 57 | # Add objective and constraints 58 | 59 | 60 | 61 | 62 | ```python 63 | m.setObjective(quicksum(c[j]*x[j] for j in range(6)),GRB.MINIMIZE) 64 | for i in range(3): 65 | m.addConstr(quicksum(p[i][j]*x[j] for j in range(6))>=r[i],"c0") 66 | ``` 67 | 68 | # Result 69 | 70 | 71 | ```python 72 | m.optimize() 73 | print("Obj:",m.objVal) 74 | for v in m.getVars(): 75 | print("%s:%.3f"%(v.varName,v.x)) 76 | ``` 77 | 78 | Optimize a model with 3 rows, 6 columns and 18 nonzeros 79 | Coefficient statistics: 80 | Matrix range [9e+00, 6e+01] 81 | Objective range [6e+00, 1e+01] 82 | Bounds range [1e+00, 1e+00] 83 | RHS range [6e+01, 2e+02] 84 | Presolve time: 0.00s 85 | Presolved: 3 rows, 6 columns, 18 nonzeros 86 | 87 | Iteration Objective Primal Inf. Dual Inf. Time 88 | 0 0.0000000e+00 6.171875e+00 0.000000e+00 0s 89 | 4 3.2154631e+01 0.000000e+00 0.000000e+00 0s 90 | 91 | Solved in 4 iterations and 0.01 seconds 92 | Optimal objective 3.215463133e+01 93 | ('Obj:', 32.154631330359486) 94 | x1:1.000 95 | x2:0.623 96 | x3:0.343 97 | x4:1.000 98 | x5:0.048 99 | x6:1.000 100 | 101 | 102 | 103 | ```python 104 | 105 | ``` 106 | -------------------------------------------------------------------------------- /python-gurobi model/Dual example.md: -------------------------------------------------------------------------------- 1 | 2 | # Dual example 3 | *POLab* 4 |
5 | *2017/10/30* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | 10 | ### ● 題目
11 | 12 |
13 | 14 | ### ● 主問題及對偶問題 15 | 16 |
17 | 18 | # Import gurobipy 19 | ```python 20 | from gurobipy import* 21 | ``` 22 | 23 | # Model 24 | 25 | 26 | ```python 27 | m=Model('Dual example') 28 | ``` 29 | 30 | # Add parameters 31 | 32 | 33 | ```python 34 | I=2 35 | J=3 36 | v=[3,5] 37 | p=[[1,0,3],[0,2,2]] 38 | a=[4,12,18] 39 | ``` 40 | 41 | # Add decision variables 42 | 43 | 44 | ```python 45 | x={} 46 | for i in range(I): 47 | x[i]=m.addVar(lb=0,vtype=GRB.CONTINUOUS,name='x_%d'%i) 48 | ``` 49 | 50 | # Update 51 | 52 | 53 | ```python 54 | m.update() 55 | ``` 56 | 57 | # Add objective and constraints 58 | 59 | 60 | ```python 61 | m.setObjective(quicksum(v[i]*x[i] for i in range(I)),GRB.MAXIMIZE) 62 | 63 | for j in range(J): 64 | m.addConstr(quicksum(p[i][j]*x[i] for i in range(I))<=a[j],name='c%d'%j) 65 | ``` 66 | 67 | # Result 68 | 69 | 70 | ```python 71 | m.optimize() 72 | print('obj:%d'%m.objVal) 73 | for v in m.getVars(): 74 | print('%s:%d'%(v.varName,v.x)) 75 | ``` 76 | ``` 77 | Optimize a model with 3 rows, 2 columns and 4 nonzeros 78 | Coefficient statistics: 79 | Matrix range [1e+00, 3e+00] 80 | Objective range [3e+00, 5e+00] 81 | Bounds range [0e+00, 0e+00] 82 | RHS range [4e+00, 2e+01] 83 | Presolve removed 2 rows and 0 columns 84 | Presolve time: 0.01s 85 | Presolved: 1 rows, 2 columns, 2 nonzeros 86 | 87 | Iteration Objective Primal Inf. Dual Inf. Time 88 | 0 4.2000000e+01 1.500000e+00 0.000000e+00 0s 89 | 1 3.6000000e+01 0.000000e+00 0.000000e+00 0s 90 | 91 | Solved in 1 iterations and 0.01 seconds 92 | Optimal objective 3.600000000e+01 93 | obj:36 94 | x_0:2 95 | x_1:6 96 | ``` 97 | 98 | # Get dual value 99 | 100 | 101 | ```python 102 | #透過限制式中的屬性pi取得對偶值 103 | for c in m.getConstrs(): 104 | print 'The dual value of %s : %g'%(c.constrName,c.pi) 105 | ``` 106 | ``` 107 | The dual value of c0 : 0 108 | The dual value of c1 : 1.5 109 | The dual value of c2 : 1 110 | ``` 111 | -------------------------------------------------------------------------------- /python-gurobi model/Netflow problem.md: -------------------------------------------------------------------------------- 1 | # Netflow problem 2 | *POLab* 3 |
4 | *2017/11/04* 5 |
6 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi)
7 | 8 | 9 | 10 | ##### ※參考資料: https://wenku.baidu.com/view/b34a6a8f680203d8ce2f24b1?pcf=2#8 、[Gurobi-Python Interface Example](https://www.gurobi.com/documentation/6.5/examples/netflow_py.html) 11 | 12 | ## (一)問題描述 13 | 此為Gurobi內建的範例,在此加以整理介紹。 14 | ### ● 題目: 15 | 有兩項產品(**鉛筆及鋼筆**),分別由兩個城市生產(**底特律及丹佛**),並送至其他三個城市(**波士頓、紐約及西雅圖**),且必須滿足這三個 16 | 城市所需商品數量,每項商品運輸過程中不得超過每條路徑所能負荷的運能。 17 | ### ● 已知: 18 | 如下圖所示
19 | 每條路徑都有相對應的運輸成本及運能,分別表示為: 20 | - (capacity , pencils transportation cost , pens transportation cost)
21 | 22 | 23 | 每個城市所擁有或所需要的商品數量: 24 | - (pencils inflow , pens inflows) 25 |
26 | 27 |
28 | 29 | ### ● 目標: 30 | - 最小化總運輸成本 31 | ### ● 限制: 32 | - 經過每條路徑上的商品總數不得超過其所能負荷的運能 33 | - 必須滿足波士頓、紐約及西雅圖所需的商品數量 34 | 35 | 36 | ## (二)數學模型 37 | ### ● 符號設定 38 | - arcs:所有可能的運輸路線
39 | 40 | - nodes:所有運輸路線上的城市
41 | 42 | - commodities:所有等待運輸的產品
43 | 44 | ### ● 參數設定 45 | - cost[h,i,j]:商品h從城市i到城市j的運輸成本
46 | 47 | - capacity[i,j]:從城市i到城市j 的運能
48 | 49 | - inflow[h,j]:商品h在城市j的生產量或需求量
50 | 51 | ### ● 決策變數 52 | - flow[h,i,j]:商品h從城市i到城市j的運輸總量 53 | 54 | ### ● 數學式 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | ## (三)Python+Gurobi 64 | 65 | #### ※完整程式碼可點擊[這裡](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Netflow%20problem.py) 66 | 67 | ## Import gurobipy 68 | 69 | 70 | ```python 71 | from gurobipy import * 72 | ``` 73 | 74 | ## Add parameters 75 | 76 | - 定義兩種商品,以及包含五個節點六條路徑的網絡結構,形成commodities與nodes兩個列表 77 | - 利用multidict函數初始化arcs與capacity,將arcs轉入tuplelist 78 | 79 | 80 | 81 | 82 | 83 | ```python 84 | commodities = ['Pencils', 'Pens'] 85 | nodes = ['Detroit', 'Denver', 'Boston', 'New York', 'Seattle'] 86 | 87 | arcs, capacity = multidict({ 88 | ('Detroit', 'Boston'): 100, 89 | ('Detroit', 'New York'): 80, 90 | ('Detroit', 'Seattle'): 120, 91 | ('Denver', 'Boston'): 120, 92 | ('Denver', 'New York'): 120, 93 | ('Denver', 'Seattle'): 120 }) 94 | arcs = tuplelist(arcs) 95 | ``` 96 | 97 | - 建立每個商品在每條路徑的運輸成本數據,以及每個節點的生產或需求量 98 | - 透過cost[h,i,j]來索引運輸成本 99 | - 透過inflow[h,j]來索引每個節點的生產或需求量 100 | 101 | 102 | ```python 103 | cost = { 104 | ('Pencils', 'Detroit', 'Boston'): 10, 105 | ('Pencils', 'Detroit', 'New York'): 20, 106 | ('Pencils', 'Detroit', 'Seattle'): 60, 107 | ('Pencils', 'Denver', 'Boston'): 40, 108 | ('Pencils', 'Denver', 'New York'): 40, 109 | ('Pencils', 'Denver', 'Seattle'): 30, 110 | ('Pens', 'Detroit', 'Boston'): 20, 111 | ('Pens', 'Detroit', 'New York'): 20, 112 | ('Pens', 'Detroit', 'Seattle'): 80, 113 | ('Pens', 'Denver', 'Boston'): 60, 114 | ('Pens', 'Denver', 'New York'): 70, 115 | ('Pens', 'Denver', 'Seattle'): 30 } 116 | 117 | inflow = { 118 | ('Pencils', 'Detroit'): 50, 119 | ('Pencils', 'Denver'): 60, 120 | ('Pencils', 'Boston'): -50, 121 | ('Pencils', 'New York'): -50, 122 | ('Pencils', 'Seattle'): -10, 123 | ('Pens', 'Detroit'): 60, 124 | ('Pens', 'Denver'): 40, 125 | ('Pens', 'Boston'): -40, 126 | ('Pens', 'New York'): -30, 127 | ('Pens', 'Seattle'): -30 } 128 | ``` 129 | 130 | ## Model 131 | 132 | 133 | ```python 134 | # Create optimization model 135 | m = Model('netflow') 136 | ``` 137 | 138 | ## Add decision variables 139 | 140 | - 創建字典flow來儲存決策變數 141 | - 透過obj參數來設定決策變數的目標係數 142 | 143 | 144 | ```python 145 | # Create variables 146 | flow = {} 147 | for h in commodities: 148 | for i,j in arcs: 149 | flow[h,i,j] = m.addVar(ub=capacity[i,j], obj=cost[h,i,j], 150 | name='flow_%s_%s_%s' % (h, i, j)) 151 | m.update() 152 | ``` 153 | 154 | ## Update 155 | 156 | 157 | ```python 158 | m.update() 159 | ``` 160 | 161 | ## Add constraints 162 | 163 | - 加入運輸容量限制式 164 | - 加入流量守恆限制式 165 | 166 | 167 | ```python 168 | # Arc capacity constraints 169 | for i,j in arcs: 170 | m.addConstr(quicksum(flow[h,i,j] for h in commodities) <= capacity[i,j], 171 | 'cap_%s_%s' % (i, j)) 172 | 173 | # Flow conservation constraints 174 | for h in commodities: 175 | for j in nodes: 176 | m.addConstr( 177 | quicksum(flow[h,i,j] for i,j in arcs.select('*',j)) + 178 | inflow[h,j] == 179 | quicksum(flow[h,j,k] for j,k in arcs.select(j,'*')), 180 | 'node_%s_%s' % (h, j)) 181 | ``` 182 | 183 | ## Result 184 | 185 | - 透過getAttr()函數取得模型m中決策變數flow的屬性值x,也就是決策變數flow的最佳解 186 | - getAttr()函數詳細內容可點擊[這裡](https://www.gurobi.com/documentation/7.0/refman/py_model_getattr.html) 187 | 188 | 189 | ```python 190 | # Compute optimal solution 191 | m.optimize() 192 | 193 | # Print solution 194 | if m.status == GRB.Status.OPTIMAL: 195 | solution = m.getAttr('x', flow) 196 | for h in commodities: 197 | print('\nOptimal flows for %s:' % h) 198 | for i,j in arcs: 199 | if solution[h,i,j] > 0: 200 | print('%s -> %s: %g' % (i, j, solution[h,i,j])) 201 | 202 | ``` 203 | 204 | Optimize a model with 16 rows, 12 columns and 36 nonzeros 205 | Coefficient statistics: 206 | Matrix range [1e+00, 1e+00] 207 | Objective range [1e+01, 8e+01] 208 | Bounds range [8e+01, 1e+02] 209 | RHS range [1e+01, 1e+02] 210 | Presolve removed 16 rows and 12 columns 211 | Presolve time: 0.00s 212 | Presolve: All rows and columns removed 213 | Iteration Objective Primal Inf. Dual Inf. Time 214 | 0 5.5000000e+03 0.000000e+00 0.000000e+00 0s 215 | 216 | Solved in 0 iterations and 0.01 seconds 217 | Optimal objective 5.500000000e+03 218 | 219 | Optimal flows for Pencils: 220 | Denver -> Seattle: 10 221 | Denver -> New York: 50 222 | Detroit -> Boston: 50 223 | 224 | Optimal flows for Pens: 225 | Denver -> Seattle: 30 226 | Detroit -> New York: 30 227 | Detroit -> Boston: 30 228 | Denver -> Boston: 10 229 | 230 |
231 | 232 |
233 |   234 | 235 | 236 | -------------------------------------------------------------------------------- /python-gurobi model/Netflow_problem.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2016, Gurobi Optimization, Inc. 4 | 5 | # Solve a multi-commodity flow problem. Two products ('Pencils' and 'Pens') 6 | # are produced in 2 cities ('Detroit' and 'Denver') and must be sent to 7 | # warehouses in 3 cities ('Boston', 'New York', and 'Seattle') to 8 | # satisfy demand ('inflow[h,i]'). 9 | # 10 | # Flows on the transportation network must respect arc capacity constraints 11 | # ('capacity[i,j]'). The objective is to minimize the sum of the arc 12 | # transportation costs ('cost[i,j]'). 13 | 14 | from gurobipy import * 15 | 16 | # Model data 17 | 18 | commodities = ['Pencils', 'Pens'] 19 | nodes = ['Detroit', 'Denver', 'Boston', 'New York', 'Seattle'] 20 | 21 | arcs, capacity = multidict({ 22 | ('Detroit', 'Boston'): 100, 23 | ('Detroit', 'New York'): 80, 24 | ('Detroit', 'Seattle'): 120, 25 | ('Denver', 'Boston'): 120, 26 | ('Denver', 'New York'): 120, 27 | ('Denver', 'Seattle'): 120 }) 28 | arcs = tuplelist(arcs) 29 | 30 | cost = { 31 | ('Pencils', 'Detroit', 'Boston'): 10, 32 | ('Pencils', 'Detroit', 'New York'): 20, 33 | ('Pencils', 'Detroit', 'Seattle'): 60, 34 | ('Pencils', 'Denver', 'Boston'): 40, 35 | ('Pencils', 'Denver', 'New York'): 40, 36 | ('Pencils', 'Denver', 'Seattle'): 30, 37 | ('Pens', 'Detroit', 'Boston'): 20, 38 | ('Pens', 'Detroit', 'New York'): 20, 39 | ('Pens', 'Detroit', 'Seattle'): 80, 40 | ('Pens', 'Denver', 'Boston'): 60, 41 | ('Pens', 'Denver', 'New York'): 70, 42 | ('Pens', 'Denver', 'Seattle'): 30 } 43 | 44 | inflow = { 45 | ('Pencils', 'Detroit'): 50, 46 | ('Pencils', 'Denver'): 60, 47 | ('Pencils', 'Boston'): -50, 48 | ('Pencils', 'New York'): -50, 49 | ('Pencils', 'Seattle'): -10, 50 | ('Pens', 'Detroit'): 60, 51 | ('Pens', 'Denver'): 40, 52 | ('Pens', 'Boston'): -40, 53 | ('Pens', 'New York'): -30, 54 | ('Pens', 'Seattle'): -30 } 55 | 56 | # Create optimization model 57 | m = Model('netflow') 58 | 59 | # Create variables 60 | flow = {} 61 | for h in commodities: 62 | for i,j in arcs: 63 | flow[h,i,j] = m.addVar(ub=capacity[i,j], obj=cost[h,i,j], 64 | name='flow_%s_%s_%s' % (h, i, j)) 65 | m.update() 66 | 67 | # Arc capacity constraints 68 | for i,j in arcs: 69 | m.addConstr(quicksum(flow[h,i,j] for h in commodities) <= capacity[i,j], 70 | 'cap_%s_%s' % (i, j)) 71 | 72 | # Flow conservation constraints 73 | for h in commodities: 74 | for j in nodes: 75 | m.addConstr( 76 | quicksum(flow[h,i,j] for i,j in arcs.select('*',j)) + 77 | inflow[h,j] == 78 | quicksum(flow[h,j,k] for j,k in arcs.select(j,'*')), 79 | 'node_%s_%s' % (h, j)) 80 | 81 | # Compute optimal solution 82 | m.optimize() 83 | 84 | # Print solution 85 | if m.status == GRB.Status.OPTIMAL: 86 | solution = m.getAttr('x', flow) 87 | for h in commodities: 88 | print('\nOptimal flows for %s:' % h) 89 | for i,j in arcs: 90 | if solution[h,i,j] > 0: 91 | print('%s -> %s: %g' % (i, j, solution[h,i,j])) 92 | -------------------------------------------------------------------------------- /python-gurobi model/Optimal Employee Work Schedule.md: -------------------------------------------------------------------------------- 1 | 2 | # Generating an Optimal Employee Work Schedule Using Integer Linear Programming 3 | *POLab* 4 |
5 | *2017/10/30* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi)
8 | ##### ※題目來源: https://blogs.mathworks.com/loren/2016/01/06/generating-an-optimal-employee-work-schedule-using-integer-linear-programming/ 9 | 10 | ## (一) 問題描述 11 | 12 | ### ● 題目: 13 | - 利用整數線性規劃最佳化員工工作班表。 14 | 15 | ### ● 已知: 16 | 如圖一、二所示: 17 | - 所有員工可得的工作時間及每小時薪資。 18 | - 每個員工每班最少所需工作時數及最多可工作時數。 19 | - 每小時最低需求人數。 20 | 21 |
22 | GitHub 23 | 24 | 圖一、員工資訊 25 |
26 | 27 |
28 | GitHub 29 | 30 | 圖二、每小時最少所需人數 31 |
32 | 33 | ### ● 目標: 34 | - 最小化每日需支付給員工的薪水。 35 | 36 | ### ● 限制: 37 | - 需滿足每小時所需人數的最低需求。 38 | - 每位員工每天只能工作一個班次 39 | - 員工只能在他們可得的時間上班。 40 | - 如果該員工需上班,則他必須滿足他最少所需上班的時數且不得大於他最多能上班時數 41 | 42 | ## (二) 數學模型 43 | 44 | ### ● 符號設定 45 | D:員工人數(d=1,...,|D|)
46 | 47 | I:總時間(i,j,c=1,...,|I|) 48 | 49 | ### ● 參數設定 50 | GitHub 51 | 52 | ### ● 決策變數 53 | 54 | 55 | ### ● 目標函數 56 | 57 | 58 | ### ● 限制式 59 | 60 | 61 | ## (三) Python+Gurobi 62 | ##### ※完整程式碼可點擊[這裡](https://github.com/wurmen/Gurobi-Python/blob/master/python-gurobi%20%20model/Optimal%20Employee%20Work%20Schedule.py) 63 | ## Import gurobipy 64 | 65 | 66 | ```python 67 | from gurobipy import* 68 | ``` 69 | 70 | ## Model 71 | 72 | 73 | ```python 74 | m=Model("work_schedule") 75 | ``` 76 | 77 | ## Add parameters 78 | 79 | 80 | ```python 81 | #設定每位員工資訊 82 | employee,min,max,cost,avs,ave=multidict({ 83 | ("SMITH"):[6,8,30,6,20],("JOHNSON"):[6,8,50,0,24],('WILLIAMS'):[6,8,30,0,24], 84 | ('JONES'):[6,8,30,0,24],('BROWN'):[6,8,40,0,24],('DAVIS'):[6,8,50,0,24], 85 | ('MILLER'):[6,8,45,6,18],('WILSON'):[6,8,30,0,24],('MOORE'):[6,8,35,0,24], 86 | ('TAYLOR'):[6,8,40,0,24],('ANDERSON'):[2,3,60,0,6],('THOMAS'):[2,4,40,0,24], 87 | ('JACKSON'):[2,4,60,8,16],('WHITE'):[2,6,55,0,24],('HARRIS'):[2,6,45,0,24], 88 | ('MARTIN'):[2,3,40,0,24],('THOMPSON'):[2,5,50,12,24],('GARCIA'):[2,4,50,0,24], 89 | ('MARTINEZ'):[2,4,40,0,24],('ROBINSON'):[2,5,50,0,24]}) 90 | 91 | #每個時段所需要的員工數 92 | required=[1,1,2,3,6,6,7,8,9,8,8,8,7,6,6,5,5,4,4,3,2,2,2,2] 93 | #總時間為24小時 94 | t=24 95 | ``` 96 | 97 | ## Update 98 | 99 | 100 | ```python 101 | m.update() 102 | ``` 103 | 104 | ## Add decision variables 105 | 106 | 107 | ```python 108 | x={} 109 | staffNumber={} 110 | for d in employee: 111 | for i in range(t): 112 | for j in range(i+1,t+1): 113 | x[d,i,j]=m.addVar(vtype=GRB.BINARY,name="x_%s_%d_%d"%(d,i,j)) 114 | for c in range(t): 115 | staffNumber[c]=m.addVar(vtype=GRB.INTEGER,lb=required[c],name='staffNumber_%d'%c) 116 | 117 | ``` 118 | 119 | ## Add objective and constraints 120 | 121 | 122 | ```python 123 | m.setObjective(quicksum(quicksum(quicksum((j-i)*x[d,i,j]*cost[d] for j in range(i+1,t+1))for i in range(t))for d in employee),GRB.MINIMIZE) 124 | 125 | for d in employee: 126 | m.addConstr(quicksum(quicksum(x[d,i,j] for j in range(i+1,ave[d]+1)if min[d] <= (j-i) <= max[d])for i in range(avs[d],ave[d]))<=1) 127 | m.addConstr(quicksum(quicksum(x[d,i,j] for j in range(i+1,t+1))for i in range(t))<=quicksum(quicksum(x[d,i,j] for j in range(i+1,ave[d]+1) 128 | if min[d] <= (j-i) <= max[d])for i in range(avs[d],ave[d]))) 129 | for c in range(t): 130 | m.addConstr(quicksum(quicksum(quicksum(x[d,i,j] for j in range(i+1,t+1)if i <= c 242 | 243 | 244 | #### ● 員工班次排程圖 245 | 每位員工的排班情形,如下圖所示,從此圖可看出 ANDERSON、JACKSON 並沒有被安排班次,我們可以從員工每小時薪資表(圖一)發現,這兩位員工的薪資皆是較高的,這是由於若在可以滿足每時段最低員工人數所需的情況下,為了使薪資成本最小化,將會優先排除薪資較高的員工。
246 | 247 | -------------------------------------------------------------------------------- /python-gurobi model/Optimal Employee Work Schedule.py: -------------------------------------------------------------------------------- 1 | from gurobipy import* 2 | 3 | employee,min,max,cost,avs,ave=multidict({ 4 | ("SMITH"):[6,8,30,6,20],("JOHNSON"):[6,8,50,0,24],('WILLIAMS'):[6,8,30,0,24], 5 | ('JONES'):[6,8,30,0,24],('BROWN'):[6,8,40,0,24],('DAVIS'):[6,8,50,0,24], 6 | ('MILLER'):[6,8,45,6,18],('WILSON'):[6,8,30,0,24],('MOORE'):[6,8,35,0,24], 7 | ('TAYLOR'):[6,8,40,0,24],('ANDERSON'):[2,3,60,0,6],('THOMAS'):[2,4,40,0,24], 8 | ('JACKSON'):[2,4,60,8,16],('WHITE'):[2,6,55,0,24],('HARRIS'):[2,6,45,0,24], 9 | ('MARTIN'):[2,3,40,0,24],('THOMPSON'):[2,5,50,12,24],('GARCIA'):[2,4,50,0,24], 10 | ('MARTINEZ'):[2,4,40,0,24],('ROBINSON'):[2,5,50,0,24]}) 11 | 12 | 13 | required=[1,1,2,3,6,6,7,8,9,8,8,8,7,6,6,5,5,4,4,3,2,2,2,2] 14 | 15 | t=24 16 | 17 | x={} 18 | staffNumber={} 19 | m=Model("work_schedule") 20 | 21 | for d in employee: 22 | for i in range(t): 23 | for j in range(i+1,t+1): 24 | x[d,i,j]=m.addVar(vtype=GRB.BINARY,name="x_%s_%d_%d"%(d,i,j)) 25 | for c in range(t): 26 | staffNumber[c]=m.addVar(vtype=GRB.INTEGER,lb=required[c],name='staffNumber_%d'%c) 27 | 28 | m.update() 29 | 30 | m.setObjective(quicksum(quicksum(quicksum((j-i)*x[d,i,j]*cost[d] for j in range(i+1,t+1))for i in range(t))for d in employee),GRB.MINIMIZE) 31 | 32 | for d in employee: 33 | m.addConstr(quicksum(quicksum(x[d,i,j] for j in range(i+1,ave[d]+1)if min[d] <= (j-i) <= max[d])for i in range(avs[d],ave[d]))<=1) 34 | m.addConstr(quicksum(quicksum(x[d,i,j] for j in range(i+1,t+1))for i in range(t))<=quicksum(quicksum(x[d,i,j] for j in range(i+1,ave[d]+1) 35 | if min[d] <= (j-i) <= max[d])for i in range(avs[d],ave[d]))) 36 | for c in range(t): 37 | m.addConstr(quicksum(quicksum(quicksum(x[d,i,j] for j in range(i+1,t+1)if i <= c 5 | *2017/10/08* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | ### ● 題目
10 | 11 |
12 | 13 | ### ● 數學式
14 | 15 |
16 | 17 | 18 | ## Import gurobipy 19 | 20 | ```python 21 | from gurobipy import* 22 | ``` 23 | ## Model 24 | 25 | ```python 26 | m=Model('Protorype example_type1') 27 | ``` 28 | 29 | 30 | ## Add decision variables 31 | ```python 32 | x_1=m.addVar(lb=0,vtype=GRB.CONTINUOUS,name='x_1') 33 | x_2=m.addVar(lb=0,vtype=GRB.CONTINUOUS,name='x_2') 34 | ``` 35 | 36 | 37 | ## Update 38 | 39 | ```python 40 | m.update() 41 | ``` 42 | 43 | ## Add objective and constraints 44 | 45 | ```python 46 | m.setObjective(3*x_1+5*x_2,GRB.MAXIMIZE) 47 | ``` 48 | 49 | 50 | ```python 51 | m.addConstr(x_1<=4,'c0') 52 | m.addConstr(2*x_2<=12,'c1') 53 | m.addConstr(3*x_1+2*x_2<=18,'c2') 54 | ``` 55 | 56 | 57 | 58 | ## Result 59 | 60 | 61 | ```python 62 | m.optimize() 63 | ``` 64 | ``` 65 | Optimize a model with 3 rows, 2 columns and 4 nonzeros 66 | Coefficient statistics: 67 | Matrix range [1e+00, 3e+00] 68 | Objective range [3e+00, 5e+00] 69 | Bounds range [0e+00, 0e+00] 70 | RHS range [4e+00, 2e+01] 71 | Presolve removed 2 rows and 0 columns 72 | Presolve time: 0.02s 73 | Presolved: 1 rows, 2 columns, 2 nonzeros 74 | 75 | Iteration Objective Primal Inf. Dual Inf. Time 76 | 0 4.5000000e+01 1.500000e+00 0.000000e+00 0s 77 | 1 3.6000000e+01 0.000000e+00 0.000000e+00 0s 78 | 79 | Solved in 1 iterations and 0.03 seconds 80 | Optimal objective 3.600000000e+01 81 | ``` 82 | 83 | 84 | ```python 85 | print('obj:%d'%m.objVal) 86 | for v in m.getVars(): 87 | print('%s:%d'%(v.varName,v.x)) 88 | ``` 89 | ``` 90 | obj:36 91 | x_1:2 92 | x_2:6 93 | 94 | ``` 95 | -------------------------------------------------------------------------------- /python-gurobi model/Prototype example_type2.md: -------------------------------------------------------------------------------- 1 | 2 | # Prototype example 3 | *POLab* 4 |
5 | *2017/10/08* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | ### ● 題目
10 | 11 |
12 | 13 | ### ● 數學式轉換
14 | 15 |
16 | 17 |
18 | 19 | 20 | 21 | 22 | ## Import gurobipy 23 | 24 | 25 | ```python 26 | from gurobipy import* 27 | ``` 28 | 29 | ## Model 30 | 31 | 32 | ```python 33 | m=Model('Protorype example_type2') 34 | ``` 35 | 36 | ## Add parameters 37 | 38 | ```python 39 | I=2 40 | J=3 41 | v=[3,5] 42 | p=[[1,0,3],[0,2,2]] 43 | a=[4,12,18] 44 | ``` 45 | 46 | ## Add decision variables 47 | 48 | 49 | ```python 50 | x={} 51 | for i in range(I): 52 | x[i]=m.addVar(lb=0,vtype=GRB.CONTINUOUS,name='x_%d'%i) 53 | ``` 54 | 55 | ## Update 56 | 57 | 58 | ```python 59 | m.update() 60 | ``` 61 | 62 | ## Add objective and constraints 63 | 64 | 65 | ```python 66 | m.setObjective(quicksum(v[i]*x[i] for i in range(I)),GRB.MAXIMIZE) 67 | 68 | for j in range(J): 69 | m.addConstr(quicksum(p[i][j]*x[i] for i in range(I))<=a[j],name='c0') 70 | ``` 71 | 72 | ## Result 73 | 74 | 75 | ```python 76 | m.optimize() 77 | print('obj:%d'%m.objVal) 78 | for v in m.getVars(): 79 | print('%s:%d'%(v.varName,v.x)) 80 | ``` 81 | ``` 82 | Optimize a model with 3 rows, 2 columns and 4 nonzeros 83 | Coefficient statistics: 84 | Matrix range [1e+00, 3e+00] 85 | Objective range [3e+00, 5e+00] 86 | Bounds range [0e+00, 0e+00] 87 | RHS range [4e+00, 2e+01] 88 | Presolve removed 2 rows and 0 columns 89 | Presolve time: 0.13s 90 | Presolved: 1 rows, 2 columns, 2 nonzeros 91 | 92 | Iteration Objective Primal Inf. Dual Inf. Time 93 | 0 4.2000000e+01 1.500000e+00 0.000000e+00 0s 94 | 1 3.6000000e+01 0.000000e+00 0.000000e+00 0s 95 | 96 | Solved in 1 iterations and 0.15 seconds 97 | Optimal objective 3.600000000e+01 98 | obj:36 99 | x_0:2 100 | x_1:6 101 | ``` 102 | -------------------------------------------------------------------------------- /python-gurobi model/Python+Gurobi基本架構.md: -------------------------------------------------------------------------------- 1 | # Python+Gurobi基本架構 2 | 3 | *POLab* 4 |
5 | *2017/09/27* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | 10 | ## (一)Python+Gurobi架構 11 | ### ● 在Python介面中,數學式子的寫法相似於原本的式子,只是將式子都拆解開來 12 | 13 | 14 | ### ● 在利用Python+Gurobi建構一個數學規劃時, 通常會依照此順序進行設定變數、目標函數、限制式等 15 | 16 | 17 | ### ● 建模時常用的for迴圈及if條件句 18 | Python中宣告for迴圈及if條件式後,記得用**冒號':'** 來結束聲明,接著在下一行打上要對for迴圈或if條件式做的事情,在此要特別注意的是Python是透過**縮排**來辨別不同的程式區塊,因此在下一行開始前,要記得按**tab鍵**來做區隔,這樣程式才知道他們是包含在for迴圈跟if條件句之下的程式碼。 19 | 20 |
-**for迴圈** 21 | ```python 22 | for i in : 23 | 24 | ``` 25 | -**if條件句** 26 | ```python 27 | if : 28 | 29 | ``` 30 | 31 | ### ● quicksum()相當於Python的sum()函數及數學符號 ∑ 32 | #### e.g. 33 |
34 |
上述限制式在Python+Gurobi中表示為: 35 | ```python 36 | for i in I: 37 | m.addConstr(quicksum(x[i,j] for j in J)<=5) 38 | ``` 39 | 40 | ### ● Python字符串格式化 41 | 42 | 在建立數學規劃的最後,通常需顯示最終求得之最佳解,例如:目標函數值、各決策變數值等...
43 | 此時,可藉由格式符來替我們列印各項數值及名稱,以下為幾個常用的格式符: 44 | #### ※如果對格式化字符串的使用較不熟悉,可參考[這裡](http://gohom.win/2015/09/13/PyStringFormat/) 45 | |符號|說明| 46 | |-----|-----| 47 | |%s|字符串| 48 | |%d|格式化整數| 49 | |%f|格式化浮點數| 50 | |%e|指數,科學計數法| 51 | |%g|根據值的大小決定使用%f或%e| 52 | #### e.g. 53 | ```python 54 | print('She is %s. She weights %gkg and is %dcm tall.'%('Rima',50.4,166)) 55 | ``` 56 | She is Rima. She weights 50.4kg and is 166cm tall. 57 | 58 | ```python 59 | print('obj:%d'%m.objVal) 60 | ``` 61 | ``` 62 | obj:36 63 | ``` 64 | ## (二)常用的三大函數及屬性 65 | ### 1.三大函數 66 | 在建立一個數學規劃時,我們必須加入我們的決策變數、目標函數及限制式,以下是在設定這些變數及式子常用的三大函數的詳細內容介紹 67 |
P.S. 在Gurobi中設定目標函數及限制式還有其他不一樣的方式,在此只介紹這三個函數的應用,若想要有更進一步的了解可至Gurboi網站內的[Python](http://www.gurobi.com/documentation/7.5/refman/py_python_api_overview.html)專區查詢,若想了解其他函數的詳細資訊可點擊[這裡](http://www.gurobi.com/documentation/7.5/refman/py_python_api_details.html) 68 | ### ● 決策變數函數 69 | 70 | 變數預設的範圍上限為無限,下限為0,變數型態為連續變數(continuous)
71 | 72 |
73 | 74 | ### ● 目標函數 75 |
76 | 77 | ### ● 限制式函數 78 | 79 | 80 | 81 | ### 2.Gurobi attributes 82 | 在Guroib中,可以透過各種屬性來查詢或更改所建立數學規劃的內容,以下為常用的幾個屬性: 83 |
P.S. 更多屬性查詢,可點擊[這裡](https://www.gurobi.com/documentation/7.0/refman/attributes.html) 84 | ### ● Model attributes: 85 | |Attribute Name|Description| 86 | |-----|-----| 87 | |**NumVars**|Number of variables| 88 | |**NumConstrs**|Number of linear constraints| 89 | |**ObjVal**|objective value for current solution| 90 | 91 | ### ● Variable attributes: 92 | |Attribute Name|Description| 93 | |-----|-----| 94 | |**LB**|Lower bound| 95 | |**Obj**|Linear objective coefficient| 96 | |**VarName**|Variable name| 97 | |**X**|Value in the current solution| 98 | 99 | ### ● Linear constraint attributes: 100 | |Attribute Name|Description| 101 | |-----|-----| 102 | |**ConstrName**|Constraint name| 103 | |**Pi**|Dual value (also known as the shadow price)| 104 | |**Slack**|Slack in the current solution| 105 | -------------------------------------------------------------------------------- /python-gurobi model/Python+Gurobi建模.md: -------------------------------------------------------------------------------- 1 | # Python+Gurobi建模 2 | 3 | *POLab* 4 |
5 | *2017/10/08* 6 |
7 | [【回到首頁】](https://github.com/PO-LAB/Python-Gurobi) 8 | 9 | ## (一)最佳化流程 10 | 11 | 12 | ## (二)問題產生 13 | ● 有x、y、z三個活動想在同一天舉辦
14 | ● 場地總時間只有四個小時可使用
15 | ● 活動z的價值為活動x及y的兩倍
16 | ● 活動x與活動y至少要選一個舉辦
17 | ● 活動x需花費1小時
18 | ● 活動y需花費2小時
19 | ● 活動z需花費3小時
20 | ● 舉辦哪幾個活動可以使價值最大化?
21 | 22 | ## (三)數學模式 23 | 24 | 25 | 26 | 27 | ## (四)Python+Gurobi建模求解 28 | ## 1.建模流程 29 | 30 | 31 | ## 2.Python+Gurobi建模 32 | 33 | 34 | 35 | ## Import gurobipy 36 | 37 | 38 | ```python 39 | from gurobipy import* #導入Gurobi函式庫 40 | ``` 41 | 42 | ## Model 43 | 44 | 45 | ```python 46 | m=Model('mip1') # 建立一個新的model,並傳至m 47 | ``` 48 | 49 | ## Add decision variable 50 | 51 | 52 | ```python 53 | x = m.addVar(vtype=GRB.BINARY, name="x") # m.addVar()加入變數 54 | y = m.addVar(vtype=GRB.BINARY, name="y") 55 | z = m.addVar(vtype=GRB.BINARY, name="z") 56 | ``` 57 | 58 | ## Update 59 | 60 | 61 | ```python 62 | m.update() #更新此model 63 | ``` 64 | 65 | ## Add objective and constraints 66 | 67 | 68 | ```python 69 | # m.setObjective()設置目標函數 70 | m.setObjective(x + y + 2 * z, GRB.MAXIMIZE) 71 | 72 | # m.addConstr()加入限制式 73 | # Add constraint: x + 2 y + 3 z <= 4 74 | m.addConstr(x + 2 * y + 3 * z <= 4, "c0") 75 | 76 | # Add constraint: x + y >= 1 77 | m.addConstr(x + y >= 1, "c1") 78 | ``` 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | ## Result 88 | - 如果不想要顯示求解的過程,可在optimize()之前加入此程式碼:**m.setParam('OutputFlag',0)** 89 | 90 | ```python 91 | m.optimize() # m.optimize()求解 92 | # 透過屬性varName、x顯示決策變數名字及值 93 | for v in m.getVars(): 94 | print('%s %g' % (v.varName, v.x)) 95 | # 透過屬性objVal顯示最佳解 96 | print('Obj: %g' % m.objVal) 97 | ``` 98 | ``` 99 | Optimize a model with 2 rows, 3 columns and 5 nonzeros 100 | Variable types: 0 continuous, 3 integer (3 binary) 101 | Coefficient statistics: 102 | Matrix range [1e+00, 3e+00] 103 | Objective range [1e+00, 2e+00] 104 | Bounds range [1e+00, 1e+00] 105 | RHS range [1e+00, 4e+00] 106 | Found heuristic solution: objective 2 107 | Presolve removed 2 rows and 3 columns 108 | Presolve time: 0.06s 109 | Presolve: All rows and columns removed 110 | 111 | Explored 0 nodes (0 simplex iterations) in 0.23 seconds 112 | Thread count was 1 (of 4 available processors) 113 | 114 | Solution count 2: 3 2 115 | 116 | Optimal solution found (tolerance 1.00e-04) 117 | Best objective 3.000000000000e+00, best bound 3.000000000000e+00, gap 0.0000% 118 | x 1 119 | y 0 120 | z 1 121 | Obj: 3 122 | ``` 123 | -------------------------------------------------------------------------------- /python-gurobi model/Python+Gurobi特殊資料結構.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python+Gurobi特殊資料結構\n", 8 | "*POLab*\n", 9 | "
\n", 10 | "*2017/10/30*\n", 11 | "
\n", 12 | "[【回到首頁】](https://github.com/PO-LAB/Python-Gurobi)\n", 13 | "#### ※參考資料https://wenku.baidu.com/view/2aa313d328ea81c758f5782b.html 、[Gurobi-Python Interface](https://www.gurobi.com/documentation/6.5/quickstart_windows/py_python_interface.html#section:Python)\n", 14 | "-----------------------------------------------" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "在GurobI的Python介面中,會經常使用下列的資料結構,前四者為Python原有的資料結構,tuplelist是Gurobi為Python介面客製化的結構,可使Python Gurobi在資料處理上更加有效率和靈活。\n", 22 | "### ● list(列表)\n", 23 | "### ● tuple(元組)\n", 24 | "### ● dictionary(字典)\n", 25 | "### ● list comprehension(列表解析)\n", 26 | "### ● tuplelist\n", 27 | "\n" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## (一)Lists(列表) and Tuples(元組)\n", 35 | "- 兩者皆為**有序集合**,索引位置由**’0’**開始數起\n", 36 | "- 內部可放任何物件,ex:數字、字串、字典、列表、元組等\n", 37 | "- 都可以透過索引、切片取得內部物件\n", 38 | "\n", 39 | "### ● Lists(列表)\n", 40 | "\n", 41 | "- 以\"[ ]\"形成
\n", 42 | " ex.[‘Pen’,’Denver’,’New York’]
\n", 43 | "- 可以新增、刪除、修改內容" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 1, 49 | "metadata": { 50 | "collapsed": false 51 | }, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "1\n", 58 | "list\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "#創建一個list a\n", 64 | "a=[1,2,3,'list']\n", 65 | "#索引位置由0開始\n", 66 | "print a[0]\n", 67 | "print a[3]" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 2, 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "[1, 2, 3, 'list', 4]\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "#利用append為list最後加入一個元素\n", 87 | "a.append(4)\n", 88 | "print a" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 3, 94 | "metadata": { 95 | "collapsed": false 96 | }, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "[1, 2, 'list', 4]\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "#利用remove刪除list中符合條件的元素\n", 108 | "a.remove(3)\n", 109 | "print a" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": { 115 | "collapsed": true 116 | }, 117 | "source": [ 118 | "### ● tuple(元組)\n", 119 | "\n", 120 | "- 以\"()\"形成
\n", 121 | " ex.(‘Pen’,’Denver’,’New York’)
\n", 122 | "- tuple是**不可變的**,一旦被建立就不能修改
\n", 123 | "- 由於不可變的特性,因此可利用tuples當成dictionaries的索引\n" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 4, 129 | "metadata": { 130 | "collapsed": false 131 | }, 132 | "outputs": [ 133 | { 134 | "name": "stdout", 135 | "output_type": "stream", 136 | "text": [ 137 | "1\n", 138 | "tuple\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "#創建一個tuple b\n", 144 | "b=(1,2,3,'tuple')\n", 145 | "#索引位置由0開始\n", 146 | "print b[0]\n", 147 | "print b[3]" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "## (二)Dictionaries(字典)and multidict" 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "### ● Dictionaries(字典)\n", 162 | "- 使用”{ }”建立新的字典,字典以**「鍵值(key):值(value)」**表示一個元素,並以冒號’:’來辨別鍵值與值
\n", 163 | "- 任一不可變的python物件皆可做為一個鍵值(key):
\n", 164 | "an integer、a oating-point number、a string、a tuple
\n", 165 | "- 透過’鍵值’來搜尋對應的’值’
\n", 166 | "- 在Python Gurobi 中可以透過字典來儲存gurobi的決策變數" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 5, 172 | "metadata": { 173 | "collapsed": false 174 | }, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "{'zero': 0, 'two': 2, 'one': 1}\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "#建立一個字典對象values,並將各數值與相對應的鍵值(key)進行連結\n", 186 | "values={}\n", 187 | "values['zero']=0\n", 188 | "values['one']=1\n", 189 | "values['two']=2\n", 190 | "print values" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 6, 196 | "metadata": { 197 | "collapsed": false 198 | }, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "{'four': 4, 'five': 5, 'three': 3}\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "#透過初始化資料結構的方式建立字典\n", 210 | "numbers={'three':3,'four':4,'five':5}\n", 211 | "print numbers" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 7, 217 | "metadata": { 218 | "collapsed": false 219 | }, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "0\n", 226 | "3\n" 227 | ] 228 | } 229 | ], 230 | "source": [ 231 | "#利用鍵值(key)尋找所對應的值(value)\n", 232 | "print values['zero']\n", 233 | "print numbers['three']" 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": {}, 239 | "source": [ 240 | "## ● multidict\n", 241 | "- 可以一次初始化一個或多個字典
\n", 242 | "- 參數是一個字典對象,每一個鍵值都對應一個長度為n的列表,該函數會將每一個列表拆成n個單項,並創造出n個字典
\n" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 8, 248 | "metadata": { 249 | "collapsed": false 250 | }, 251 | "outputs": [], 252 | "source": [ 253 | "from gurobipy import*\n", 254 | "names,lower,upper=multidict({'x':[0,1],'y':[1,2],'z':[0,3]})" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": 9, 260 | "metadata": { 261 | "collapsed": false 262 | }, 263 | "outputs": [ 264 | { 265 | "name": "stdout", 266 | "output_type": "stream", 267 | "text": [ 268 | "['y', 'x', 'z']\n" 269 | ] 270 | } 271 | ], 272 | "source": [ 273 | "#顯示共享鍵值列表\n", 274 | "print names" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 10, 280 | "metadata": { 281 | "collapsed": false 282 | }, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "{'y': 1, 'x': 0, 'z': 0}\n", 289 | "{'y': 2, 'x': 1, 'z': 3}\n" 290 | ] 291 | } 292 | ], 293 | "source": [ 294 | "#顯示所創立的兩個字典\n", 295 | "print lower\n", 296 | "print upper" 297 | ] 298 | }, 299 | { 300 | "cell_type": "markdown", 301 | "metadata": {}, 302 | "source": [ 303 | "## (三)List comprehension(列表解析) and tuplelist\n", 304 | "### ● List comprehension(列表解析)\n", 305 | "- 以更簡潔的方式產生列表\n" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 11, 311 | "metadata": { 312 | "collapsed": false 313 | }, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "[1, 4, 9, 16, 25]\n" 320 | ] 321 | } 322 | ], 323 | "source": [ 324 | "print [x*x for x in [1,2,3,4,5]]" 325 | ] 326 | }, 327 | { 328 | "cell_type": "markdown", 329 | "metadata": {}, 330 | "source": [ 331 | "- 一個列表解析可包含多個for迴圈及if條件句\n" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 12, 337 | "metadata": { 338 | "collapsed": false 339 | }, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "[(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)]\n" 346 | ] 347 | } 348 | ], 349 | "source": [ 350 | " print [(x,y) for x in range(3) for y in range(3) if x != y] " 351 | ] 352 | }, 353 | { 354 | "cell_type": "markdown", 355 | "metadata": {}, 356 | "source": [ 357 | "### ● tuplelist\n", 358 | "- 能夠有效的在元組列表中檢索符合要求的子列表\n", 359 | "- 透過tuplelist中的**select**方法返回所有滿足特定條件的元組子集,此方法可以提高資料選擇的效率\n", 360 | "- 透過符號‘*’表示元組中相應位置元素配對成功的值\n" 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "execution_count": 13, 366 | "metadata": { 367 | "collapsed": false 368 | }, 369 | "outputs": [ 370 | { 371 | "name": "stdout", 372 | "output_type": "stream", 373 | "text": [ 374 | "\n" 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "from gurobipy import*\n", 383 | "l=tuplelist([(1,2),(1,3),(2,3),(2,4)])\n", 384 | "print l.select(1,'*')" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 14, 390 | "metadata": { 391 | "collapsed": false 392 | }, 393 | "outputs": [ 394 | { 395 | "name": "stdout", 396 | "output_type": "stream", 397 | "text": [ 398 | "\n" 402 | ] 403 | } 404 | ], 405 | "source": [ 406 | "print l.select('*',3)" 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": 15, 412 | "metadata": { 413 | "collapsed": false 414 | }, 415 | "outputs": [ 416 | { 417 | "name": "stdout", 418 | "output_type": "stream", 419 | "text": [ 420 | "\n" 423 | ] 424 | } 425 | ], 426 | "source": [ 427 | "print l.select(1,3)" 428 | ] 429 | }, 430 | { 431 | "cell_type": "code", 432 | "execution_count": 16, 433 | "metadata": { 434 | "collapsed": false 435 | }, 436 | "outputs": [ 437 | { 438 | "name": "stdout", 439 | "output_type": "stream", 440 | "text": [ 441 | "\n" 447 | ] 448 | } 449 | ], 450 | "source": [ 451 | "print l.select('*','*')" 452 | ] 453 | }, 454 | { 455 | "cell_type": "markdown", 456 | "metadata": {}, 457 | "source": [ 458 | "## ● List comprehension v.s.tuplelist\n", 459 | "- 列表解析也可以達到與tuplelist同樣的搜尋結果,但是會較沒效率\n" 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": 17, 465 | "metadata": { 466 | "collapsed": false 467 | }, 468 | "outputs": [ 469 | { 470 | "name": "stdout", 471 | "output_type": "stream", 472 | "text": [ 473 | "\n" 477 | ] 478 | } 479 | ], 480 | "source": [ 481 | "print l.select(1,'*')" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 18, 487 | "metadata": { 488 | "collapsed": false 489 | }, 490 | "outputs": [ 491 | { 492 | "name": "stdout", 493 | "output_type": "stream", 494 | "text": [ 495 | "[(1, 2), (1, 3)]\n" 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | " print [(x,y) for x,y in l if x ==1] " 501 | ] 502 | } 503 | ], 504 | "metadata": { 505 | "kernelspec": { 506 | "display_name": "Python 2", 507 | "language": "python", 508 | "name": "python2" 509 | }, 510 | "language_info": { 511 | "codemirror_mode": { 512 | "name": "ipython", 513 | "version": 2 514 | }, 515 | "file_extension": ".py", 516 | "mimetype": "text/x-python", 517 | "name": "python", 518 | "nbconvert_exporter": "python", 519 | "pygments_lexer": "ipython2", 520 | "version": "2.7.12" 521 | } 522 | }, 523 | "nbformat": 4, 524 | "nbformat_minor": 2 525 | } 526 | -------------------------------------------------------------------------------- /python-gurobi model/gurobi.log: -------------------------------------------------------------------------------- 1 | 2 | Gurobi 8.0.0 (win64, Python) logging started 05/29/18 13:21:00 3 | 4 | Academic license - for non-commercial use only 5 | Optimize a model with 16 rows, 12 columns and 36 nonzeros 6 | Coefficient statistics: 7 | Matrix range [1e+00, 1e+00] 8 | Objective range [1e+01, 8e+01] 9 | Bounds range [8e+01, 1e+02] 10 | RHS range [1e+01, 1e+02] 11 | Presolve removed 16 rows and 12 columns 12 | Presolve time: 0.00s 13 | Presolve: All rows and columns removed 14 | Iteration Objective Primal Inf. Dual Inf. Time 15 | 0 5.5000000e+03 0.000000e+00 0.000000e+00 0s 16 | 17 | Solved in 0 iterations and 0.00 seconds 18 | Optimal objective 5.500000000e+03 19 | Freed default Gurobi environment 20 | -------------------------------------------------------------------------------- /python-gurobi model/picture/Controlling Air Pollution example/.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /python-gurobi model/picture/Controlling Air Pollution example/Controlling Air Pollution 12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Controlling Air Pollution example/Controlling Air Pollution 12.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Controlling Air Pollution example/Controlling Air Pollution 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Controlling Air Pollution example/Controlling Air Pollution 2.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Controlling Air Pollution example/Controlling Air Pollution1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Controlling Air Pollution example/Controlling Air Pollution1.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Dual example/.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /python-gurobi model/picture/Dual example/convertPintoD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Dual example/convertPintoD.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Netflow problem/.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /python-gurobi model/picture/Netflow problem/netflow problem model.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Netflow problem/netflow problem model.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Netflow problem/netflow problem picture.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Netflow problem/netflow problem picture.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Netflow problem/netflow problem picture_final.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Netflow problem/netflow problem picture_final.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/參數設定.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/參數設定.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/員工班次排程圖.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/員工班次排程圖.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/員工資訊.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/員工資訊.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/每小時最少所需人數.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/每小時最少所需人數.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/每時段所需員工人數比較圖.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/每時段所需員工人數比較圖.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/決策變數.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/決策變數.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/目標函數.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/目標函數.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Optimal Employee Work Schedule/限制式.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Optimal Employee Work Schedule/限制式.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/Prototype example picture/Prototype example 數學式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Prototype example picture/Prototype example 數學式.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Prototype example picture/Prototype example_type2_S.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Prototype example picture/Prototype example_type2_S.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Prototype example picture/Prototype example_type2_數學式轉換.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Prototype example picture/Prototype example_type2_數學式轉換.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Prototype example picture/Prototype example_type2符號設定.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Prototype example picture/Prototype example_type2符號設定.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Prototype example picture/Prototype example題目.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Prototype example picture/Prototype example題目.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Python+gurobi 架構.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Python+gurobi 架構.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Python+gurobi建模/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Python+gurobi建模/example.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Python+gurobi建模/建模範例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Python+gurobi建模/建模範例.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Python+gurobi建模/最佳化流程.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Python+gurobi建模/最佳化流程.png -------------------------------------------------------------------------------- /python-gurobi model/picture/Python+gurobi建模流程.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/Python+gurobi建模流程.png -------------------------------------------------------------------------------- /python-gurobi model/picture/m.addconstr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/m.addconstr.png -------------------------------------------------------------------------------- /python-gurobi model/picture/m.addvar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/m.addvar.png -------------------------------------------------------------------------------- /python-gurobi model/picture/m.setobjective.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/m.setobjective.png -------------------------------------------------------------------------------- /python-gurobi model/picture/mip_example執行畫面.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/mip_example執行畫面.PNG -------------------------------------------------------------------------------- /python-gurobi model/picture/python數學式子.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/python數學式子.png -------------------------------------------------------------------------------- /python-gurobi model/picture/quicksum_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/quicksum_example.png -------------------------------------------------------------------------------- /python-gurobi model/picture/求解題目.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wurmen/Gurobi-Python/593c62084bda91cc48ef3f42a2b455c83fef213f/python-gurobi model/picture/求解題目.png --------------------------------------------------------------------------------