Hi,

I use pulp module to solve my some optimization problems. With integer numbers, it works like a charm. I wonder if it is possible for pulp to work with real numbers.

Here is a sample optimization problem I build for my project.

``````prob = pulp.LpProblem("example", pulp.LpMinimize)

# Variable represent number of times device i is used
n1 = pulp.LpVariable("n1", 1, 5, pulp.LpInteger)
n2 = pulp.LpVariable("n2", 0, max_exp, pulp.LpInteger)
n3 = pulp.LpVariable("n3", 0, max_exp, pulp.LpInteger)
n4 = pulp.LpVariable("n4", 0, max_exp, pulp.LpInteger)
n5 = pulp.LpVariable("n5", 0, max_exp, pulp.LpInteger)

# The objective function that we want to minimize: the total cost
prob += n1 * Device1[-1] + n2 * Device2[-1] + n3 * Device3[-1] + n4 * Device4[-1] + n5 * Device5[-1], "Minimize total cost"

# Constraint that we use no more than max. devices per controller device
prob += n2 + n3 + n4 + n5 <= n1*max_exp

#Constraint (total_UI >= (target_AI + target_BI))
prob += n1 * Device1 + n2 * Device2 + n3 * Device3 + n4 * Device4 + n5 * Device5 >= (Target+Target)

#Constraint ((total_UO + total_BO) >= target_BO)
prob += n1 * Device1 + n2 * Device2 + n3 * Device3 + n4 * Device4 + n5 * Device5 + n1 * Device1 + n2 * Device2 + n3 * Device3 + n4 * Device4 + n5 * Device5>= (Target)

#Constraint [total_UO + total_AO + total_BO - target_BO] >= target_AO
prob += n1 * Device1 + n2 * Device2 + n3 * Device3 + n4 * Device4 + n5 * Device5 + n1 * Device1 + n2 * Device2 + n3 * Device3 + n4 * Device4 + n5 * Device5 + n1 * Device1 + n2 * Device2 + n3 * Device3 + n4 * Device4 + n5 * Device5 >= (Target+Target)

# Actually solve the problem, this calls GLPK so you need it installed
prob.solve()``````

Lets assume DeviceX[-1] be a real number. Could you make the required changes?

If you would multiply all values by constant, say 1000000, and divide solution accordingly, maybe it could work out to transform the problem to integer realm.

This is not a good idea. LP problems are much easier to solve with real numbers than with integers, so yes I think pulp …

## All 2 Replies

If you would multiply all values by constant, say 1000000, and divide solution accordingly, maybe it could work out to transform the problem to integer realm.

If you would multiply all values by constant, say 1000000, and divide solution accordingly, maybe it could work out to transform the problem to integer realm.

This is not a good idea. LP problems are much easier to solve with real numbers than with integers, so yes I think pulp can work with real numbers, but since I don't use pulp, I can't make the required changes to your code. The solution is in the pulp documentation https://www.coin-or.org/PuLP/ .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.