{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"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}{lcrcrcl}\n",
" \\max \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 30 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 20 x_{2} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{50} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{80} x_{2} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 170 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 7000 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} x_{2} \\mspace{-6mu}&\\mspace{-6mu} \\leq \\mspace{-6mu}&\\mspace{-6mu} 10000 \\\\\n",
"\\end{array} \\\\\n",
"x_{1}, x_{2} \\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}}267500$$"
],
"text/plain": [
"267500"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(2250,\\,10000\\right)$$"
],
"text/plain": [
"(2250, 10000)"
]
},
"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} 170 y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 7000 y_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 10000 y_{3} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{50} y_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} y_{2} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\geq \\mspace{-6mu}&\\mspace{-6mu} 30 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\frac{1}{80} y_{1} \\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} 20 \\\\\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}}267500$$"
],
"text/plain": [
"267500"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(1500,\\,0,\\,\\frac{5}{4}\\right)$$"
],
"text/plain": [
"(1500, 0, 5/4)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
],
"text/plain": [
"salto"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
],
"text/plain": [
"ry"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
"\\hline\n",
" {\\color{green}{s}}_{1} & \\frac{1}{50} & \\frac{1}{80} & 1 & 0 & 0 & 170 \\\\\n",
"{\\color{green}{s}}_{2} & 1 & 0 & 0 & 1 & 0 & 7000 \\\\\n",
"{\\color{green}{s}}_{3} & 0 & 1 & 0 & 0 & 1 & 10000 \\\\\n",
"\\hline\n",
" {Z_{ind}} & 30 & 20 & 0 & 0 & 0 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 s1 s2 s3| rhs]\n",
"[-----+-----------------------------+-----]\n",
"[ s1| 1/50 1/80 1 0 0| 170]\n",
"[ s2| 1 0 0 1 0| 7000]\n",
"[ s3| 0 1 0 0 1|10000]\n",
"[-----+-----------------------------+-----]\n",
"[ Z| 30 20 0 0 0| 0]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cambio( 2 , 1 )\n"
]
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
"\\hline\n",
" {\\color{green}{s}}_{1} & 0 & \\frac{1}{80} & 1 & -\\frac{1}{50} & 0 & 30 \\\\\n",
"{x}_{1} & 1 & 0 & 0 & 1 & 0 & 7000 \\\\\n",
"{\\color{green}{s}}_{3} & 0 & 1 & 0 & 0 & 1 & 10000 \\\\\n",
"\\hline\n",
" {Z_{ind}} & 0 & 20 & 0 & -30 & 0 & 210000\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 s1 s2 s3| rhs]\n",
"[------+----------------------------------+------]\n",
"[ s1| 0 1/80 1 -1/50 0| 30]\n",
"[ x1| 1 0 0 1 0| 7000]\n",
"[ s3| 0 1 0 0 1| 10000]\n",
"[------+----------------------------------+------]\n",
"[ Z| 0 20 0 -30 0|210000]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cambio( 1 , 2 )\n"
]
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
"\\hline\n",
" {x}_{2} & 0 & 1 & 80 & -\\frac{8}{5} & 0 & 2400 \\\\\n",
"{x}_{1} & 1 & 0 & 0 & 1 & 0 & 7000 \\\\\n",
"{\\color{green}{s}}_{3} & 0 & 0 & -80 & \\frac{8}{5} & 1 & 7600 \\\\\n",
"\\hline\n",
" {Z_{ind}} & 0 & 0 & -1600 & 2 & 0 & 258000\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 s1 s2 s3| rhs]\n",
"[------+----------------------------------+------]\n",
"[ x2| 0 1 80 -8/5 0| 2400]\n",
"[ x1| 1 0 0 1 0| 7000]\n",
"[ s3| 0 0 -80 8/5 1| 7600]\n",
"[------+----------------------------------+------]\n",
"[ Z| 0 0 -1600 2 0|258000]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cambio( 3 , 4 )\n"
]
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} \\\\\n",
"\\hline\n",
" {x}_{2} & 0 & 1 & 0 & 0 & 1 & 10000 \\\\\n",
"{x}_{1} & 1 & 0 & 50 & 0 & -\\frac{5}{8} & 2250 \\\\\n",
"{\\color{green}{s}}_{2} & 0 & 0 & -50 & 1 & \\frac{5}{8} & 4750 \\\\\n",
"\\hline\n",
" {Z_{ind}} & 0 & 0 & -1500 & 0 & -\\frac{5}{4} & 267500\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 s1 s2 s3| rhs]\n",
"[------+----------------------------------+------]\n",
"[ x2| 0 1 0 0 1| 10000]\n",
"[ x1| 1 0 50 0 -5/8| 2250]\n",
"[ s2| 0 0 -50 1 5/8| 4750]\n",
"[------+----------------------------------+------]\n",
"[ Z| 0 0 -1500 0 -5/4|267500]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"El problema es óptimo\n"
]
}
],
"source": [
"tipo='max' # max o min\n",
"\n",
"n=2 # 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,[30,20] ) # vector de costos\n",
"\n",
"A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n",
"[1/50,1/80],\n",
"[1,0],\n",
"[0,1]\n",
"])\n",
"\n",
"b=matrix(QQ,m,1,[170,7000,10000]) # 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",
"\n",
"\n",
"\n",
"####################################################################\n",
"############ HASTA AQUÍ LOS DATOS ################################\n",
"####################################################################\n",
"\n",
"load('https://sage.unex.es/501708/simplex2023Auto.sage')\n",
"#load('https://sage.unex.es/501708/SAGE/simplex2023AutoREVISED.sage')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|rr}\n",
"{Basic} & {x}_{1} & {x}_{2} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} & {b_1} \\\\\n",
"\\hline\n",
" {x}_{2} & 0 & 1 & 0 & 0 & 1 & 10000 & 0 \\\\\n",
"{x}_{1} & 1 & 0 & 50 & 0 & -\\frac{5}{8} & 2250 & 50 \\\\\n",
"{\\color{green}{s}}_{2} & 0 & 0 & -50 & 1 & \\frac{5}{8} & 4750 & -50 \\\\\n",
"\\hline\n",
" {Z_{ind}} & 0 & 0 & -1500 & 0 & -\\frac{5}{4} & 267500 & 1500\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 s1 s2 s3| rhs rhs1]\n",
"[------+----------------------------------+-------------]\n",
"[ x2| 0 1 0 0 1| 10000 0]\n",
"[ x1| 1 0 50 0 -5/8| 2250 50]\n",
"[ s2| 0 0 -50 1 5/8| 4750 -50]\n",
"[------+----------------------------------+-------------]\n",
"[ Z| 0 0 -1500 0 -5/4|267500 1500]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"b1p=matrix(QQ,m,1,[1,0,0]); param1b(b1p)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrr|rr}\n",
"{Basic} & {x}_{1} & {x}_{2} & {\\color{green}{s}}_{1} & {\\color{green}{s}}_{2} & {\\color{green}{s}}_{3} & {b} & {b_1} \\\\\n",
"\\hline\n",
" {x}_{2} & 0 & 1 & 0 & 0 & 1 & 10000 & 0 \\\\\n",
"{x}_{1} & 1 & 0 & 0 & 1 & 0 & 7000 & 0 \\\\\n",
"{\\color{green}{s}}_{1} & 0 & 0 & 1 & -\\frac{1}{50} & -\\frac{1}{80} & -95 & 1 \\\\\n",
"\\hline\n",
" {Z_{ind}} & 0 & 0 & 0 & -30 & -20 & 410000 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 s1 s2 s3| rhs rhs1]\n",
"[------+----------------------------------+-------------]\n",
"[ x2| 0 1 0 0 1| 10000 0]\n",
"[ x1| 1 0 0 1 0| 7000 0]\n",
"[ s1| 0 0 1 -1/50 -1/80| -95 1]\n",
"[------+----------------------------------+-------------]\n",
"[ Z| 0 0 0 -30 -20|410000 0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(3,3)"
]
}
],
"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
}