Created
December 21, 2011 16:52
-
-
Save satomacoto/1506745 to your computer and use it in GitHub Desktop.
Linear Programming w/ OpenOpt, FuncDesigner, GLPK, CVXOPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from FuncDesigner import * | |
from openopt import LP | |
# 変数の定義 | |
x1,x2 = oovars(2) | |
# 目的関数 | |
f = 3*x1 + 2*x2 | |
# 初期解 | |
startPoint = {x1:0, x2:0} | |
# 制約条件 | |
constraints = [x1+x2<=5, x1+3*x2<=10, 2*x1+x2<=9] | |
# 式の定義 | |
p = LP(f, startPoint, constraints=constraints, goal='max') | |
# 解 | |
r = p.solve('glpk') | |
x1_opt,x2_opt = r(x1,x2) | |
print(x1_opt,x2_opt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment