# 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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter