Define a Model, Objective function and Constraints in Pulp - Python Snippets - Snipit

PHOTO EMBED

Sun Jul 10 2022 05:46:10 GMT+0000 (Coordinated Universal Time)

Saved by @nilotpalc #python

# creating a model for running optimization
model = LpProblem('transportprob', sense=LpMinimize)

# defining the objective function
model += lpSum([demand_dict.get(c) * flows[(w, c)] * dist_dict.get((w, c)) for w in open_w for c in distmatrix.columns])

# defining constraints
for c in customers:
    model += lpSum([flows.get((w, c)) for w in warehouse]) == 1 # note the use of comparison operators for constraints

model += lpSum([open_w[w] for w in warehouse]) == 3

for w in warehouse:
    for c in customers:
        model += open_w[w] >= flows.get((w,c))
        
model.solve() # run the solver for solution
content_copyCOPY

https://snipit.io/