{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": false
   },
   "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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\max \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\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}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       "\\end{array} \\\\\n",
       "x_{1}, x_{2}, x_{3} \\geq 0\n",
       "\\end{array}</script></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} \\frac{1}{100} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\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}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}1</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(1,\\,\\frac{9}{10},\\,\\frac{9}{10}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(1,\\,\\frac{9}{10},\\,\\frac{9}{10}\\right)$$"
      ],
      "text/plain": [
       "(1, 9/10, 9/10)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}$$"
      ],
      "text/plain": [
       "dual"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\min \\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} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2}, y_{3} \\geq 0\n",
       "\\end{array}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\min \\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} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{100} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{10} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2}, y_{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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}1</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,1\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,1\\right)$$"
      ],
      "text/plain": [
       "(0, 0, 1)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{2} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{3} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{2} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{3} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[    B|   x1    x2    x3    s1    s2    s3|  rhs]\n",
       "[-----+-----------------------------------+-----]\n",
       "[   s1|    1     0     0     1     0     0|    1]\n",
       "[   s2| 1/10     1     0     0     1     0|    1]\n",
       "[   s3|1/100  1/10     1     0     0     1|    1]\n",
       "[-----+-----------------------------------+-----]\n",
       "[    Z|1/100  1/10     1     0     0     0|    0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 3 , 3 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{2} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n",
       "{x}_{3} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & -1 & 1\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{2} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n",
       "{x}_{3} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & -1 & 1\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[    B|   x1    x2    x3    s1    s2    s3|  rhs]\n",
       "[-----+-----------------------------------+-----]\n",
       "[   s1|    1     0     0     1     0     0|    1]\n",
       "[   s2| 1/10     1     0     0     1     0|    1]\n",
       "[   x3|1/100  1/10     1     0     0     1|    1]\n",
       "[-----+-----------------------------------+-----]\n",
       "[    Z|    0     0     0     0     0    -1|    1]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "El problema es óptimo\n"
     ]
    }
   ],
   "source": [
    "tipo='max'     #   Problema de tipo max o min\n",
    "\n",
    "n=3 #  número de variables x's\n",
    "m=3 #  número de restricciones (distintas de las de signo)\n",
    "\n",
    "c=matrix(QQ,1,n,[1/100,1/10,1] )  # vector de costos\n",
    "\n",
    "A=matrix(QQ,m,n,[   # coeficientes de las variables x's\n",
    "[1,0,0],\n",
    "[1/10,1,0],\n",
    "[1/100, 1/10, 1]\n",
    "])\n",
    "\n",
    "b=matrix(QQ,m,1,[1,1,1])  # vector de la derecha\n",
    "\n",
    "\n",
    "h=matrix(ZZ,1,m,[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",
    "t=matrix(ZZ,1,m,[0,0,0])   # variables artificiales: \n",
    "                             # pon 1 si utilizas variable artificial en la fila i-ésima\n",
    "                             #     0 si no utilizas variable artificial en la fila i-ésima\n",
    "\n",
    "colId=(4,5,6) # posición de la matriz identidad\n",
    "\n",
    "\n",
    "    \n",
    "    \n",
    "####################################################################\n",
    "############  HASTA AQUÍ LOS DATOS  ################################\n",
    "####################################################################\n",
    "\n",
    "\n",
    "load('https://sage.unex.es/501708/simplex2023Auto.sage')\n",
    "\n",
    "#load('https://sage.unex.es/501708/simplex2023CompletamenteManual.sage')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{2} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n",
       "{x}_{3} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & -1 & 1\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\\\\n",
       "{\\color{green}{s}}_{2} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 0 & 1 \\\\\n",
       "{x}_{3} & \\frac{1}{100} & \\frac{1}{10} & 1 & 0 & 0 & 1 & 1 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & -1 & 1\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[    B|   x1    x2    x3    s1    s2    s3|  rhs]\n",
       "[-----+-----------------------------------+-----]\n",
       "[   s1|    1     0     0     1     0     0|    1]\n",
       "[   s2| 1/10     1     0     0     1     0|    1]\n",
       "[   x3|1/100  1/10     1     0     0     1|    1]\n",
       "[-----+-----------------------------------+-----]\n",
       "[    Z|    0     0     0     0     0    -1|    1]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cambio(2,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\max \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 100 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\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}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 5 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 10 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 55 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 100 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 550 \\\\\n",
       "\\end{array} \\\\\n",
       "x_{1}, x_{2}, x_{3} \\geq 0\n",
       "\\end{array}</script></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} 100 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\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}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 5 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 10 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 55 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 100 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 550 \\\\\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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}550</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}550$$"
      ],
      "text/plain": [
       "550"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(5,\\,5,\\,0\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(5,\\,5,\\,0\\right)$$"
      ],
      "text/plain": [
       "(5, 5, 0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}$$"
      ],
      "text/plain": [
       "dual"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\min \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 5 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 55 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 550 y_{3} \\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} 10 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 100 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 100 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 10 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2}, y_{3} \\geq 0\n",
       "\\end{array}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\min \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 5 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 55 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 550 y_{3} \\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} 10 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 100 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 100 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 10 \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 1 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2}, y_{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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}550</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}550$$"
      ],
      "text/plain": [
       "550"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,1\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,1\\right)$$"
      ],
      "text/plain": [
       "(0, 0, 1)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{2} & 10 & 1 & 0 & 0 & 1 & 0 & 55 \\\\\n",
       "{\\color{green}{s}}_{3} & 100 & 10 & 1 & 0 & 0 & 1 & 550 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 100 & 10 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{2} & 10 & 1 & 0 & 0 & 1 & 0 & 55 \\\\\n",
       "{\\color{green}{s}}_{3} & 100 & 10 & 1 & 0 & 0 & 1 & 550 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 100 & 10 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3|rhs]\n",
       "[---+-----------------------+---]\n",
       "[ s1|  1   0   0   1   0   0|  5]\n",
       "[ s2| 10   1   0   0   1   0| 55]\n",
       "[ s3|100  10   1   0   0   1|550]\n",
       "[---+-----------------------+---]\n",
       "[  Z|100  10   1   0   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 1 , 1 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{2} & 0 & 1 & 0 & -10 & 1 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{3} & 0 & 10 & 1 & -100 & 0 & 1 & 50 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 10 & 1 & -100 & 0 & 0 & 500\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{2} & 0 & 1 & 0 & -10 & 1 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{3} & 0 & 10 & 1 & -100 & 0 & 1 & 50 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 10 & 1 & -100 & 0 & 0 & 500\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[   B|  x1   x2   x3   s1   s2   s3| rhs]\n",
       "[----+-----------------------------+----]\n",
       "[  x1|   1    0    0    1    0    0|   5]\n",
       "[  s2|   0    1    0  -10    1    0|   5]\n",
       "[  s3|   0   10    1 -100    0    1|  50]\n",
       "[----+-----------------------------+----]\n",
       "[   Z|   0   10    1 -100    0    0| 500]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 2 , 2 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{x}_{2} & 0 & 1 & 0 & -10 & 1 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{3} & 0 & 0 & 1 & 0 & -10 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 1 & 0 & -10 & 0 & 550\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{x}_{2} & 0 & 1 & 0 & -10 & 1 & 0 & 5 \\\\\n",
       "{\\color{green}{s}}_{3} & 0 & 0 & 1 & 0 & -10 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 1 & 0 & -10 & 0 & 550\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3|rhs]\n",
       "[---+-----------------------+---]\n",
       "[ x1|  1   0   0   1   0   0|  5]\n",
       "[ x2|  0   1   0 -10   1   0|  5]\n",
       "[ s3|  0   0   1   0 -10   1|  0]\n",
       "[---+-----------------------+---]\n",
       "[  Z|  0   0   1   0 -10   0|550]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cambio( 3 , 3 )\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{x}_{2} & 0 & 1 & 0 & -10 & 1 & 0 & 5 \\\\\n",
       "{x}_{3} & 0 & 0 & 1 & 0 & -10 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & -1 & 550\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{1} & 1 & 0 & 0 & 1 & 0 & 0 & 5 \\\\\n",
       "{x}_{2} & 0 & 1 & 0 & -10 & 1 & 0 & 5 \\\\\n",
       "{x}_{3} & 0 & 0 & 1 & 0 & -10 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & -1 & 550\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3|rhs]\n",
       "[---+-----------------------+---]\n",
       "[ x1|  1   0   0   1   0   0|  5]\n",
       "[ x2|  0   1   0 -10   1   0|  5]\n",
       "[ x3|  0   0   1   0 -10   1|  0]\n",
       "[---+-----------------------+---]\n",
       "[  Z|  0   0   0   0   0  -1|550]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "El problema es óptimo\n"
     ]
    }
   ],
   "source": [
    "tipo='max'     #   Problema de tipo max o min\n",
    "\n",
    "n=3 #  número de variables x's\n",
    "m=3 #  número de restricciones (distintas de las de signo)\n",
    "\n",
    "c=matrix(QQ,1,n,[100,10,1] )  # vector de costos\n",
    "\n",
    "A=matrix(QQ,m,n,[   # coeficientes de las variables x's\n",
    "[1,0,0],\n",
    "[10,1,0],\n",
    "[100, 10, 1]\n",
    "])\n",
    "\n",
    "b=matrix(QQ,m,1,[5,55,550])  # vector de la derecha\n",
    "\n",
    "\n",
    "h=matrix(ZZ,1,m,[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",
    "t=matrix(ZZ,1,m,[0,0,0])   # variables artificiales: \n",
    "                             # pon 1 si utilizas variable artificial en la fila i-ésima\n",
    "                             #     0 si no utilizas variable artificial en la fila i-ésima\n",
    "\n",
    "colId=(4,5,6) # posición de la matriz identidad\n",
    "\n",
    "\n",
    "    \n",
    "    \n",
    "####################################################################\n",
    "############  HASTA AQUÍ LOS DATOS  ################################\n",
    "####################################################################\n",
    "\n",
    "\n",
    "load('https://sage.unex.es/501708/simplex2023Auto.sage')\n",
    "\n",
    "#load('https://sage.unex.es/501708/simplex2023CompletamenteManual.sage')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\min \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 0 \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} \\geq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\n",
       "\\end{array} \\\\\n",
       "x_{1}, x_{2}, x_{3} \\geq 0\n",
       "\\end{array}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\min \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 0 \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} \\geq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}0</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,0\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,0\\right)$$"
      ],
      "text/plain": [
       "(0, 0, 0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}$$"
      ],
      "text/plain": [
       "dual"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n",
       "\\begin{array}{lcrcrcrcl}\n",
       " \\max \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 0 \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} \\leq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} \\leq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2}, y_{3} \\geq 0\n",
       "\\end{array}</script></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}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} 0 \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
       " \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu}  \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} \\leq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\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} \\leq \\mspace{-6mu}&\\mspace{-6mu} 0 \\\\\n",
       "\\end{array} \\\\\n",
       "y_{1}, y_{2}, y_{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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}0</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,0\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,0,\\,0\\right)$$"
      ],
      "text/plain": [
       "(0, 0, 0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
      ],
      "text/plain": [
       "salto"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\ \\ \\ Fase\\ I}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\ \\ \\ Fase\\ I}$$"
      ],
      "text/plain": [
       "FI"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{red}{t}}_{1} & 0 & -1 & 1 & -1 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{red}{t}}_{1} & 0 & -1 & 1 & -1 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ t1|  0  -1   1  -1   0   0   1   0   0|  0]\n",
       "[ t2|  1   0  -1   0  -1   0   0   1   0|  0]\n",
       "[ t3| -1   1   0   0   0  -1   0   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0   0   0   1   1   1   0   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": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{2} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 0 & 1 & -1 & 0 & -1 & 1 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{2} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 0 & 1 & -1 & 0 & -1 & 1 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ x2|  0   1  -1   1   0   0  -1   0   0|  0]\n",
       "[ t2|  1   0  -1   0  -1   0   0   1   0|  0]\n",
       "[ t3| -1   0   1  -1   0  -1   1   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0   0   0   1   1   1   0   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 0 & -1 & 1 & -1 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & -1 & 0 & -1 & -1 & 0 & 1 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{3} & 0 & -1 & 1 & -1 & 0 & 0 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & -1 & 0 & -1 & -1 & 0 & 1 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ x3|  0  -1   1  -1   0   0   1   0   0|  0]\n",
       "[ t2|  1  -1   0  -1  -1   0   1   1   0|  0]\n",
       "[ t3| -1   1   0   0   0  -1   0   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0   0   0   1   1   1   0   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & -1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{2} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & -1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1|  0   1  -1   1   0   0  -1   0   0|  0]\n",
       "[ t2|  1   0  -1   0  -1   0   0   1   0|  0]\n",
       "[ t3| -1   1   0   0   0  -1   0   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0  -1   1   0   1   1   1   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{x}_{1} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & 0 & 1 & -1 & 0 & -1 & -1 & 0 & 1 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & -1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{x}_{1} & 1 & 0 & -1 & 0 & -1 & 0 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & 0 & 1 & -1 & 0 & -1 & -1 & 0 & 1 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & -1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1|  0   1  -1   1   0   0  -1   0   0|  0]\n",
       "[ x1|  1   0  -1   0  -1   0   0   1   0|  0]\n",
       "[ t3|  0   1  -1   0  -1  -1   0   1   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0  -1   1   0   1   1   1   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & -1 & 1 & 0 & 1 & 1 & 0 & -1 & -1 & 0 & 0 \\\\\n",
       "{x}_{3} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 1 & -1 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & -1 & 1 & 0 & 1 & 1 & 0 & -1 & -1 & 0 & 0 \\\\\n",
       "{x}_{3} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 1 & -1 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1| -1   1   0   1   1   0  -1  -1   0|  0]\n",
       "[ x3| -1   0   1   0   1   0   0  -1   0|  0]\n",
       "[ t3| -1   1   0   0   0  -1   0   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  1  -1   0   0   0   1   1   1   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 1 & -1 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{\\color{red}{t}}_{3} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 1 & -1 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1|  0   1  -1   1   0   0  -1   0   0|  0]\n",
       "[ s2| -1   0   1   0   1   0   0  -1   0|  0]\n",
       "[ t3| -1   1   0   0   0  -1   0   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  1  -1   0   0   0   1   1   1   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & 0 & -1 & 1 & 0 & 1 & 1 & 0 & -1 & -1 & 0 \\\\\n",
       "{x}_{1} & 1 & -1 & 0 & 0 & 0 & 1 & 0 & 0 & -1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & 0 & -1 & 1 & 0 & 1 & 1 & 0 & -1 & -1 & 0 \\\\\n",
       "{x}_{1} & 1 & -1 & 0 & 0 & 0 & 1 & 0 & 0 & -1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1|  0   1  -1   1   0   0  -1   0   0|  0]\n",
       "[ s2|  0  -1   1   0   1   1   0  -1  -1|  0]\n",
       "[ x1|  1  -1   0   0   0   1   0   0  -1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0   0   0   0   0   0   1   1   1|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & -1 & 1 & 0 & 1 & -1 & 0 & -1 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{x}_{2} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 1 & 0 & -1 & 1 & 0 & 1 & -1 & 0 & -1 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{x}_{2} & -1 & 1 & 0 & 0 & 0 & -1 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1|  1   0  -1   1   0   1  -1   0  -1|  0]\n",
       "[ s2| -1   0   1   0   1   0   0  -1   0|  0]\n",
       "[ x2| -1   1   0   0   0  -1   0   0   1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0   0   0   0   0   0   1   1   1|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{3} & 1 & -1 & 0 & 0 & 0 & 1 & 0 & 0 & -1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & -1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{3} & 1 & -1 & 0 & 0 & 0 & 1 & 0 & 0 & -1 & 0 \\\\\n",
       "\\hline\n",
       " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3  t1  t2  t3|rhs]\n",
       "[---+-----------------------------------+---]\n",
       "[ s1|  0   1  -1   1   0   0  -1   0   0|  0]\n",
       "[ s2| -1   0   1   0   1   0   0  -1   0|  0]\n",
       "[ s3|  1  -1   0   0   0   1   0   0  -1|  0]\n",
       "[---+-----------------------------------+---]\n",
       "[  W|  0   0   0   0   0   0   1   1   1|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\ \\ \\ Fase\\ II}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\ \\ \\ Fase\\ II}$$"
      ],
      "text/plain": [
       "FII"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
      ],
      "text/plain": [
       "ry"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{3} & 1 & -1 & 0 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {\\color{green}{s}}_{1} & 0 & 1 & -1 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{3} & 1 & -1 & 0 & 0 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3|rhs]\n",
       "[---+-----------------------+---]\n",
       "[ s1|  0   1  -1   1   0   0|  0]\n",
       "[ s2| -1   0   1   0   1   0|  0]\n",
       "[ s3|  1  -1   0   0   0   1|  0]\n",
       "[---+-----------------------+---]\n",
       "[  Z|  0   0   0   0   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "El problema es óptimo\n"
     ]
    }
   ],
   "source": [
    "tipo=\"min\"\n",
    "n=3 #  número de variables x's\n",
    "m=3 #  número de restricciones (distintas de las de signo)\n",
    "\n",
    "c=matrix(QQ,1,n,[0,0,0] )  # vector de costos\n",
    "\n",
    "A=matrix(QQ,m,n,[   # coeficientes de las variables x's\n",
    "[0,-1,1],\n",
    "[1,0,-1],\n",
    "[-1,1,0]\n",
    "])\n",
    "\n",
    "\n",
    "\n",
    "b=matrix(QQ,m,1,[0,0,0])  # vector de la derecha\n",
    "\n",
    "\n",
    "######################################################\n",
    "############### VARIABLES DE HOLGURA  ################\n",
    "\n",
    "\n",
    "h=matrix(ZZ,1,m,[-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",
    "load('https://sage.unex.es/501708/simplex2023Auto.sage')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{2} & 0 & 1 & -1 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{3} & 1 & 0 & -1 & 1 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{2} & 0 & 1 & -1 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & -1 & 0 & 1 & 0 & 1 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{3} & 1 & 0 & -1 & 1 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3|rhs]\n",
       "[---+-----------------------+---]\n",
       "[ x2|  0   1  -1   1   0   0|  0]\n",
       "[ s2| -1   0   1   0   1   0|  0]\n",
       "[ s3|  1   0  -1   1   0   1|  0]\n",
       "[---+-----------------------+---]\n",
       "[  Z|  0   0   0   0   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cambio(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html><script type=\"math/tex; mode=display\">\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{2} & 0 & 1 & -1 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & 0 & 0 & 0 & 1 & 1 & 1 & 0 \\\\\n",
       "{x}_{1} & 1 & 0 & -1 & 1 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)</script></html>"
      ],
      "text/latex": [
       "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
       "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
       "\\hline\n",
       " {x}_{2} & 0 & 1 & -1 & 1 & 0 & 0 & 0 \\\\\n",
       "{\\color{green}{s}}_{2} & 0 & 0 & 0 & 1 & 1 & 1 & 0 \\\\\n",
       "{x}_{1} & 1 & 0 & -1 & 1 & 0 & 1 & 0 \\\\\n",
       "\\hline\n",
       " {Z_{ind}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\n",
       "\\end{array}\\right)$$"
      ],
      "text/plain": [
       "[  B| x1  x2  x3  s1  s2  s3|rhs]\n",
       "[---+-----------------------+---]\n",
       "[ x2|  0   1  -1   1   0   0|  0]\n",
       "[ s2|  0   0   0   1   1   1|  0]\n",
       "[ x1|  1   0  -1   1   0   1|  0]\n",
       "[---+-----------------------+---]\n",
       "[  Z|  0   0   0   0   0   0|  0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cambio(3,1)"
   ]
  }
 ],
 "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
}
