{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "fbbcdb39", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "status:1,Optimal\n", "objective:903543.2259999998\n", "CR1PS:0.0\n", "CR2PS:6000.0\n", "CR3PS:4000.0\n", "CRRFO:2760.0\n", "CRTPS:10000.0\n", "DC:3783.7742\n", "DOCDC:3783.7742\n", "DOCFO:623.22581\n", "DOCTOT:4407.0\n", "DOVCC:2940.0\n", "DOVDC:0.0\n", "DOVFO:0.0\n", "DOVTOT:2940.0\n", "FO:3383.2258\n", "GOPCC:3180.0\n", "NF:3504.0\n", "NFCDC:0.0\n", "NFCNF:2484.0\n", "NFCTOT:2484.0\n", "NFVFO:0.0\n", "NFVNF:1020.0\n", "NFVTOT:1020.0\n", "TOTCC:6120.0\n", "BAL_CRUDO:0.0\n", "BAL_CRACK:0.0\n", "BAL_NFV:0.0\n", "BAL_DOV:0.0\n", "BAL_NFC:0.0\n", "BAL_DOC:9.999999747378752e-06\n", "BAL_NAFTA:0.0\n", "BAL_DIESEL:0.0\n", "BAL_FUEL:9.99999986106559e-06\n", "DISP_C1:-6000.0\n", "DISP_C2:0.0\n", "DISP_C3:-2000.0\n", "CAPACIDAD_PS:0.0\n", "CAPACIDAD_CC:-380.0\n", "REND_NFV:0.0\n", "REND_DOV:0.0\n", "REND_GOP:0.0\n", "REND_CRR:0.0\n", "REND_NFC:2.2737367544323206e-13\n", "REND_DOC:0.0\n", "DEM_NF:-496.0\n", "DEM_DC:-216.22580000000016\n", "ESP_NAFTA:23292.0\n", "ESP_DIESEL:-378.37742000000003\n", "ESP_FUEL:0.00031999999919207767\n" ] } ], "source": [ "#EJERCICIO 3.1\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=\"Destileria\", sense=LpMaximize)\n", "\n", "#Inicializo las variables\n", "CR1PS=LpVariable(name=\"CR1PS\", lowBound=0)\n", "CR2PS=LpVariable(name=\"CR2PS\", lowBound=0)\n", "CR3PS=LpVariable(name=\"CR3PS\", lowBound=0)\n", "CRTPS=LpVariable(name=\"CRTPS\", lowBound=0)\n", "NFVNF=LpVariable(name=\"NFVNF\", lowBound=0)\n", "NFVFO=LpVariable(name=\"NFVFO\", lowBound=0)\n", "NFVTOT=LpVariable(name=\"NFVTOT\", lowBound=0)\n", "DOVCC=LpVariable(name=\"DOVCC\", lowBound=0)\n", "DOVDC=LpVariable(name=\"DOVDC\", lowBound=0)\n", "DOVFO=LpVariable(name=\"DOVFO\", lowBound=0)\n", "DOVTOT=LpVariable(name=\"DOVTOT\", lowBound=0)\n", "GOPCC=LpVariable(name=\"GOPCC\", lowBound=0)\n", "CRRFO=LpVariable(name=\"CRRFO\", lowBound=0)\n", "TOTCC=LpVariable(name=\"TOTCC\", lowBound=0)\n", "NFCTOT=LpVariable(name=\"NFCTOT\", lowBound=0)\n", "NFCNF=LpVariable(name=\"NFCNF\", lowBound=0)\n", "NFCDC=LpVariable(name=\"NFCDC\", lowBound=0)\n", "DOCTOT=LpVariable(name=\"DOCTOT\", lowBound=0)\n", "DOCDC=LpVariable(name=\"DOCDC\", lowBound=0)\n", "DOCFO=LpVariable(name=\"DOCFO\", lowBound=0)\n", "NF=LpVariable(name=\"NF\", lowBound=0)\n", "DC=LpVariable(name=\"DC\", lowBound=0)\n", "FO=LpVariable(name=\"FO\", lowBound=0)\n", "\n", "#Determino las restricciones\n", "#BALANCES\n", "model+= (CR1PS+CR2PS+CR3PS-CRTPS== 0, \"BAL_CRUDO\")\n", "model+= (DOVCC+GOPCC-TOTCC== 0, \"BAL_CRACK\")\n", "model+= (-NFVTOT+NFVNF+NFVFO== 0, \"BAL_NFV\")\n", "model+= (-DOVTOT+DOVCC+DOVDC+DOVFO== 0, \"BAL_DOV\")\n", "model+= (-NFCTOT+NFCNF+NFCDC== 0, \"BAL_NFC\")\n", "model+= (-DOCTOT+DOCFO+DOCDC== 0, \"BAL_DOC\")\n", "model+= (-NF+NFVNF+NFCNF== 0, \"BAL_NAFTA\")\n", "model+= (-DC+DOVDC+NFCDC+DOCDC== 0, \"BAL_DIESEL\")\n", "model+= (-FO+CRRFO+DOCFO+NFVFO+DOVFO== 0, \"BAL_FUEL\")\n", "#DISPONIBILIDAD CRUDOS\n", "model+= (CR1PS<= 6000, \"DISP_C1\")\n", "model+= (CR2PS<= 6000, \"DISP_C2\")\n", "model+= (CR3PS<= 6000, \"DISP_C3\")\n", "#CAPACIDADES\n", "model+= (CRTPS<= 10000, \"CAPACIDAD_PS\")\n", "model+= (TOTCC<= 6500, \"CAPACIDAD_CC\")\n", "#RENDIMIENTO PIPESTILL\n", "model+= (-NFVTOT+CR1PS*0.23+CR2PS*0.15+CR3PS*0.03== 0, \"REND_NFV\")\n", "model+= (-DOVTOT+CR1PS*0.28+CR2PS*0.31+CR3PS*0.27== 0, \"REND_DOV\")\n", "model+= (-GOPCC+CR1PS*0.4+CR2PS*0.35+CR3PS*0.27== 0, \"REND_GOP\")\n", "model+= (-CRRFO+CR1PS*0.08+CR2PS*0.18+CR3PS*0.42== 0, \"REND_CRR\")\n", "# RENDIMIENTO CRACKING\n", "model+= (-NFCTOT+DOVCC*0.25+GOPCC*0.55== 0, \"REND_NFC\")\n", "model+= (-DOCTOT+DOVCC*0.85+GOPCC*0.6== 0, \"REND_DOC\")\n", "#DEMANDA\n", "model+= (NF<= 4000, \"DEM_NF\")\n", "model+= (DC<= 4000, \"DEM_DC\")\n", "#ESPECIFICACIONES NAFTA COMERCIAL\n", "model+= (-80*NF+59*NFVNF+98*NFCNF>= 0, \"ESP_NAFTA\")\n", "#ESPECIFICACIONES DIESEL COMERCIAL\n", "model+= (-DC*0.1+NFCDC<= 0, \"ESP_DIESEL\")\n", "#ESPECIFICACIONES FUEL OIL COMERCIAL\n", "model+= (-21*FO+14*CRRFO+52*DOCFO+42*NFVFO+60*DOVFO>= 0, \"ESP_FUEL\")\n", "\n", "model+= NF*290+DC*240+FO*210-CR1PS*170-CR2PS*150-CR3PS*130-CRTPS*5-TOTCC*10-200000\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 }