{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Ejercicios Guia 3.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "NcERlrTN8dcn", "outputId": "38770727-1e40-4823-b827-4c9b7c67905e" }, "source": [ "pip install pulp" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Collecting pulp\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/14/c4/0eec14a0123209c261de6ff154ef3be5cad3fd557c084f468356662e0585/PuLP-2.4-py3-none-any.whl (40.6MB)\n", "\u001b[K |████████████████████████████████| 40.6MB 1.4MB/s \n", "\u001b[?25hCollecting amply>=0.1.2\n", " Downloading https://files.pythonhosted.org/packages/f3/c5/dfa09dd2595a2ab2ab4e6fa7bebef9565812722e1980d04b0edce5032066/amply-0.1.4-py3-none-any.whl\n", "Requirement already satisfied: docutils>=0.3 in /usr/local/lib/python3.7/dist-packages (from amply>=0.1.2->pulp) (0.17)\n", "Requirement already satisfied: pyparsing in /usr/local/lib/python3.7/dist-packages (from amply>=0.1.2->pulp) (2.4.7)\n", "Installing collected packages: amply, pulp\n", "Successfully installed amply-0.1.4 pulp-2.4\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "2Ps-pwrqSpLR", "outputId": "3f8f65e8-a82d-439c-a65a-caa5d545c473" }, "source": [ "# EJERCICIO 3.1\n", "\n", "\n", "from pulp import *\n", "\n", "\n", "#definimos el modelo de programacion lienal.\n", "\n", "modelo = LpProblem(\"Maximizar Utilidad\", sense=LpMaximize)\n", "\n", "#Defino las variables \"Mayores a 0\"\n", "NF = LpVariable(\"NF\", lowBound=0, cat= 'Float')\n", "DO = LpVariable(\"DO\", lowBound=0, cat= 'Float')\n", "FO = LpVariable(\"FO\", lowBound=0, cat= 'Float')\n", "\n", "NFVNF = LpVariable(\"NFVNF\", lowBound=0, cat= 'Float')\n", "NFCNF = LpVariable(\"NFCNF\", lowBound=0, cat= 'Float')\n", "NFV = LpVariable(\"NFV\", lowBound=0, cat= 'Float')\n", "NFC = LpVariable(\"NFC\", lowBound=0, cat= 'Float')\n", "\n", "DOVDO = LpVariable(\"DOVDO\", lowBound=0, cat= 'Float')\n", "NFCDO = LpVariable(\"NFCDO\", lowBound=0, cat= 'Float')\n", "DOCDO = LpVariable(\"DOCDO\", lowBound=0, cat= 'Float')\n", "\n", "CRRFO = LpVariable(\"CRRFO\", lowBound=0, cat= 'Float')\n", "DOCFO = LpVariable(\"DOCFO\", lowBound=0, cat= 'Float')\n", "DOVFO = LpVariable(\"DOVFO\", lowBound=0, cat= 'Float')\n", "NFVFO = LpVariable(\"NFVFO\", lowBound=0, cat= 'Float')\n", "\n", "CR1 = LpVariable(\"CR1\", lowBound=0, cat= 'Float')\n", "CR2 = LpVariable(\"CR2\", lowBound=0, cat= 'Float')\n", "CR3 = LpVariable(\"CR3\", lowBound=0, cat= 'Float')\n", "\n", "NF = LpVariable(\"NF\", lowBound=0, cat= 'Float')\n", "NC = LpVariable(\"NC\", lowBound=0, cat= 'Float')\n", "DOV = LpVariable(\"DOV\", lowBound=0, cat= 'Float')\n", "DOC = LpVariable(\"DOC\", lowBound=0, cat= 'Float')\n", "CRR = LpVariable(\"CRR\", lowBound=0, cat= 'Float')\n", "GOP = LpVariable(\"GOP\", lowBound=0, cat= 'Float')\n", "\n", "CC = LpVariable(\"CC\", lowBound=0, cat= 'Float')\n", "PS = LpVariable(\"PS\", lowBound=0, cat= 'Float')\n", "\n", "#Defino la funcion objetivo\n", "\n", "modelo += (290 * NF) + (240 * DO) + (210 * FO) - (170 * CR1) - (150 * CR2) - (130 * CR3) - (10 * CC) - (5 * PS) - 200000\n", "\n", "#Defino las restricciones\n", "\n", "modelo += NFVNF + NFCNF <= NF\n", "modelo += NFVNF + NFCNF >= NF\n", "\n", "modelo += DOVDO + NFCDO + DOCDO <= DO\n", "modelo += DOVDO + NFCDO + DOCDO >= DO\n", "\n", "modelo += CRRFO + DOCFO + DOVFO + NFVFO <= FO\n", "modelo += CRRFO + DOCFO + DOVFO + NFVFO >= FO\n", "\n", "modelo += NFVNF + NFVFO <= NFV\n", "modelo += NFVNF + NFVFO >= NFV\n", "\n", "modelo += NFCNF + NFCDO <= NFC\n", "modelo += NFCNF + NFCDO >= NFC\n", "\n", "modelo += DOVDO + DOVFO <= DOV\n", "modelo += DOVDO + DOVFO >= DOV\n", "\n", "modelo += DOCDO + DOCFO <= DOC\n", "modelo += DOCDO + DOCFO >= DOC\n", "\n", "modelo += CRRFO <= CRR\n", "modelo += CRRFO >= CRR\n", "\n", "\n", "modelo += 0.23 * NFV + 0.28 * DOV + 0.4 * GOP + 0.08 * CRR>=CR1\n", "modelo += 0.15 * NFV + 0.31 * DOV + 0.35 * GOP + 0.18 * CRR>=CR2\n", "modelo += 0.03 * NFV + 0.27 * DOV + 0.27 * GOP + 0.42 * CRR>=CR3\n", "modelo += 0.23 * NFV + 0.28 * DOV + 0.4 * GOP + 0.08 * CRR<=CR1\n", "modelo += 0.15 * NFV + 0.31 * DOV + 0.35 * GOP + 0.18 * CRR<=CR2\n", "modelo += 0.03 * NFV + 0.27 * DOV + 0.27 * GOP + 0.42 * CRR<=CR3\n", "\n", "modelo += 0.25 * NFC + 0.85 * DOC <=DOV\n", "modelo += 0.25 * NFC + 0.85 * DOC >=DOV\n", "\n", "modelo += 0.55 * NFC + 0.6 * DOC >=GOP\n", "modelo += 0.55 * NFC + 0.6 * DOC <=GOP\n", "\n", "modelo += NF <= 4000\n", "modelo += DO <= 4000\n", "\n", "\n", "modelo += 59 * NFVNF + 98 * NFCNF >= 80\n", "modelo += NFCDO <= 0.1 * DO\n", "\n", "modelo += 14 * CRRFO + 52 * DOCFO + 42 * DOVFO + 60 * NFVFO >= 21\n", "\n", "modelo += CR1 + CR2 + CR3 >= PS\n", "modelo += CR1 + CR2 + CR3 <= PS\n", "modelo += PS <= 10000\n", "\n", "modelo += DOV + GOP >= CC\n", "modelo += DOV + GOP <= CC\n", "modelo += CC <= 6500\n", "\n", "modelo += CR1 <= 6000\n", "modelo += CR2 <= 6000\n", "modelo += CR3 <= 6000\n", "\n", "modelo.solve()\n", "\n", "valor_opt = value(modelo.objective)\n", "\n", "print(\"Se Producen {} BbL de NF\".format(NF.varValue))\n", "print(\"Se Producen {} BbL de DO\".format(DO.varValue))\n", "print(\"Se Producen {} BbL de FO\".format(FO.varValue))\n", "\n", "print(\"Valor Optimo: \", valor_opt)" ], "execution_count": 5, "outputs": [ { "output_type": "stream", "text": [ "Se Producen 4000.0 BbL de NF\n", "Se Producen 0.0 BbL de DO\n", "Se Producen 20390.244 BbL de FO\n", "Valor Optimo: 3594390.2613999997\n" ], "name": "stdout" }, { "output_type": "stream", "text": [ "/usr/local/lib/python3.7/dist-packages/pulp/pulp.py:1199: UserWarning: Spaces are not permitted in the name. Converted to '_'\n", " warnings.warn(\"Spaces are not permitted in the name. Converted to '_'\")\n" ], "name": "stderr" } ] } ] }