凸优化第一课-介绍




线性规划可以采用python库PULP,http://packages.python.org/PuLP/index.html

例如解  

                                                                           \textbf{ min } 0.013 x_1 + 0.008 x_2             

                                                                           1.000 x_1  + 1.000 x_2 &= 100.0\\0.100 x_1  + 0.200 x_2 &\ge 8.0\\0.080 x_1  + 0.100 x_2 &\ge 6.0\\0.001 x_1  + 0.005 x_2 &\le 2.0\\0.002 x_1  + 0.005 x_2 &\le 0.4\\ 

# Import PuLP modeler functions
from pulp import *

# Create the 'prob' variable to contain the problem data,第一个参数是描述这个问题的参数,可以自己取,第二个是描述最大化还是最小化
prob = LpProblem("The Whiskas Problem",LpMinimize)

# The 2 variables Beef and Chicken are created with a lower limit of zero,第一个参数的变量名,第二个是下界,3是上届,4是表示数据类型,默认是连续
x1=LpVariable("ChickenPercent",0,None,LpInteger)
x2=LpVariable("BeefPercent",0)

# The objective function is added to 'prob' first首先加目标函数
prob += 0.013*x1 + 0.008*x2, "Total Cost of Ingredients per can"

# The five constraints are entered其次加约束
prob += x1 + x2 == 100, "PercentagesSum"
prob += 0.100*x1 + 0.200*x2 >= 8.0, "ProteinRequirement"
prob += 0.080*x1 + 0.100*x2 >= 6.0, "FatRequirement"
prob += 0.001*x1 + 0.005*x2 <= 2.0, "FibreRequirement"
prob += 0.002*x1 + 0.005*x2 <= 0.4, "SaltRequirement"

# The problem data is written to an .lp file
prob.writeLP("WhiskasModel.lp")

# The problem is solved using PuLP's choice of Solver
prob.solve()

# The status of the solution is printed to the screen
print "Status:", LpStatus[prob.status]

# Each of the variables is printed with it's resolved optimum value
for v in prob.variables():
    print v.name, "=", v.varValue

# The optimised objective function value is printed to the screen
print "Total Cost of Ingredients per can = ", value(prob.objective)

                                       

一个例子,光照问题。p是光照的强度,r是距离,a_kj的由来是如果灯太低就会照不到,所以需要一个角度。



4种近似解法



凸约束优化解法




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值