Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2011 16:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Linear Programming w/ OpenOpt, FuncDesigner, GLPK, CVXOPT
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment