Formulating an Linear Programming Assignment in pulp

So, here's the context of what I am trying to solve:

I want to divide cost units into two or more companies. Now, I have it solved for two companies with the following objective function:

20*x1 + 30*x2 + 100*x3 + 20*x4 + 30*x5

with the variables being Binary type.

Suppose I get the optimized solution as:

x1 = 1
x2 = 0
x3 = 0
x4 = 1
x5 = 0

this means that Company A would be responsible for unit costs x1 and x4 and Company B with the rest of the costs.

This is working fine, and I have all coded on pulp correctly. I can also use constraints to limit the maximum cost for a particular company, which is the point of all this to begin with. The coefficients's sum represent the total cost of a given project. So I use that amount as constraint to the objective function to limit the cost of Company A

Now, what I want to do is the same thing with 3 or more companies. I have no idea how to formulate the objective function or functions, as I think that it might fall into a multi objective function problem, but I'm actually not sure.

I am not very experienced in Linear Programming, so I'm sorry if I have misplaced the question. I haven't found anything that could help me accomplish this.

I would put the code, but I have way more variables and some basic data preparation before creating the function, so I created a hypothetical example to make it easier to understand.

Thanks very much for any help.

Upvotes: 0

Views: 1870

Answers (1)

abc
abc

Reputation: 11929

You can define a binary variable as follows:

x_{i,j} = 1 if Company i is responsible for Unit Cost j

and add a constraint for each unit cost j telling that exactly one company must be responsible for that cost.
Consider the following example.

# data
companies = ["company1", "company2", ...]
products = ["prod1", "prod2", ...]
cost = {"prod1": cost1, "prod2": cost2, ...}

x = pulp.LpVariable.dicts("responsability",[(company, product) for company in companies for product in products], cat=pulp.LpBinary)    
prob = pulp.LpProblem("ilp", pulp.LpMinimize)

# objective function - assuming the cost is the same for all the companies
prob += pulp.LpSum(cost[product] * sum(x[(company, product)] for company in companies) for product in products)

# each product assigned to one company
for product in products:
   prob+= pulp.LpSum(x[(company, product)] for company in companies) == 1

# additional constraints
...

Upvotes: 2

Related Questions