Jeu J
Jeu J

Reputation: 21

Implementing MCLP in pulp

I just started some couple hours ago with Pulp. I'm solving a MCLP problem, but i have no idea how to implement the Ni formula: see below in picture. My idea is that if a demand node is covered that another demand node less then 100m should also be covered by the facility.

enter image description here

Upvotes: 2

Views: 925

Answers (1)

kabdulla
kabdulla

Reputation: 5429

There are a few ways to do this. The way which most closely matches your formulation is to use the 'list comprehension' capability of python. See below, which should output:

Status: Optimal
Population Served is =  100.0
x =  [1. 0.]

Simple example, with dummy data:

import numpy as np
import pandas as pd
from pulp import *

# Some dummy data, let's have 3 demand nodes and 2 possible sites
I = [0,1,2]
J = [0,1]
S = 100
d = [[50, 150], [80, 110], [160, 10]]

a = [80, 20, 30]
P = 1

# Compute the sets Ni
# NB: this will be a list in which each item is a list of nodes
# within the threshold distance of the i'th node
N = [[j for j in J if d[i][j] < S] for i in I]

# Formulate optimisation

prob = LpProblem("MCLP", LpMaximize)
x = LpVariable.dicts("x", J, 0)
y = LpVariable.dicts("y", I, 0)

# Objective
prob += lpSum([a[i]*y[i] for i in I])

# Constraints
for i in I:
    prob += lpSum([x[j] for j in N[i]]) >= y[i]

prob += lpSum([x[j] for j in J]) == P

# Solve problem
prob.solve()

x_soln = np.array([x[j].varValue for j in J])

# And print some output
print (("Status:"), LpStatus[prob.status])
print ("Population Served is = ", value(prob.objective))
print ("x = ", x_soln)

Upvotes: 1

Related Questions