{
"cells": [
{
"cell_type": "markdown",
"id": "376dd6e5",
"metadata": {},
"source": [
"# Problema de Programación lineal con un parámetro\n",
"## 1. Calculo del 'shadow price' para una restricción"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9bc055d8",
"metadata": {
"scrolled": false
},
"outputs": [
{
"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}{lcrcrcrcrcrcrcl}\n",
" \\max \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 10 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 14 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 12 x_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 18 x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 20 x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 16 x_{6} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\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} + \\mspace{-6mu}&\\mspace{-6mu} x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{6} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 6 \\\\\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} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{6} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 8 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{5} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 6 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 3 x_{1} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 4 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 5 x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 4 x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{6} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 20 \\\\\n",
"\\end{array} \\\\\n",
"x_{1}, x_{2}, x_{3}, x_{4}, x_{5}, x_{6} \\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}}104$$"
],
"text/plain": [
"104"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,2,\\,0,\\,4,\\,0\\right)$$"
],
"text/plain": [
"(0, 0, 2, 0, 4, 0)"
]
},
"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} 6 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 8 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 6 y_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 20 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 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} 3 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 10 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 y_{3} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 4 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 14 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 12 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 5 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 18 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 4 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 20 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 y_{4} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 16 \\\\\n",
"\\end{array} \\\\\n",
"\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}}104$$"
],
"text/plain": [
"104"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\frac{47}{4},\\,\\frac{15}{4},\\,-\\frac{1}{4},\\,\\frac{1}{4}\\right)$$"
],
"text/plain": [
"(47/4, 15/4, -1/4, 1/4)"
]
},
"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|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {\\color{red}{t}}_{1} & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 6 \\\\\n",
"{\\color{red}{t}}_{2} & 1 & 1 & 0 & 3 & 2 & 1 & 0 & 1 & 0 & 0 & 8 \\\\\n",
"{\\color{red}{t}}_{3} & 1 & 2 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 6 \\\\\n",
"{\\color{red}{t}}_{4} & 3 & -4 & 2 & -5 & 4 & 2 & 0 & 0 & 0 & 1 & 20 \\\\\n",
"\\hline\n",
" {W_{ind}} & -6 & 0 & -4 & 0 & -8 & -4 & 0 & 0 & 0 & 0 & 40\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4|rhs]\n",
"[---+---------------------------------------+---]\n",
"[ t1| 1 1 1 1 1 1 1 0 0 0| 6]\n",
"[ t2| 1 1 0 3 2 1 0 1 0 0| 8]\n",
"[ t3| 1 2 1 1 1 0 0 0 1 0| 6]\n",
"[ t4| 3 -4 2 -5 4 2 0 0 0 1| 20]\n",
"[---+---------------------------------------+---]\n",
"[ W| -6 0 -4 0 -8 -4 0 0 0 0| 40]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cambio( 2 , 5 )\n"
]
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {\\color{red}{t}}_{1} & \\frac{1}{2} & \\frac{1}{2} & 1 & -\\frac{1}{2} & 0 & \\frac{1}{2} & 1 & -\\frac{1}{2} & 0 & 0 & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & \\frac{1}{2} & 0 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & \\frac{1}{2} & 0 & 0 & 4 \\\\\n",
"{\\color{red}{t}}_{3} & \\frac{1}{2} & \\frac{3}{2} & 1 & -\\frac{1}{2} & 0 & -\\frac{1}{2} & 0 & -\\frac{1}{2} & 1 & 0 & 2 \\\\\n",
"{\\color{red}{t}}_{4} & 1 & -6 & 2 & -11 & 0 & 0 & 0 & -2 & 0 & 1 & 4 \\\\\n",
"\\hline\n",
" {W_{ind}} & -2 & 4 & -4 & 12 & 0 & 0 & 0 & 4 & 0 & 0 & 8\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4| rhs]\n",
"[----+-------------------------------------------------+----]\n",
"[ t1| 1/2 1/2 1 -1/2 0 1/2 1 -1/2 0 0| 2]\n",
"[ x5| 1/2 1/2 0 3/2 1 1/2 0 1/2 0 0| 4]\n",
"[ t3| 1/2 3/2 1 -1/2 0 -1/2 0 -1/2 1 0| 2]\n",
"[ t4| 1 -6 2 -11 0 0 0 -2 0 1| 4]\n",
"[----+-------------------------------------------------+----]\n",
"[ W| -2 4 -4 12 0 0 0 4 0 0| 8]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cambio( 1 , 3 )\n"
]
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & \\frac{1}{2} & 1 & -\\frac{1}{2} & 0 & \\frac{1}{2} & 1 & -\\frac{1}{2} & 0 & 0 & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & \\frac{1}{2} & 0 & \\frac{3}{2} & 1 & \\frac{1}{2} & 0 & \\frac{1}{2} & 0 & 0 & 4 \\\\\n",
"{\\color{red}{t}}_{3} & 0 & 1 & 0 & 0 & 0 & -1 & -1 & 0 & 1 & 0 & 0 \\\\\n",
"{\\color{red}{t}}_{4} & 0 & -7 & 0 & -10 & 0 & -1 & -2 & -1 & 0 & 1 & 0 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 6 & 0 & 10 & 0 & 2 & 4 & 2 & 0 & 0 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4| rhs]\n",
"[----+-------------------------------------------------+----]\n",
"[ x3| 1/2 1/2 1 -1/2 0 1/2 1 -1/2 0 0| 2]\n",
"[ x5| 1/2 1/2 0 3/2 1 1/2 0 1/2 0 0| 4]\n",
"[ t3| 0 1 0 0 0 -1 -1 0 1 0| 0]\n",
"[ t4| 0 -7 0 -10 0 -1 -2 -1 0 1| 0]\n",
"[----+-------------------------------------------------+----]\n",
"[ W| 0 6 0 10 0 2 4 2 0 0| 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}}\\left(\\begin{array}{r|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & 0 & 1 & -\\frac{1}{2} & 0 & 1 & \\frac{3}{2} & -\\frac{1}{2} & -\\frac{1}{2} & 0 & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & 0 & 0 & \\frac{3}{2} & 1 & 1 & \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & 0 & 4 \\\\\n",
"{x}_{2} & 0 & 1 & 0 & 0 & 0 & -1 & -1 & 0 & 1 & 0 & 0 \\\\\n",
"{\\color{red}{t}}_{4} & 0 & 0 & 0 & -10 & 0 & -8 & -9 & -1 & 7 & 1 & 0 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 0 & 0 & 10 & 0 & 8 & 10 & 2 & -6 & 0 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4| rhs]\n",
"[----+-------------------------------------------------+----]\n",
"[ x3| 1/2 0 1 -1/2 0 1 3/2 -1/2 -1/2 0| 2]\n",
"[ x5| 1/2 0 0 3/2 1 1 1/2 1/2 -1/2 0| 4]\n",
"[ x2| 0 1 0 0 0 -1 -1 0 1 0| 0]\n",
"[ t4| 0 0 0 -10 0 -8 -9 -1 7 1| 0]\n",
"[----+-------------------------------------------------+----]\n",
"[ W| 0 0 0 10 0 8 10 2 -6 0| 0]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & 1 & 1 & -\\frac{1}{2} & 0 & 0 & \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & 0 & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & 1 & 0 & \\frac{3}{2} & 1 & 0 & -\\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & 0 & 4 \\\\\n",
"{x}_{6} & 0 & -1 & 0 & 0 & 0 & 1 & 1 & 0 & -1 & 0 & 0 \\\\\n",
"{\\color{red}{t}}_{4} & 0 & -8 & 0 & -10 & 0 & 0 & -1 & -1 & -1 & 1 & 0 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 8 & 0 & 10 & 0 & 0 & 2 & 2 & 2 & 0 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4| rhs]\n",
"[----+-------------------------------------------------+----]\n",
"[ x3| 1/2 1 1 -1/2 0 0 1/2 -1/2 1/2 0| 2]\n",
"[ x5| 1/2 1 0 3/2 1 0 -1/2 1/2 1/2 0| 4]\n",
"[ x6| 0 -1 0 0 0 1 1 0 -1 0| 0]\n",
"[ t4| 0 -8 0 -10 0 0 -1 -1 -1 1| 0]\n",
"[----+-------------------------------------------------+----]\n",
"[ W| 0 8 0 10 0 0 2 2 2 0| 0]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & 0 & 1 & -\\frac{7}{4} & 0 & 0 & \\frac{3}{8} & -\\frac{5}{8} & \\frac{3}{8} & \\frac{1}{8} & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & 0 & 0 & \\frac{1}{4} & 1 & 0 & -\\frac{5}{8} & \\frac{3}{8} & \\frac{3}{8} & \\frac{1}{8} & 4 \\\\\n",
"{x}_{6} & 0 & 0 & 0 & \\frac{5}{4} & 0 & 1 & \\frac{9}{8} & \\frac{1}{8} & -\\frac{7}{8} & -\\frac{1}{8} & 0 \\\\\n",
"{x}_{2} & 0 & 1 & 0 & \\frac{5}{4} & 0 & 0 & \\frac{1}{8} & \\frac{1}{8} & \\frac{1}{8} & -\\frac{1}{8} & 0 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4| rhs]\n",
"[----+-------------------------------------------------+----]\n",
"[ x3| 1/2 0 1 -7/4 0 0 3/8 -5/8 3/8 1/8| 2]\n",
"[ x5| 1/2 0 0 1/4 1 0 -5/8 3/8 3/8 1/8| 4]\n",
"[ x6| 0 0 0 5/4 0 1 9/8 1/8 -7/8 -1/8| 0]\n",
"[ x2| 0 1 0 5/4 0 0 1/8 1/8 1/8 -1/8| 0]\n",
"[----+-------------------------------------------------+----]\n",
"[ W| 0 0 0 0 0 0 1 1 1 1| 0]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & \\frac{7}{5} & 1 & 0 & 0 & 0 & \\frac{11}{20} & -\\frac{9}{20} & \\frac{11}{20} & -\\frac{1}{20} & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & -\\frac{1}{5} & 0 & 0 & 1 & 0 & -\\frac{13}{20} & \\frac{7}{20} & \\frac{7}{20} & \\frac{3}{20} & 4 \\\\\n",
"{x}_{6} & 0 & -1 & 0 & 0 & 0 & 1 & 1 & 0 & -1 & 0 & 0 \\\\\n",
"{x}_{4} & 0 & \\frac{4}{5} & 0 & 1 & 0 & 0 & \\frac{1}{10} & \\frac{1}{10} & \\frac{1}{10} & -\\frac{1}{10} & 0 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3 t4| rhs]\n",
"[------+---------------------------------------------------------------------+------]\n",
"[ x3| 1/2 7/5 1 0 0 0 11/20 -9/20 11/20 -1/20| 2]\n",
"[ x5| 1/2 -1/5 0 0 1 0 -13/20 7/20 7/20 3/20| 4]\n",
"[ x6| 0 -1 0 0 0 1 1 0 -1 0| 0]\n",
"[ x4| 0 4/5 0 1 0 0 1/10 1/10 1/10 -1/10| 0]\n",
"[------+---------------------------------------------------------------------+------]\n",
"[ W| 0 0 0 0 0 0 1 1 1 1| 0]"
]
},
"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\\ 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|rrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & \\frac{7}{5} & 1 & 0 & 0 & 0 & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & -\\frac{1}{5} & 0 & 0 & 1 & 0 & 4 \\\\\n",
"{x}_{6} & 0 & -1 & 0 & 0 & 0 & 1 & 0 \\\\\n",
"{x}_{4} & 0 & \\frac{4}{5} & 0 & 1 & 0 & 0 & 0 \\\\\n",
"\\hline\n",
" {Z_{ind}} & -6 & \\frac{14}{5} & 0 & 0 & 0 & 0 & 104\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6| rhs]\n",
"[----+-----------------------------+----]\n",
"[ x3| 1/2 7/5 1 0 0 0| 2]\n",
"[ x5| 1/2 -1/5 0 0 1 0| 4]\n",
"[ x6| 0 -1 0 0 0 1| 0]\n",
"[ x4| 0 4/5 0 1 0 0| 0]\n",
"[----+-----------------------------+----]\n",
"[ Z| -6 14/5 0 0 0 0| 104]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cambio( 4 , 2 )\n"
]
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & 0 & 1 & -\\frac{7}{4} & 0 & 0 & 2 \\\\\n",
"{x}_{5} & \\frac{1}{2} & 0 & 0 & \\frac{1}{4} & 1 & 0 & 4 \\\\\n",
"{x}_{6} & 0 & 0 & 0 & \\frac{5}{4} & 0 & 1 & 0 \\\\\n",
"{x}_{2} & 0 & 1 & 0 & \\frac{5}{4} & 0 & 0 & 0 \\\\\n",
"\\hline\n",
" {Z_{ind}} & -6 & 0 & 0 & -\\frac{7}{2} & 0 & 0 & 104\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6| rhs]\n",
"[----+-----------------------------+----]\n",
"[ x3| 1/2 0 1 -7/4 0 0| 2]\n",
"[ x5| 1/2 0 0 1/4 1 0| 4]\n",
"[ x6| 0 0 0 5/4 0 1| 0]\n",
"[ x2| 0 1 0 5/4 0 0| 0]\n",
"[----+-----------------------------+----]\n",
"[ Z| -6 0 0 -7/2 0 0| 104]"
]
},
"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=6 # número de variables x's\n",
"m=4 # número de restricciones (distintas de las de signo)\n",
"\n",
"c=matrix(QQ,1,n,[10,14,12,18,20,16] ) # vector de costos\n",
"\n",
"A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n",
"[1,1,1,1,1,1],\n",
"[1,1,0,3,2,1],\n",
"[1,2,1,1,1,0],\n",
"[3,-4,2,-5,4,2]\n",
"])\n",
"\n",
"b=matrix(QQ,m,1,[6,8,6,20]) # vector de la derecha\n",
"\n",
"\n",
"######################################################\n",
"############### VARIABLES DE HOLGURA ################\n",
"\n",
"\n",
"h=matrix(ZZ,1,m,[0,0,0,0]) # 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",
"############ HASTA AQUÍ LOS DATOS ################################\n",
"####################################################################\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"load('https://sage.unex.es/501708/simplex2023Auto.sage')\n"
]
},
{
"cell_type": "markdown",
"id": "f7f09020",
"metadata": {},
"source": [
"Calculemos el 'shadow price' para la fila 2. \n",
"\n",
"Para ello resolvemos el problema paramétrico \n",
"\n",
"$\n",
"\\mathcal{P(\\lambda)}: \\quad max \\;\\; \\text{z(x)},\\quad \\text{s.a.:} \\quad Ax=b+\\lambda b_{1p}, \\quad x\\geq 0, \\quad\n",
"$ \n",
"\n",
"para $\\lambda = 1$"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7c54b7d7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|rr}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {b} & {b_1} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{1}{2} & 0 & 1 & -\\frac{7}{4} & 0 & 0 & 2 & -\\frac{5}{8} \\\\\n",
"{x}_{5} & \\frac{1}{2} & 0 & 0 & \\frac{1}{4} & 1 & 0 & 4 & \\frac{3}{8} \\\\\n",
"{x}_{6} & 0 & 0 & 0 & \\frac{5}{4} & 0 & 1 & 0 & \\frac{1}{8} \\\\\n",
"{x}_{2} & 0 & 1 & 0 & \\frac{5}{4} & 0 & 0 & 0 & \\frac{1}{8} \\\\\n",
"\\hline\n",
" {Z_{ind}} & -6 & 0 & 0 & -\\frac{7}{2} & 0 & 0 & 104 & \\frac{15}{4}\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6| rhs rhs1]\n",
"[----+-----------------------------+---------]\n",
"[ x3| 1/2 0 1 -7/4 0 0| 2 -5/8]\n",
"[ x5| 1/2 0 0 1/4 1 0| 4 3/8]\n",
"[ x6| 0 0 0 5/4 0 1| 0 1/8]\n",
"[ x2| 0 1 0 5/4 0 0| 0 1/8]\n",
"[----+-----------------------------+---------]\n",
"[ Z| -6 0 0 -7/2 0 0| 104 15/4]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"b1p=matrix(QQ,m,1,[0,1,0,0]); param1b(b1p) "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2ab231ca",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[ NO NO NO 2.0000 NO NO]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cocientesD(1)"
]
},
{
"cell_type": "markdown",
"id": "7b6d065e",
"metadata": {},
"source": [
"¿Para qué valores del parámetro $\\lambda$ es este cuadro óptimo?"
]
},
{
"cell_type": "markdown",
"id": "81e1cb96",
"metadata": {},
"source": [
"Resolvamos el sistema de inecuaciones: \n",
"$$\n",
"2 - 5/8\\lambda \\geq 0 \\\\\n",
"4 + 3/8\\lambda \\geq 0 \\\\\n",
"0 + 1/8\\lambda \\geq 0 \\\\\n",
"0 + 1/8\\lambda \\geq 0 \n",
"$$\n",
"\n",
"Su solución es $\\lambda\\in [0,16/5].$ Por tanto, el cuadro es óptimo para los valores de $\\lambda$ en dicho intervalo. "
]
},
{
"cell_type": "markdown",
"id": "50d123b2",
"metadata": {},
"source": [
"En particular, este cuadro es óptimo para el problema $\\mathcal{\\lambda = 1}.$ El valor de la función objetivo óptima es $104+15/4\\lambda$, con $\\lambda =1.$ Si la función objetivo $z$ representa un beneficio, la mejora al aumentar $b_2$ de 8 a 9 es 15/4. Ese es el \"precio en la sombra\" para esta línea 2. "
]
},
{
"cell_type": "markdown",
"id": "6688aeff",
"metadata": {},
"source": [
"Si quisiéramos resolver problemas $\\mathcal{P}(\\lambda)$ para valores del parámetro a la derecha de 16/5, tendríamos que utilizar el método símplex dual. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c48a9e2e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {b} \\\\\n",
"\\hline\n",
" {x}_{4} & -\\frac{2}{7} & 0 & -\\frac{4}{7} & 1 & 0 & 0 & -\\frac{8}{7} \\\\\n",
"{x}_{5} & \\frac{4}{7} & 0 & \\frac{1}{7} & 0 & 1 & 0 & \\frac{30}{7} \\\\\n",
"{x}_{6} & \\frac{5}{14} & 0 & \\frac{5}{7} & 0 & 0 & 1 & \\frac{10}{7} \\\\\n",
"{x}_{2} & \\frac{5}{14} & 1 & \\frac{5}{7} & 0 & 0 & 0 & \\frac{10}{7} \\\\\n",
"\\hline\n",
" {Z_{ind}} & -7 & 0 & -2 & 0 & 0 & 0 & 108\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6| rhs]\n",
"[----+-----------------------------+----]\n",
"[ x4|-2/7 0 -4/7 1 0 0|-8/7]\n",
"[ x5| 4/7 0 1/7 0 1 0|30/7]\n",
"[ x6|5/14 0 5/7 0 0 1|10/7]\n",
"[ x2|5/14 1 5/7 0 0 0|10/7]\n",
"[----+-----------------------------+----]\n",
"[ Z| -7 0 -2 0 0 0| 108]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(1,4)"
]
},
{
"cell_type": "markdown",
"id": "7baad470",
"metadata": {},
"source": [
"Resolviendo un siguiente sistema de inecuaciones obtenido de manera similar al alterior, encontraremos los valores del parámetro \\lambda para los que ese cuadro es óptimo."
]
},
{
"cell_type": "markdown",
"id": "c75199c6",
"metadata": {},
"source": [
"etc"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed732fbe",
"metadata": {},
"outputs": [],
"source": []
}
],
"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": 5
}