Skip to content

Commit

Permalink
Create prob_transporte.py
Browse files Browse the repository at this point in the history
  • Loading branch information
VikSanz authored Aug 28, 2020
1 parent 81d4b51 commit 91fb3cf
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions prob_transporte.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 91fb3cf

Please sign in to comment.