You are on page 1of 2

Examen Problema 1

July 13, 2021

1 Librerias
[1]: # pulp Libreria por excelencia en programacion lineal
from pulp import *

[2]: #Creando el modelo


model = LpProblem(name="ExamenP1", sense=LpMinimize)

[3]: # Definiendo variables


x1 = LpVariable(name="x1", lowBound=0,cat='Binary')
x2 = LpVariable(name="x2", lowBound=0,cat='Binary')
x3 = LpVariable(name="x3", lowBound=0,cat='Binary')
x4 = LpVariable(name="x4", lowBound=0,cat='Binary')
x5 = LpVariable(name="x5", lowBound=0,cat='Binary')
x6 = LpVariable(name="x6", lowBound=0,cat='Binary')

[4]: # Agregando las restricciones


model += ( x1+x2 >=1 , "Res1")
model += ( x1+x2+x6 >=1 ,"Res2")
model += ( x3+x4 >=1 , "Res3")
model += ( x3+x4+x5 >=1 , "Res4")
model += ( x4+x5+x6 >=1 , "Res5")
model += ( x2+x5+x6 >=1 , "Res6")

[5]: # Definiendo la funcion objetivo


model += ( x1+x2+x3+x4+x5+x6 , "Res1")

[6]: # Verificacion del modelo Introducido


model

[6]: ExamenP1:
MINIMIZE
1*x1 + 1*x2 + 1*x3 + 1*x4 + 1*x5 + 1*x6 + 0
SUBJECT TO
Res1: x1 + x2 >= 1

Res2: x1 + x2 + x6 >= 1

1
Res3: x3 + x4 >= 1

Res4: x3 + x4 + x5 >= 1

Res5: x4 + x5 + x6 >= 1

Res6: x2 + x5 + x6 >= 1

VARIABLES
0 <= x1 <= 1 Integer
0 <= x2 <= 1 Integer
0 <= x3 <= 1 Integer
0 <= x4 <= 1 Integer
0 <= x5 <= 1 Integer
0 <= x6 <= 1 Integer

[7]: # Resolviendo el problema


status = model.solve(solver=GLPK(msg=False))
print(f"status: {model.status}, {LpStatus[model.status]}")
print(f"objective: {model.objective.value()}")
for var in model.variables():
print(f"{var.name}: {var.value()}")
for name, constraint in model.constraints.items():
print(f"{name}: {constraint.value()}")

status: 1, Optimal
objective: 2
x1: 0
x2: 1
x3: 0
x4: 1
x5: 0
x6: 0
Res1: 0
Res2: 0
Res3: 0
Res4: 0
Res5: 0
Res6: 0

[ ]:

You might also like