{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "a77756a7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "status:1,Optimal\n", "objective:17400000.0\n", "A:4000.0\n", "AC:0.0\n", "AP:4000.0\n", "B:3000.0\n", "BC:0.0\n", "BP:3000.0\n", "C:8000.0\n", "CC:0.0\n", "CP:8000.0\n", "D:5000.0\n", "DC:5000.0\n", "DP:0.0\n", "Estampado:-450.0\n", "Armado:-1720.0\n", "Cableado:-1050.0\n", "Ajuste:-1777.77778348\n", "Control:-2294.44444812\n", "Bal_A:0.0\n", "Bal_B:0.0\n", "Bal_C:0.0\n", "Bal_D:0.0\n", "Nec_A:0.0\n", "Nec_B:0.0\n", "Nec_C:0.0\n", "Nec_D:0.0\n" ] } ], "source": [ "#EJERCICIO 2.5\n", "#importo librerias \n", "from pulp import LpMaximize, LpProblem, LpStatus, lpSum, LpVariable, LpMinimize\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from scipy.optimize import linprog\n", "import numpy as np\n", "\n", "#Creo el modelo\n", "model= LpProblem (name=\"Tableros_autos\", sense=LpMinimize)\n", "\n", "#Inicializo las variables\n", "A=LpVariable(name=\"A\", lowBound=0)\n", "AP=LpVariable(name=\"AP\", lowBound=0)\n", "AC=LpVariable(name=\"AC\", lowBound=0)\n", "B=LpVariable(name=\"B\", lowBound=0)\n", "BP=LpVariable(name=\"BP\", lowBound=0)\n", "BC=LpVariable(name=\"BC\", lowBound=0)\n", "C=LpVariable(name=\"C\", lowBound=0)\n", "CP=LpVariable(name=\"CP\", lowBound=0)\n", "CC=LpVariable(name=\"CC\", lowBound=0)\n", "D=LpVariable(name=\"D\", lowBound=0)\n", "DP=LpVariable(name=\"DP\", lowBound=0)\n", "DC=LpVariable(name=\"DC\", lowBound=0)\n", "\n", "model+= (0.05*AP + 0.05*BP + 0.05*CP + 0.05*DP<=1200,\"Estampado\")\n", "model+= (0.1*AP + 0.12*BP + 0.14*CP + 0.18*DP<=3600,\"Armado\")\n", "model+= (0.2*AP + 0.25*BP + 0.3*CP + 0.25*DP<=5000,\"Cableado\")\n", "model+= (0.08888888888*AP + 0.111111111*BP + 0.066666666*CP + 0.11111111111*DP<=3000,\"Ajuste\")\n", "model+= (0.02222222222*AP + 0.033333333*BP + 0.033333333*CP + 0.04444444444*DP \n", " + 0.0375* AC + 0.0625* BC + 0.05* CC +0.05*DC<=3000,\"Control\")\n", "model+= (-A+AP+AC==0,\"Bal_A\")\n", "model+= (-B+BP+BC==0,\"Bal_B\")\n", "model+= (-C+CP+CC==0,\"Bal_C\")\n", "model+= (-D+DP+DC==0,\"Bal_D\")\n", "model+= (A==4000,\"Nec_A\")\n", "model+= (B==3000,\"Nec_B\")\n", "model+= (C==8000,\"Nec_C\")\n", "model+= (D==5000,\"Nec_D\")\n", "\n", "model+= 500*AP + 600*BP + 1200*CP + 1000*DP + 800*AC +750*BC + 1800*CC + 800*DC\n", "\n", "#Resolvemos el problema de programacion lineal\n", "status = model.solve()\n", "\n", "#Imprimo la solucion\n", "print(f\"status:{model.status},{LpStatus[model.status]}\")#tipo de solucion\n", "print(f\"objective:{model.objective.value()}\")#Beneficio maximo sujeto a las restricciones\n", "for var in model.variables():\n", " print(f\"{var.name}:{var.value()}\")#Valores de solucion de las variables\n", "for name, constraint in model.constraints.items():\n", " print(f\"{name}:{constraint.value()}\") " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 5 }