{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8f1b9136", "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": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n", "\\begin{array}{lcrcrcrcl}\n", " \\min \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 5 x_{2} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 2 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} x_{2} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 20 \\\\\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} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 18 \\\\\n", "\\end{array} \\\\\n", "x_{1}, x_{2}, x_{3} \\geq 0\n", "\\end{array}$$" ], "text/plain": [ "LP problem (use 'view(...)' or '%display typeset' for details)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}-\\infty$$" ], "text/plain": [ "-Infinity" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\mathrm{None}$$" ], "text/plain": [ "None" ] }, "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}}{===================================}$$" ], "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} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{red}{t}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & -1 & -1 & -1 & 0 & 0 & 20 \\\\\n", "{\\color{red}{t}}_{2} & 0 & 1 & 2 & 0 & -1 & 1 & 18 \\\\\n", "\\hline\n", " {W_{ind}} & 0 & -1 & -2 & 0 & 1 & 0 & 18\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 t2|rhs]\n", "[---+-----------------------+---]\n", "[ x1| 1 -1 -1 -1 0 0| 20]\n", "[ t2| 0 1 2 0 -1 1| 18]\n", "[---+-----------------------+---]\n", "[ W| 0 -1 -2 0 1 0| 18]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tipo='min' # max o min\n", "\n", "n=3 # número de variables x's\n", "m=2 # número de restricciones (distintas de las de signo)\n", "\n", "c=matrix(QQ,1,n,[-1,-5,-2] ) # vector de costos\n", "\n", "A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n", "[1,-1,-1],\n", "[0,1,2]\n", "])\n", "\n", "b=matrix(QQ,m,1,[20,18]) # vector de la derecha\n", "\n", "\n", "######################################################\n", "############### VARIABLES DE HOLGURA ################\n", "\n", "\n", "h=matrix(ZZ,1,m,[-1,-1]) \n", "\n", "t=matrix(ZZ,1,m,[0,1])\n", "\n", "colId=(1,6)\n", "\n", "\n", "\n", "\n", "\n", "####################################################################\n", "############ HASTA AQUÍ LOS DATOS ################################\n", "####################################################################\n", "\n", "\n", "\n", "load('https://sage.unex.es/501708/simplex2023CompletamenteManual.sage')\n", "\n", "#load('https://sage.unex.es/501708/simplex2023Auto.sage')" ] }, { "cell_type": "code", "execution_count": 2, "id": "7ff9f894", "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} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{red}{t}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & -\\frac{1}{2} & 0 & -1 & -\\frac{1}{2} & \\frac{1}{2} & 29 \\\\\n", "{x}_{3} & 0 & \\frac{1}{2} & 1 & 0 & -\\frac{1}{2} & \\frac{1}{2} & 9 \\\\\n", "\\hline\n", " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 1 & 0\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 t2| rhs]\n", "[----+-----------------------------+----]\n", "[ x1| 1 -1/2 0 -1 -1/2 1/2| 29]\n", "[ x3| 0 1/2 1 0 -1/2 1/2| 9]\n", "[----+-----------------------------+----]\n", "[ W| 0 0 0 0 0 1| 0]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cambio(2,3)" ] }, { "cell_type": "code", "execution_count": 3, "id": "88ce80bb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & -\\frac{1}{2} & 0 & -1 & -\\frac{1}{2} & 29 \\\\\n", "{x}_{3} & 0 & \\frac{1}{2} & 1 & 0 & -\\frac{1}{2} & 9 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & -\\frac{9}{2} & 0 & -1 & -\\frac{3}{2} & -47\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2| rhs]\n", "[----+------------------------+----]\n", "[ x1| 1 -1/2 0 -1 -1/2| 29]\n", "[ x3| 0 1/2 1 0 -1/2| 9]\n", "[----+------------------------+----]\n", "[ Z| 0 -9/2 0 -1 -3/2| -47]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tt=[0,0];faseII(0,tt)" ] }, { "cell_type": "code", "execution_count": 4, "id": "b3cf70a0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & 0 & 1 & -1 & -1 & 38 \\\\\n", "{x}_{2} & 0 & 1 & 2 & 0 & -1 & 18 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & 0 & 9 & -1 & -6 & -128\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2| rhs]\n", "[----+------------------------+----]\n", "[ x1| 1 0 1 -1 -1| 38]\n", "[ x2| 0 1 2 0 -1| 18]\n", "[----+------------------------+----]\n", "[ Z| 0 0 9 -1 -6|-128]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cambio(2,2)" ] }, { "cell_type": "code", "execution_count": 5, "id": "9684f6ec", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/lib/python3/dist-packages/sage/misc/remote_file.py:46: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated.\n", " content = urlopen(req, timeout=1, context=SSLContext())\n", "/usr/lib/python3/dist-packages/sage/misc/remote_file.py:46: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated\n", " content = urlopen(req, timeout=1, context=SSLContext())\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n", "\\begin{array}{lcrcrcrcl}\n", " \\min \\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} 2 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} x_{2} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 20 \\\\\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} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 18 \\\\\n", "\\end{array} \\\\\n", "x_{1}, x_{2}, x_{3} \\geq 0\n", "\\end{array}$$" ], "text/plain": [ "LP problem (use 'view(...)' or '%display typeset' for details)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}18$$" ], "text/plain": [ "18" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,58,\\,38\\right)$$" ], "text/plain": [ "(0, 58, 38)" ] }, "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}}{===================================}$$" ], "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} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{red}{t}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & 1 & -1 & -1 & 0 & 0 & 20 \\\\\n", "{\\color{red}{t}}_{2} & 0 & -1 & 2 & 0 & -1 & 1 & 18 \\\\\n", "\\hline\n", " {W_{ind}} & 0 & 1 & -2 & 0 & 1 & 0 & 18\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 t2|rhs]\n", "[---+-----------------------+---]\n", "[ x1| 1 1 -1 -1 0 0| 20]\n", "[ t2| 0 -1 2 0 -1 1| 18]\n", "[---+-----------------------+---]\n", "[ W| 0 1 -2 0 1 0| 18]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tipo='min' # max o min\n", "\n", "n=3 # número de variables x's\n", "m=2 # número de restricciones (distintas de las de signo)\n", "\n", "c=matrix(QQ,1,n,[1,-1,2] ) # vector de costos\n", "\n", "A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n", "[1,1,-1],\n", "[0,-1,2]\n", "])\n", "\n", "b=matrix(QQ,m,1,[20,18]) # vector de la derecha\n", "\n", "\n", "######################################################\n", "############### VARIABLES DE HOLGURA ################\n", "\n", "\n", "h=matrix(ZZ,1,m,[-1,-1]) \n", "t=matrix(ZZ,1,m,[0,1])\n", "\n", "colId=(1,6)\n", "\n", "\n", "\n", "\n", "\n", "####################################################################\n", "############ HASTA AQUÍ LOS DATOS ################################\n", "####################################################################\n", "\n", "\n", "\n", "load('https://sage.unex.es/501708/simplex2023CompletamenteManual.sage')\n", "\n", "#load('https://sage.unex.es/501708/simplex2023Auto.sage')\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "1fcb5c41", "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} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{red}{t}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & \\frac{1}{2} & 0 & -1 & -\\frac{1}{2} & \\frac{1}{2} & 29 \\\\\n", "{x}_{3} & 0 & -\\frac{1}{2} & 1 & 0 & -\\frac{1}{2} & \\frac{1}{2} & 9 \\\\\n", "\\hline\n", " {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 1 & 0\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 t2| rhs]\n", "[----+-----------------------------+----]\n", "[ x1| 1 1/2 0 -1 -1/2 1/2| 29]\n", "[ x3| 0 -1/2 1 0 -1/2 1/2| 9]\n", "[----+-----------------------------+----]\n", "[ W| 0 0 0 0 0 1| 0]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cambio(2,3)" ] }, { "cell_type": "code", "execution_count": 7, "id": "f1de3171", "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & \\frac{1}{2} & 0 & -1 & -\\frac{1}{2} & 29 \\\\\n", "{x}_{3} & 0 & -\\frac{1}{2} & 1 & 0 & -\\frac{1}{2} & 9 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & -\\frac{1}{2} & 0 & 1 & \\frac{3}{2} & 47\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2| rhs]\n", "[----+------------------------+----]\n", "[ x1| 1 1/2 0 -1 -1/2| 29]\n", "[ x3| 0 -1/2 1 0 -1/2| 9]\n", "[----+------------------------+----]\n", "[ Z| 0 -1/2 0 1 3/2| 47]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tt=[0,0]; faseII(0,tt)" ] }, { "cell_type": "code", "execution_count": 8, "id": "77a43c91", "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {b} \\\\\n", "\\hline\n", " {x}_{2} & 2 & 1 & 0 & -2 & -1 & 58 \\\\\n", "{x}_{3} & 1 & 0 & 1 & -1 & -1 & 38 \\\\\n", "\\hline\n", " {Z_{ind}} & 1 & 0 & 0 & 0 & 1 & 18\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2|rhs]\n", "[---+-------------------+---]\n", "[ x2| 2 1 0 -2 -1| 58]\n", "[ x3| 1 0 1 -1 -1| 38]\n", "[---+-------------------+---]\n", "[ Z| 1 0 0 0 1| 18]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cambio(1,2)" ] }, { "cell_type": "code", "execution_count": null, "id": "6ccc13d1", "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 }