From 91fb3cf2c568bf54b9caea54c322a80ead595f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20S=C3=A1nchez?= <57121207+VikSanz@users.noreply.github.com> Date: Fri, 28 Aug 2020 13:04:06 -0500 Subject: [PATCH] Create prob_transporte.py --- prob_transporte.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 prob_transporte.py diff --git a/prob_transporte.py b/prob_transporte.py new file mode 100644 index 0000000..0622dad --- /dev/null +++ b/prob_transporte.py @@ -0,0 +1,35 @@ +import pandas as np +from pulp import * +from pandas import DataFrame + +origen = ['LA','Detroit','New Orleans'] +destino = ['Denver','Miami'] + +oferta = {'LA': 1000, 'Detroit' : 1500, 'New Orleans': 1200} +demanda = {'Denver': 2300, 'Miami' : 1400} + +costo_envio ={'LA':{'Denver': 80, 'Miami' : 215}, + 'Detroit':{'Denver': 100, 'Miami' : 108}, + 'New Orleans': {'Denver': 102, 'Miami' : 68}} + +prob = LpProblem('Transporte', LpMinimize) + +rutas = [(i,j) for i in origen for j in destino] + +cantidad = LpVariable.dicts('Cantidad de Envio',(origen,destino),0) + +prob += lpSum(cantidad[i][j]*costo_envio[i][j] for (i,j) in rutas) + +for j in destino: + prob += lpSum(cantidad[i][j] for i in origen) == demanda[j] + +for i in origen: + prob += lpSum(cantidad[i][j] for j in destino) <= oferta[i] + +prob.solve() +print("Status:", LpStatus[prob.status]) + +for v in prob.variables(): + if v.varValue > 0: + print(v.name, "=", v.varValue) +print('El costo mínimo es:', value(prob.objective))