Linear optimization in Python using pulp

我怕爱的太早我们不能终老 提交于 2020-01-06 06:40:29

问题


So I have 3 datasets as follows, Cost data:

Vcost
Out[325]: 
                            P1        P2        P3        
Vendors\Product List                                                  
V1                    0.204403  0.208178  0.198216  
V2                    0.220126  0.213755  0.198991  
V3                    0.204403  0.191450  0.203258  

Risk data:

Vrisk
Out[326]: 
                            P1        P2        P3       
Vendors\Product List                                                  
V1                    0.198598  0.210145  0.198157  
V2                    0.172897  0.178744  0.193548  
V3                    0.219626  0.200483  0.205069 

Decision variables data:

Vdecision
Out[327]: 
                     P1 P2 P3 
Vendors\Product List               
V1                    a  b  c  
V2                    f  g  h  
V3                    k  l  m

My objective is to minimize 0.71*Cost*x + 0.29*Risk*x subjected to constraints of row summation and column summation of the decision variable matrix. So basically the objective fuction will be something like:

0.71*(0.204*a+0.208*b+0.198*c....+0.203*m) + 0.29*(0.198*a+0.210*b+0.198*c....+0.205*m)

I'm trying to use the PuLP module and defined the function as:

prob = LpProblem("Inventory Optimization", LpMinimize)
prob += lpSum([0.71*i*x for i,x in zip(Vcost.values,Vdecision.values) + 0.29*j*x for j,x in zip(Vrisk.values,Vdecision.values)])

But I'm getting the following error:

TypeError: can't multiply sequence by non-int of type 'float'

Can somebody help me formulate the objective function please?

来源:https://stackoverflow.com/questions/49194399/linear-optimization-in-python-using-pulp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!