{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/lib/python3/dist-packages/sage/misc/remote_file.py:46: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated.\n", " content = urlopen(req, timeout=1, context=SSLContext())\n", "/usr/lib/python3/dist-packages/sage/misc/remote_file.py:46: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated\n", " content = urlopen(req, timeout=1, context=SSLContext())\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n", "\\begin{array}{lcrcrcrcl}\n", " \\max \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 60 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 40 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 70 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 3 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 12 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 15 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 25 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 40 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 310 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 9 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 20 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 30 x_{3} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 200 \\\\\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}}\\frac{14680}{27}$$" ], "text/plain": [ "14680/27" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\frac{160}{81},\\,0,\\,\\frac{164}{27}\\right)$$" ], "text/plain": [ "(160/81, 0, 164/27)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$" ], "text/plain": [ "salto" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{\\texttt{El dual es:}}$$" ], "text/plain": [ "dual" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$" ], "text/plain": [ "ry" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\begin{array}{l}\n", "\\begin{array}{lcrcrcrcl}\n", " \\min \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 12 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 310 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 200 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 3 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 15 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 9 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 60 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 2 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 25 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 20 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 40 \\\\\n", " \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 40 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 30 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 70 \\\\\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": [ "" ], "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}}\\frac{14680}{27}$$" ], "text/plain": [ "14680/27" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\frac{130}{9},\\,0,\\,\\frac{50}{27}\\right)$$" ], "text/plain": [ "(130/9, 0, 50/27)" ] }, "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{green}{s}}_{3} & {b} \\\\\n", "\\hline\n", " {\\color{green}{s}}_{1} & 3 & 2 & 1 & 1 & 0 & 0 & 12 \\\\\n", "{\\color{green}{s}}_{2} & 15 & 25 & 40 & 0 & 1 & 0 & 310 \\\\\n", "{\\color{green}{s}}_{3} & 9 & 20 & 30 & 0 & 0 & 1 & 200 \\\\\n", "\\hline\n", " {Z_{ind}} & 60 & 40 & 70 & 0 & 0 & 0 & 0\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3|rhs]\n", "[---+-----------------------+---]\n", "[ s1| 3 2 1 1 0 0| 12]\n", "[ s2| 15 25 40 0 1 0|310]\n", "[ s3| 9 20 30 0 0 1|200]\n", "[---+-----------------------+---]\n", "[ Z| 60 40 70 0 0 0| 0]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " \n", " \n", "cambio( 3 , 3 )\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n", "\\hline\n", " {\\color{green}{s}}_{1} & \\frac{27}{10} & \\frac{4}{3} & 0 & 1 & 0 & -\\frac{1}{30} & \\frac{16}{3} \\\\\n", "{\\color{green}{s}}_{2} & 3 & -\\frac{5}{3} & 0 & 0 & 1 & -\\frac{4}{3} & \\frac{130}{3} \\\\\n", "{x}_{3} & \\frac{3}{10} & \\frac{2}{3} & 1 & 0 & 0 & \\frac{1}{30} & \\frac{20}{3} \\\\\n", "\\hline\n", " {Z_{ind}} & 39 & -\\frac{20}{3} & 0 & 0 & 0 & -\\frac{7}{3} & \\frac{1400}{3}\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3| rhs]\n", "[------+-----------------------------------------+------]\n", "[ s1| 27/10 4/3 0 1 0 -1/30| 16/3]\n", "[ s2| 3 -5/3 0 0 1 -4/3| 130/3]\n", "[ x3| 3/10 2/3 1 0 0 1/30| 20/3]\n", "[------+-----------------------------------------+------]\n", "[ Z| 39 -20/3 0 0 0 -7/3|1400/3]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "cambio( 1 , 1 )\n" ] }, { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & \\frac{40}{81} & 0 & \\frac{10}{27} & 0 & -\\frac{1}{81} & \\frac{160}{81} \\\\\n", "{\\color{green}{s}}_{2} & 0 & -\\frac{85}{27} & 0 & -\\frac{10}{9} & 1 & -\\frac{35}{27} & \\frac{1010}{27} \\\\\n", "{x}_{3} & 0 & \\frac{14}{27} & 1 & -\\frac{1}{9} & 0 & \\frac{1}{27} & \\frac{164}{27} \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & -\\frac{700}{27} & 0 & -\\frac{130}{9} & 0 & -\\frac{50}{27} & \\frac{14680}{27}\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3| rhs]\n", "[--------+-----------------------------------------------------+--------]\n", "[ x1| 1 40/81 0 10/27 0 -1/81| 160/81]\n", "[ s2| 0 -85/27 0 -10/9 1 -35/27| 1010/27]\n", "[ x3| 0 14/27 1 -1/9 0 1/27| 164/27]\n", "[--------+-----------------------------------------------------+--------]\n", "[ Z| 0 -700/27 0 -130/9 0 -50/27|14680/27]" ] }, "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{green}{s}}_{3} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & \\frac{40}{81} & 0 & \\frac{10}{27} & 0 & -\\frac{1}{81} & \\frac{160}{81} \\\\\n", "{\\color{green}{s}}_{2} & 0 & -\\frac{85}{27} & 0 & -\\frac{10}{9} & 1 & -\\frac{35}{27} & \\frac{1010}{27} \\\\\n", "{x}_{3} & 0 & \\frac{14}{27} & 1 & -\\frac{1}{9} & 0 & \\frac{1}{27} & \\frac{164}{27} \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & -\\frac{700}{27} & 0 & -\\frac{130}{9} & 0 & -\\frac{50}{27} & \\frac{14680}{27}\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3| rhs]\n", "[--------+-----------------------------------------------------+--------]\n", "[ x1| 1 40/81 0 10/27 0 -1/81| 160/81]\n", "[ s2| 0 -85/27 0 -10/9 1 -35/27| 1010/27]\n", "[ x3| 0 14/27 1 -1/9 0 1/27| 164/27]\n", "[--------+-----------------------------------------------------+--------]\n", "[ Z| 0 -700/27 0 -130/9 0 -50/27|14680/27]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "El problema es óptimo\n" ] } ], "source": [ "tipo='max' #max o min\n", "n=3 # número de variables x's\n", "m=3 # número de restricciones (distintas de las de signo)\n", "\n", "\n", "c=matrix(QQ,1,n,[60,40,70] ) # vector de costos\n", "\n", "A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n", "[3,2,1],\n", "[15,25,40],\n", "[9,20,30]\n", "])\n", "\n", "b=matrix(QQ,m,1,[12,310,200]) # vector de la derecha\n", "\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", "#######################################################\n", "\n", "####################################################################\n", "############ HASTA AQUÍ LOS DATOS ################################\n", "####################################################################\n", "\n", "\n", "#load('https://sage.unex.es/501708/simplex2023Auto.sage')\n", "load('https://sage.unex.es/501708/simplex2023Auto_MC.sage')\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left[1, 2, 3, 4, 5, 6\\right]$$" ], "text/plain": [ "[1, 2, 3, 4, 5, 6]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "[79/81, 11/27, 2/27]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pardec()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & \\frac{40}{81} & 0 & \\frac{10}{27} & 0 & -\\frac{1}{81} & 0 & \\frac{160}{81} \\\\\n", "{\\color{green}{s}}_{2} & 0 & -\\frac{85}{27} & 0 & -\\frac{10}{9} & 1 & -\\frac{35}{27} & 0 & \\frac{1010}{27} \\\\\n", "{x}_{3} & 0 & \\frac{14}{27} & 1 & -\\frac{1}{9} & 0 & \\frac{1}{27} & 0 & \\frac{164}{27} \\\\\n", "{\\color{green}{s}}_{4} & 0 & -\\frac{26}{675} & 0 & -\\frac{2}{225} & 0 & -\\frac{1}{27} & 1 & -\\frac{2}{27} \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & -\\frac{700}{27} & 0 & -\\frac{130}{9} & 0 & -\\frac{50}{27} & 0 & \\frac{14680}{27}\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4| rhs]\n", "[--------+--------------------------------------------------------------+--------]\n", "[ x1| 1 40/81 0 10/27 0 -1/81 0| 160/81]\n", "[ s2| 0 -85/27 0 -10/9 1 -35/27 0| 1010/27]\n", "[ x3| 0 14/27 1 -1/9 0 1/27 0| 164/27]\n", "[ s4| 0 -26/675 0 -2/225 0 -1/27 1| -2/27]\n", "[--------+--------------------------------------------------------------+--------]\n", "[ Z| 0 -700/27 0 -130/9 0 -50/27 0|14680/27]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "v=matrix(QQ,1,nv,[0,-26/675,0,-2/225,0,-1/27] ); R=-2/27;añadeRes(v,R)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ NO 673.08 NO 1625.0 NO 50.000 NO]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cocientesD(4)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/latex": [ "$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrr|r}\n", "{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {\\color{green}{s}}_{4} & {b} \\\\\n", "\\hline\n", " {x}_{1} & 1 & \\frac{38}{75} & 0 & \\frac{28}{75} & 0 & 0 & -\\frac{1}{3} & 2 \\\\\n", "{\\color{green}{s}}_{2} & 0 & -\\frac{9}{5} & 0 & -\\frac{4}{5} & 1 & 0 & -35 & 40 \\\\\n", "{x}_{3} & 0 & \\frac{12}{25} & 1 & -\\frac{3}{25} & 0 & 0 & 1 & 6 \\\\\n", "{\\color{green}{s}}_{3} & 0 & \\frac{26}{25} & 0 & \\frac{6}{25} & 0 & 1 & -27 & 2 \\\\\n", "\\hline\n", " {Z_{ind}} & 0 & -24 & 0 & -14 & 0 & 0 & -50 & 540\n", "\\end{array}\\right)$$" ], "text/plain": [ "[ B| x1 x2 x3 s1 s2 s3 s4| rhs]\n", "[-----+-----------------------------------------+-----]\n", "[ x1| 1 38/75 0 28/75 0 0 -1/3| 2]\n", "[ s2| 0 -9/5 0 -4/5 1 0 -35| 40]\n", "[ x3| 0 12/25 1 -3/25 0 0 1| 6]\n", "[ s3| 0 26/25 0 6/25 0 1 -27| 2]\n", "[-----+-----------------------------------------+-----]\n", "[ Z| 0 -24 0 -14 0 0 -50| 540]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cambio(4,6)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1298/16875" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(-2/25)*(26/675-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 }