Wednesday, February 10, 2010

Using GLPK in Python through pulp 1.4.7 in Windows Seven (32 bits)

There are several steps before we can use GLPK (GNU Linear Programming Kits) in Python
1. For those who are not familiar with python, you have to learn some of basic Python here (I recommend to use python v.2.6.4).
2. Install Pulp 1.4.7 from here (please also follow the install instruction in Windows)
3. Download the Microsoft Visual Studio Express 2008 from microsoft (Indeed, we just want only visual c compiler, but I've not tried it yet).
4. Download the GLPK from here
5. Goes deep into folder "your download directory"\glpk-4.42\glpk-4.42\w32. Find for the file name Build_GLPK_with_VC9.bat.
6. Open with text editor and check for the path of c compiler (in the case that you have changed the default installation directory of visual C compiler).
7. Run Build_GLPK_with_VC9.bat
8. If the installation was successfully, it will display the message 'OPTIMAL SOLUTION FOUND'.
9. Now, you test with the following script

Note that you have to add the path for all executable files (Python, Easy_install and glpsol) in the environment variables of Windows seven.

from pulp import *

prob = LpProblem("test1", LpMinimize)

# Variables x = LpVariable("x", 0, 4) y = LpVariable("y", -1, 1) z = LpVariable("z", 0)

# Objective prob += x + 4*y + 9*z

# Constraints prob += x+y <= 5 prob += x+z >= 10 prob += -y+z == 7

GLPK().solve(prob)

# Solution for v in prob.variables():    print v.name, "=", v.varValue

print "objective=", value(prob.objective)

33 comments:

  1. 看到大家都留言,我也來留個言支持!!!加油囉 ........................................

    ReplyDelete
  2. 與人相處不妨多用眼睛說話,多用嘴巴思考,..................................................

    ReplyDelete
  3. hello~welcome my world~<. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    ReplyDelete
  4. 向小善致敬,它使人生旅程較為平順。........................................

    ReplyDelete
  5. All roads lead to Rome. 堅持自己所選!.............................................

    ReplyDelete
  6. 卡爾.桑得柏:「除非先有夢,否則一切皆不成。」共勉!..................................................

    ReplyDelete
  7. 文章是心情的反應~~祝妳天天寫的都是讓人開心的好文章哦!!............................................................

    ReplyDelete
  8. 人生最重要的一件事,就是從生活中認識你自己。............................................................

    ReplyDelete
  9. 生命所經歷的折磨愈多,其所產生的奮鬥力愈大。............................................................

    ReplyDelete
  10. 好久沒有這樣輕鬆享受閱讀的樂趣了~~留個言邀您分享我的快樂~~..................................................................

    ReplyDelete
  11. 我們這一代最偉大的發現是,人類可以藉由改變心中的態度來改變人生。.......................................................

    ReplyDelete
  12. 人生有些波折,才能有些成長,所以不論順逆,凡是成長、成功的助緣,都應該心存感激。.................................................

    ReplyDelete
  13. 聰明人之所以不會成功,是因為他們缺乏了堅忍的毅力。.................................................

    ReplyDelete
  14. 河水永遠是相同的,可是每一剎那又都是新的。..................................................

    ReplyDelete
  15. 一棵樹除非在春天開了花,否則難望在秋天結果。......................................... ........................

    ReplyDelete