{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/lib/python3/dist-packages/sage/misc/remote_file.py:46: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated.\n", " content = urlopen(req, timeout=1, context=SSLContext())\n", "/usr/lib/python3/dist-packages/sage/misc/remote_file.py:46: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated\n", " content = urlopen(req, timeout=1, context=SSLContext())\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n", "\\begin{array}{lcrcrcrcl}\n", " \\max \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 8 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 16 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 9 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 4 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 6 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 148 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{2} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 23 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 28 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 4 \\\\\n", "\\end{array} \\\\\n", "x_{1}, x_{2}, x_{3} \\geq 0\n", "\\end{array}$$" ], "text/plain": [ "LP problem (use 'view(...)' or '%display typeset' for details)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}395$$" ], "text/plain": [ "395" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(4,\\,21,\\,3\\right)$$" ], "text/plain": [ "(4, 21, 3)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$" ], "text/plain": [ "salto" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}$$" ], "text/plain": [ "dual" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n", "\\begin{array}{lcrcrcrcrcl}\n", " \\min \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 148 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 23 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 28 y_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 4 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 4 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 8 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 6 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{2} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 16 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 2 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 9 \\\\\n", "\\end{array} \\\\\n", "y_{1} \\geq 0,\\ y_{2} \\geq 0,\\ y_{3} \\geq 0,\\ y_{4} \\leq 0\n", "\\end{array}$$" ], "text/plain": [ "LP problem (use 'view(...)' or '%display typeset' for details)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}395$$" ], "text/plain": [ "395" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\frac{7}{4},\\,0,\\,\\frac{11}{2},\\,-\\frac{9}{2}\\right)$$" ], "text/plain": [ "(7/4, 0, 11/2, -9/2)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$" ], "text/plain": [ "salto" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\ \\ \\ Fase\\ I}$$" ], "text/plain": [ "FI" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {\\color{red}{t}}_{4} & {b} \\\\\n", "\\hline\n", " {\\color{green}{s}}_{1} & 4 & 6 & 2 & 1 & 0 & 0 & 0 & 0 & 148 \\\\\n", "{\\color{green}{s}}_{2} & 1 & \\frac{1}{2} & 1 & 0 & 1 & 0 & 0 & 0 & 23 \\\\\n", "{\\color{green}{s}}_{3} & 1 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 28 \\\\\n", "{\\color{red}{t}}_{4} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & 4 \\\\\n", "\\hline\n", " {W_{ind}} & -1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 4\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4 t4|rhs]\n", "[---+-------------------------------+---]\n", "[ s1| 4 6 2 1 0 0 0 0|148]\n", "[ s2| 1 1/2 1 0 1 0 0 0| 23]\n", "[ s3| 1 1 1 0 0 1 0 0| 28]\n", "[ t4| 1 0 0 0 0 0 -1 1| 4]\n", "[---+-------------------------------+---]\n", "[ W| -1 0 0 0 0 0 1 0| 4]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "cambio( 4 , 1 )\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {\\color{red}{t}}_{4} & {b} \\\\\n", "\\hline\n", " {\\color{green}{s}}_{1} & 0 & 6 & 2 & 1 & 0 & 0 & 4 & -4 & 132 \\\\\n", "{\\color{green}{s}}_{2} & 0 & \\frac{1}{2} & 1 & 0 & 1 & 0 & 1 & -1 & 19 \\\\\n", "{\\color{green}{s}}_{3} & 0 & 1 & 1 & 0 & 0 & 1 & 1 & -1 & 24 \\\\\n", "{x}_{1} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 1 & 4 \\\\\n", "\\hline\n", " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4 t4|rhs]\n", "[---+-------------------------------+---]\n", "[ s1| 0 6 2 1 0 0 4 -4|132]\n", "[ s2| 0 1/2 1 0 1 0 1 -1| 19]\n", "[ s3| 0 1 1 0 0 1 1 -1| 24]\n", "[ x1| 1 0 0 0 0 0 -1 1| 4]\n", "[---+-------------------------------+---]\n", "[ W| 0 0 0 0 0 0 0 1| 0]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "El problema de la fase I es óptimo y Wopt=0. Por tanto, el original es factible\n", "Preparemos el cuadro inicial de la fase II\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\ \\ \\ Fase\\ II}$$" ], "text/plain": [ "FII" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} \\\\\n", "\\hline\n", " {\\color{green}{s}}_{1} & 0 & 6 & 2 & 1 & 0 & 0 & 4 & 132 \\\\\n", "{\\color{green}{s}}_{2} & 0 & \\frac{1}{2} & 1 & 0 & 1 & 0 & 1 & 19 \\\\\n", "{\\color{green}{s}}_{3} & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 24 \\\\\n", "{x}_{1} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 4 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & 16 & 9 & 0 & 0 & 0 & 8 & 32\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4|rhs]\n", "[---+---------------------------+---]\n", "[ s1| 0 6 2 1 0 0 4|132]\n", "[ s2| 0 1/2 1 0 1 0 1| 19]\n", "[ s3| 0 1 1 0 0 1 1| 24]\n", "[ x1| 1 0 0 0 0 0 -1| 4]\n", "[---+---------------------------+---]\n", "[ Z| 0 16 9 0 0 0 8| 32]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "cambio( 1 , 2 )\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} \\\\\n", "\\hline\n", " {x}_{2} & 0 & 1 & \\frac{1}{3} & \\frac{1}{6} & 0 & 0 & \\frac{2}{3} & 22 \\\\\n", "{\\color{green}{s}}_{2} & 0 & 0 & \\frac{5}{6} & -\\frac{1}{12} & 1 & 0 & \\frac{2}{3} & 8 \\\\\n", "{\\color{green}{s}}_{3} & 0 & 0 & \\frac{2}{3} & -\\frac{1}{6} & 0 & 1 & \\frac{1}{3} & 2 \\\\\n", "{x}_{1} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 4 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & 0 & \\frac{11}{3} & -\\frac{8}{3} & 0 & 0 & -\\frac{8}{3} & 384\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4| rhs]\n", "[-----+-----------------------------------------+-----]\n", "[ x2| 0 1 1/3 1/6 0 0 2/3| 22]\n", "[ s2| 0 0 5/6 -1/12 1 0 2/3| 8]\n", "[ s3| 0 0 2/3 -1/6 0 1 1/3| 2]\n", "[ x1| 1 0 0 0 0 0 -1| 4]\n", "[-----+-----------------------------------------+-----]\n", "[ Z| 0 0 11/3 -8/3 0 0 -8/3| 384]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "cambio( 3 , 3 )\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} \\\\\n", "\\hline\n", " {x}_{2} & 0 & 1 & 0 & \\frac{1}{4} & 0 & -\\frac{1}{2} & \\frac{1}{2} & 21 \\\\\n", "{\\color{green}{s}}_{2} & 0 & 0 & 0 & \\frac{1}{8} & 1 & -\\frac{5}{4} & \\frac{1}{4} & \\frac{11}{2} \\\\\n", "{x}_{3} & 0 & 0 & 1 & -\\frac{1}{4} & 0 & \\frac{3}{2} & \\frac{1}{2} & 3 \\\\\n", "{x}_{1} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 4 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & 0 & 0 & -\\frac{7}{4} & 0 & -\\frac{11}{2} & -\\frac{9}{2} & 395\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4| rhs]\n", "[-----+-----------------------------------------+-----]\n", "[ x2| 0 1 0 1/4 0 -1/2 1/2| 21]\n", "[ s2| 0 0 0 1/8 1 -5/4 1/4| 11/2]\n", "[ x3| 0 0 1 -1/4 0 3/2 1/2| 3]\n", "[ x1| 1 0 0 0 0 0 -1| 4]\n", "[-----+-----------------------------------------+-----]\n", "[ Z| 0 0 0 -7/4 0 -11/2 -9/2| 395]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "El problema es óptimo\n" ] } ], "source": [ "tipo='max' # max o min\n", "\n", "n=3 # número de variables x's\n", "m=4 # número de restricciones (distintas de las de signo)\n", "\n", "cMP=matrix(QQ,1,m,[1.5,2,4,0] ) # coste de las materias primas\n", "\n", "\n", "A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n", "[4, 6, 2],\n", "[1, 0.5, 1],\n", "[1, 1, 1],\n", "[1,0,0]\n", "])\n", "\n", "cf=cMP*A # coste de cada unidad de producto fabricada\n", "\n", "\n", "venta=matrix(QQ,1,n,[20,30,18]) # precio de venta\n", "\n", "c=venta-cf # vector de costos (beneficio en este caso)\n", "\n", "\n", "b=matrix(QQ,m,1,[148,23,28,4]) # vector de la derecha\n", "\n", "\n", "############### VARIABLES DE HOLGURA ################\n", "\n", "\n", "h=matrix(ZZ,1,m,[1,1,1,-1]) # variables de holgura: \n", " # Pon 1 si va sumando, \n", " # -1 si va restando y \n", " # 0 si no hay variable de holgura.\n", "\n", "#######################################################\n", "\n", "\n", "\n", "load('https://sage.unex.es/501708/simplex2023Auto.sage')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculando el 'shadow price' de la línea 1 (Harina)\n", "Suponemos que $\\lambda$ es el parámetro." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "#b1p=matrix(QQ,m,1,[0,1,0,0]); param1b(b1p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Para $\\lambda=1$, este cuadro es óptimo. Por tanto, 7/4 sería el precio máximo que pagaríamos por un por un kg adicional de harina. " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "#cambio(3,4)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "#cocientesD(3)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "#b1p=matrix(QQ,m,1,[0,0,1,0]); param1b(b1p)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "#cocientesD(2)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "#cambio(2,6)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "24.2000000000000" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2096/5. - 395" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculando los 'shadow prices' de dos líneas simultáneamente:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|rrr}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} & {b_1} & {b_2} \\\\\n", "\\hline\n", " {x}_{2} & 0 & 1 & 0 & \\frac{1}{4} & 0 & -\\frac{1}{2} & \\frac{1}{2} & 21 & \\frac{1}{4} & 0 \\\\\n", "{\\color{green}{s}}_{2} & 0 & 0 & 0 & \\frac{1}{8} & 1 & -\\frac{5}{4} & \\frac{1}{4} & \\frac{11}{2} & \\frac{1}{8} & 1 \\\\\n", "{x}_{3} & 0 & 0 & 1 & -\\frac{1}{4} & 0 & \\frac{3}{2} & \\frac{1}{2} & 3 & -\\frac{1}{4} & 0 \\\\\n", "{x}_{1} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 4 & 0 & 0 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & 0 & 0 & -\\frac{7}{4} & 0 & -\\frac{11}{2} & -\\frac{9}{2} & 395 & \\frac{7}{4} & 0\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4| rhs rhs1 rhs2]\n", "[-----+-----------------------------------------+-----------------]\n", "[ x2| 0 1 0 1/4 0 -1/2 1/2| 21 1/4 0]\n", "[ s2| 0 0 0 1/8 1 -5/4 1/4| 11/2 1/8 1]\n", "[ x3| 0 0 1 -1/4 0 3/2 1/2| 3 -1/4 0]\n", "[ x1| 1 0 0 0 0 0 -1| 4 0 0]\n", "[-----+-----------------------------------------+-----------------]\n", "[ Z| 0 0 0 -7/4 0 -11/2 -9/2| 395 7/4 0]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "b1p=matrix(QQ,m,1,[1,0,0,0]); b2p=matrix(QQ,m,1,[0,1,0,0]); param2b(b1p,b2p)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|rrrr}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} & {b_1} & {b_2} & {b_1} \\\\\n", "\\hline\n", " {x}_{2} & 0 & 1 & 0 & \\frac{1}{4} & 0 & -\\frac{1}{2} & \\frac{1}{2} & 21 & \\frac{1}{4} & 0 & -\\frac{1}{2} \\\\\n", "{\\color{green}{s}}_{2} & 0 & 0 & 0 & \\frac{1}{8} & 1 & -\\frac{5}{4} & \\frac{1}{4} & \\frac{11}{2} & \\frac{1}{8} & 1 & -\\frac{5}{4} \\\\\n", "{x}_{3} & 0 & 0 & 1 & -\\frac{1}{4} & 0 & \\frac{3}{2} & \\frac{1}{2} & 3 & -\\frac{1}{4} & 0 & \\frac{3}{2} \\\\\n", "{x}_{1} & 1 & 0 & 0 & 0 & 0 & 0 & -1 & 4 & 0 & 0 & 0 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & 0 & 0 & -\\frac{7}{4} & 0 & -\\frac{11}{2} & -\\frac{9}{2} & 395 & \\frac{7}{4} & 0 & \\frac{11}{2}\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4| rhs rhs1 rhs2 rhs1]\n", "[-----+-----------------------------------------+-----------------------]\n", "[ x2| 0 1 0 1/4 0 -1/2 1/2| 21 1/4 0 -1/2]\n", "[ s2| 0 0 0 1/8 1 -5/4 1/4| 11/2 1/8 1 -5/4]\n", "[ x3| 0 0 1 -1/4 0 3/2 1/2| 3 -1/4 0 3/2]\n", "[ x1| 1 0 0 0 0 0 -1| 4 0 0 0]\n", "[-----+-----------------------------------------+-----------------------]\n", "[ Z| 0 0 0 -7/4 0 -11/2 -9/2| 395 7/4 0 11/2]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "b3p=matrix(QQ,m,1,[0,0,1,0]);param1b(b3p)" ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.5", "language": "sage", "name": "sagemath" }, "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.11.2" } }, "nbformat": 4, "nbformat_minor": 4 }