<jupyter_start><jupyter_text>----------------------------------- **Programacion Lineal con Python: Caso transporte****Universidad Tecnologica Nacional - Facultad Buenos Aires** **Ingenieria Industrial****Investigacion Operativa** Autor: <NAME> Curso I4051<jupyter_code>pip install pulp
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import pulp
from pulp import *
import scipy as sp
from scipy import optimize<jupyter_output><empty_output><jupyter_text>La funcion objetivo del problema Primal Programacion Lineal$$\text{max z } = \begin{matrix}5x_{1} + 4x_{2}  \end{matrix}$$sujeto a las restricciones$$6x_{1} + 4x_{2}  \leq 24\\x_{1} + 2x_{2}  \leq 6\\-x_{1} + x_{2}  \leq 1\\0x_{1} + x_{2}  \leq 2\\$$<jupyter_code>import pulp
# definimos si es un problema de minimizacion o maximizacion
linprog_primal = LpProblem("Primal", LpMaximize)

# definimos las variables de decision, el tipo de variable y la cota inferior
x1 = LpVariable('x1', lowBound=0, cat='Continuous')
x2 = LpVariable('x2', lowBound=0, cat='Continuous')

# primero agregamos la funcion objetivo
linprog_primal += 5*x1 + 4*x2 , "Funcion objetivo"

# luego agregamos restricciones
linprog_primal += 6*x1 + 4*x2 <= 24 , "restriccion1"
linprog_primal += x1 + 2*x2 <= 6, "restriccion2"
linprog_primal += -1*x1 + x2 <= 1, "restriccion3"
linprog_primal += 0*x1 + x2 <= 2, "restriccion4"

# Resolver el problema con el solver de PULP
linprog_primal.solve()
# valor de la funcion objetivo
value(linprog_primal.objective)
# obtenemos el valor de la variable de decision X1....X12 en el punto optimo
solucion_primal = np.array([[linprog_primal.variables()[0].varValue,
  linprog_primal.variables()[1].varValue]])
print(solucion_primal)<jupyter_output><empty_output><jupyter_text>La funcion objetivo del problema Dual Programacion Lineal$$\text{max w} = \begin{matrix}24y_{1} + 6y_{2} + y_3 + 2 y_4  \end{matrix}$$sujeto a las restricciones$$6y_{1} + y_{2} - y_3 + 0 y_4    \geq 5\\4y_{1} + 2y_{2} + y_3 +  y_4    \geq 5\\$$<jupyter_code># definimos si es un problema de minimizacion o maximizacion
linprog_dual = LpProblem("dual", LpMinimize)

# definimos las variables de decision, el tipo de variable y la cota inferior
y1 = LpVariable('y1', lowBound=0, cat='Continuous')
y2 = LpVariable('y2', lowBound=0, cat='Continuous')
y3 = LpVariable('y3', lowBound=0, cat='Continuous')
y4 = LpVariable('y4', lowBound=0, cat='Continuous')
# primero agregamos la funcion objetivo
linprog_dual += 24*y1 + 6*y2 + y3 + 2*y4, "Funcion objetivo"

# luego agregamos restricciones
linprog_dual += 6*y1 + y2 - y3 + 0*y4 >= 5 , "restriccion1_dual"
linprog_dual += 4*y1 + 2*y2 + y3 + y4 >= 4 , "restriccion2_dual"

# Resolver el problema con el solver de PULP
linprog_dual.solve()
# valor de la funcion objetivo
value(linprog_dual.objective)
# obtenemos el valor de la variable de decision X1....X12 en el punto optimo
solucion_dual = np.array([[linprog_dual.variables()[0].varValue,
                            linprog_dual.variables()[1].varValue,
                           linprog_dual.variables()[2].varValue,
                           linprog_dual.variables()[3].varValue]])
print(solucion_dual)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1368584758942457, 'fraction_numerical': 0.039502332814930013, 'mean_word_length': 4.583333333333333, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '256577', 'license': 'Apache-2.0', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1168, 'n_words': 307, 'path': '07_programacion_matematica/casos_codigo/ioperativ_clase20_linprog_primal_dual.ipynb', 'repo_name': 'juanntripaldi/pyOperativ', 'size': '3223'}