using pulp ,Choosing a project according to some constraint

91 Views Asked by At
|project|loc_Bangalore|loc_Pune|cat_s|cat_c|
|:------|:-----------:|:------:|:---:|:---:|
|abc    |1            |0       |0    |1    |
|Sys    |1            |0       |0    |1    |
|Syst   |0            |1       |1    |0    |
|EPS    |1            |0       |0    |1    |
|foss   |1            |0       |0    |1    |
|opc    |0            |1       |1    |0    |

given

In above df 1 is true and 0 is false. I have to choose all project from given df,which satisfied below condition: 1.total project choosed count<=4((banglore location project+pune location project+cat_s project+cat_c project)<=4)

2.In choosed project project count should be following: 1.banglore location project<=3 2.pune location project <=1 3.cat_s project<=1 4.cat_c project<=3

i have to select project which will satisfy both the condition. i am not able to write equation for this.Pls help me in solving this.

1

There are 1 best solutions below

1
On

I think you are close. You didn't show what answer you are getting from above, but my guess is that you are getting a bunch of wild integer values, including negative ones because your decision variable has no bounds, so it could be selecting -568 projects in area __.

First issue: When the variable represents a yes/no type of decision, you should make it a binary variable. Change this:

proj_vars = pulp.LpVariable.dicts("project",project_list,cat='Integer')

to:

proj_vars = pulp.LpVariable.dicts("project",project_list,cat='Binary')

Second issue: right now, you are missing an objective function... all you have are a bunch of "upper constraints" and the model (at least the piece you posted) has no motivation to increase (or assign) projects. You have it as a minimization model.... What are you minimizing?

From what you describe, you appear to want to do the maximum number of projects, subject to your constraints. So to do that you must: add a simple objective that is just the sum of the projects, and flip the problem into a maximization problem. Make sense?