
Supply chain programming (P-median location problem in python)
- or -
Post a project like this1689
£20(approx. $27)
- Posted:
- Proposals: 7
- Remote
- #3262878
- Awarded
Website Developer, Graphic Designer, Transcriber, Content writer, CAD Expert, Python Developer, Photo Editor, Web Scrapper, JAVA developer, Android developer, Wix/Shopify Expert,

2412587254377851681112147640527048856829825425955
Description
Experience Level: Entry
I have a formulation, and I need to edit it. Could you please help me with it? by removing the warehouses :
from __future__ import print_function
import sys
from ortools.constraint_solver import pywrapcp
def main():
# Create the solver.
solver = pywrapcp.Solver('P-median problem')
#
# data
#
p = 2
num_customers = 4
customers = list(range(num_customers))
Albert, Bob, Chris, Daniel = customers
num_warehouses = 3
warehouses = list(range(num_warehouses))
Santa_Clara, San_Jose, Berkeley = warehouses
demand = [100, 80, 80, 70]
distance = [[2, 10, 50], [2, 10, 52], [50, 60, 3], [40, 60, 1]]
#
# declare variables
#
open = [solver.IntVar(warehouses, 'open[%i]% % i') for w in warehouses]
ship = {}
for c in customers:
for w in warehouses:
ship[c, w] = solver.IntVar(0, 1, 'ship[%i,%i]' % (c, w))
ship_flat = [ship[c, w] for c in customers for w in warehouses]
z = solver.IntVar(0, 1000, 'z')
#
# constraints
#
z_sum = solver.Sum([
demand[c] * distance[c][w] * ship[c, w]
for c in customers
for w in warehouses
])
solver.Add(z == z_sum)
for c in customers:
s = solver.Sum([ship[c, w] for w in warehouses])
solver.Add(s == 1)
solver.Add(solver.Sum(open) == p)
for c in customers:
for w in warehouses:
solver.Add(ship[c, w] <= open[w])
# objective
objective = solver.Minimize(z, 1)
#
# solution and search
#
db = solver.Phase(open + ship_flat, solver.INT_VAR_DEFAULT,
solver.INT_VALUE_DEFAULT)
solver.NewSearch(db, [objective])
num_solutions = 0
while solver.NextSolution():
num_solutions += 1
print('z:', z.Value())
print('open:', [open[w].Value() for w in warehouses])
for c in customers:
for w in warehouses:
print(ship[c, w].Value(), end=' ')
print()
print()
print('num_solutions:', num_solutions)
print('failures:', solver.Failures())
print('branches:', solver.Branches())
print('WallTime:', solver.WallTime(), 'ms')
if __name__ == '__main__':
main()
from __future__ import print_function
import sys
from ortools.constraint_solver import pywrapcp
def main():
# Create the solver.
solver = pywrapcp.Solver('P-median problem')
#
# data
#
p = 2
num_customers = 4
customers = list(range(num_customers))
Albert, Bob, Chris, Daniel = customers
num_warehouses = 3
warehouses = list(range(num_warehouses))
Santa_Clara, San_Jose, Berkeley = warehouses
demand = [100, 80, 80, 70]
distance = [[2, 10, 50], [2, 10, 52], [50, 60, 3], [40, 60, 1]]
#
# declare variables
#
open = [solver.IntVar(warehouses, 'open[%i]% % i') for w in warehouses]
ship = {}
for c in customers:
for w in warehouses:
ship[c, w] = solver.IntVar(0, 1, 'ship[%i,%i]' % (c, w))
ship_flat = [ship[c, w] for c in customers for w in warehouses]
z = solver.IntVar(0, 1000, 'z')
#
# constraints
#
z_sum = solver.Sum([
demand[c] * distance[c][w] * ship[c, w]
for c in customers
for w in warehouses
])
solver.Add(z == z_sum)
for c in customers:
s = solver.Sum([ship[c, w] for w in warehouses])
solver.Add(s == 1)
solver.Add(solver.Sum(open) == p)
for c in customers:
for w in warehouses:
solver.Add(ship[c, w] <= open[w])
# objective
objective = solver.Minimize(z, 1)
#
# solution and search
#
db = solver.Phase(open + ship_flat, solver.INT_VAR_DEFAULT,
solver.INT_VALUE_DEFAULT)
solver.NewSearch(db, [objective])
num_solutions = 0
while solver.NextSolution():
num_solutions += 1
print('z:', z.Value())
print('open:', [open[w].Value() for w in warehouses])
for c in customers:
for w in warehouses:
print(ship[c, w].Value(), end=' ')
print()
print()
print('num_solutions:', num_solutions)
print('failures:', solver.Failures())
print('branches:', solver.Branches())
print('WallTime:', solver.WallTime(), 'ms')
if __name__ == '__main__':
main()
S M.
100% (14)Projects Completed
12
Freelancers worked with
6
Projects awarded
54%
Last project
29 Jul 2022
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies