在项目选择问题中创建约束

问题描述 投票:0回答:1

这是我正在处理“项目选择”问题的数据框:

Return   Sector    Investment Project_name  
0.290    Solar     228376120  Solar1   
0.07     Solar     70021891   Solar2   
0.25     Wind      6467237    Eolico1  
0.3      Wind      417713440  Eolico2  
0.16     Wind      377494250  Eolico3  
0.28     Wind      230345712  Eolico4  
0.29     CGHPCHBIO 35476862   CGH1     
0.26     CGHPCHBIO 60671402   CGH2     
0.07     CGHPCHBIO 349544333  PCH1     
0.12     CGHPCHBIO 425442985  PCH2     
0.29     CGHPCHBIO 66292734   PCH3     
0.15     CGHPCHBIO 300677487  PCH4     
0.25     CGHPCHBIO 409144798  Biomassa1
0.19     CGHPCHBIO 184123496  Biomassa2
0.08     CGHPCHBIO 61835863   Biomassa3

我的目标是:

Maximize the "Return"

我的限制是:

  • [投资总额]的限制为916000000(已解决);
  • “太阳能行业”不能超过总投资的60% (解决);
  • “风能部门”不能超过总投资额的[[(%)] (要解决);和“ CGHPCHBIO Sector”不能超过总投资的
  • (25%
  • )[[(解决)这是我到目前为止所尝试的:
from pulp import * import pandas as pd import xlrd #First, we create a LP problem with the method LpProblem in PuLP prob = LpProblem("Selecao de Projetos",LpMaximize) #Read the first rows dataset in a Pandas DataFrame df = pd.read_excel("df.xlsx", encoding = 'unicode_escape') #Create a list of the projects names projects = list(df['Project_name']) #Create a dictionary of investments for all the projects investments = dict(zip(projects,df['Investment'])) #Create a dictionay of sectors for all the projects sectors = dict(zip(projects,df['Sector'])) #Create a dictionary of Returns for all the projects returns = dict(zip(projects,df['Return'])) #Create a dictionary of projects with lower bound = 0 and category continuous project_vars = LpVariable.dicts("Project",projects,lowBound =0,cat='Continuous') #Built the LP problem by assing the main objective function prob += lpSum([returns[i]*project_vars[i] for i in projects]) #Add the constraints prob += lpSum([investments[f] * project_vars[f] for f in projects]) <= 916000000 prob += lpSum([investments[f] * project_vars[f] for f in sectors["Solar"]]) <= sum(df['Investment'])*0.6 #this last one isn't working.

我想知道如何正确估算

关于按部门划分的最大投资权重的限制

这就是我正在处理“项目选择”问题的数据帧:返回行业投资项目名称0.290太阳能228376120太阳能1 0.07太阳能70021891太阳能2 0.25 ...

python pandas dictionary constraints pulp
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.