{
"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}{lcrcrcrcrcrcrcl}\n",
" \\min \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 3 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 5 x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{6} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 2 x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{4} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{6} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 10 \\\\\n",
" \\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} x_{3} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{5} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{6} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 15 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{1} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 2 x_{4} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} x_{5} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{6} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 25 \\\\\n",
"\\end{array} \\\\\n",
"x_{1}, x_{2}, x_{3}, x_{4}, x_{5}, x_{6} \\geq 0\n",
"\\end{array}$$"
],
"text/plain": [
"LP problem (use 'view(...)' or '%display typeset' for details)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\frac{615}{7}$$"
],
"text/plain": [
"615/7"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(0,\\,\\frac{25}{7},\\,\\frac{80}{7},\\,0,\\,\\frac{60}{7},\\,0\\right)$$"
],
"text/plain": [
"(0, 25/7, 80/7, 0, 60/7, 0)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{===================================}$$"
],
"text/plain": [
"ry"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}{}$$"
],
"text/plain": [
"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|rrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
"\\hline\n",
" {\\color{red}{t}}_{1} & 2 & 2 & 1 & 2 & -1 & 1 & 1 & 0 & 0 & 10 \\\\\n",
"{\\color{red}{t}}_{2} & 1 & 5 & -1 & -1 & 1 & -1 & 0 & 1 & 0 & 15 \\\\\n",
"{\\color{red}{t}}_{3} & -1 & 3 & 2 & -2 & -1 & 1 & 0 & 0 & 1 & 25 \\\\\n",
"\\hline\n",
" {W_{ind}} & -2 & -10 & -2 & 1 & 1 & -1 & 0 & 0 & 0 & 50\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3|rhs]\n",
"[---+-----------------------------------+---]\n",
"[ t1| 2 2 1 2 -1 1 1 0 0| 10]\n",
"[ t2| 1 5 -1 -1 1 -1 0 1 0| 15]\n",
"[ t3| -1 3 2 -2 -1 1 0 0 1| 25]\n",
"[---+-----------------------------------+---]\n",
"[ W| -2 -10 -2 1 1 -1 0 0 0| 50]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tipo ='min' # Problema de tipo max o min\n",
"\n",
"n=6 # 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,[3,3,3,1,5,2] ) # vector de costos\n",
"\n",
"A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n",
"[2,2,1,2,-1,1],\n",
"[1,5,-1,-1,1,-1],\n",
"[-1,3,2,-2,-1,1]\n",
"])\n",
"\n",
"b=matrix(QQ,m,1,[10,15,25]) # vector de la derecha\n",
"\n",
"\n",
"h=matrix(ZZ,1,m,[0,0,0]) # variables de holgura: \n",
" # Pon 1 si va sumando, \n",
" # -1 si va restando y \n",
" # 0 si no hay variable de holgura.\n",
" \n",
"t=matrix(ZZ,1,m,[1,1,1]) # 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=(7,8,9) # posición de la matriz identidad\n",
"\n",
"\n",
" \n",
" \n",
"####################################################################\n",
"############ HASTA AQUÍ LOS DATOS ################################\n",
"####################################################################\n",
"\n",
"\n",
"\n",
"\n",
"load('https://sage.unex.es/501708/simplex2023CompletamenteManual.sage')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[2.8571]\n",
"[ NO]\n",
"[ NO]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cocientes(6)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
"\\hline\n",
" {\\color{red}{t}}_{1} & \\frac{8}{5} & 0 & \\frac{7}{5} & \\frac{12}{5} & -\\frac{7}{5} & \\frac{7}{5} & 1 & -\\frac{2}{5} & 0 & 4 \\\\\n",
"{x}_{2} & \\frac{1}{5} & 1 & -\\frac{1}{5} & -\\frac{1}{5} & \\frac{1}{5} & -\\frac{1}{5} & 0 & \\frac{1}{5} & 0 & 3 \\\\\n",
"{\\color{red}{t}}_{3} & -\\frac{8}{5} & 0 & \\frac{13}{5} & -\\frac{7}{5} & -\\frac{8}{5} & \\frac{8}{5} & 0 & -\\frac{3}{5} & 1 & 16 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 0 & -4 & -1 & 3 & -3 & 0 & 2 & 0 & 20\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3| rhs]\n",
"[----+--------------------------------------------+----]\n",
"[ t1| 8/5 0 7/5 12/5 -7/5 7/5 1 -2/5 0| 4]\n",
"[ x2| 1/5 1 -1/5 -1/5 1/5 -1/5 0 1/5 0| 3]\n",
"[ t3|-8/5 0 13/5 -7/5 -8/5 8/5 0 -3/5 1| 16]\n",
"[----+--------------------------------------------+----]\n",
"[ W| 0 0 -4 -1 3 -3 0 2 0| 20]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(2,2)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & \\frac{8}{7} & 0 & 1 & \\frac{12}{7} & -1 & 1 & \\frac{5}{7} & -\\frac{2}{7} & 0 & \\frac{20}{7} \\\\\n",
"{x}_{2} & \\frac{3}{7} & 1 & 0 & \\frac{1}{7} & 0 & 0 & \\frac{1}{7} & \\frac{1}{7} & 0 & \\frac{25}{7} \\\\\n",
"{\\color{red}{t}}_{3} & -\\frac{32}{7} & 0 & 0 & -\\frac{41}{7} & 1 & -1 & -\\frac{13}{7} & \\frac{1}{7} & 1 & \\frac{60}{7} \\\\\n",
"\\hline\n",
" {W_{ind}} & \\frac{32}{7} & 0 & 0 & \\frac{41}{7} & -1 & 1 & \\frac{20}{7} & \\frac{6}{7} & 0 & \\frac{60}{7}\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6 t1 t2 t3| rhs]\n",
"[-----+-----------------------------------------------------+-----]\n",
"[ x3| 8/7 0 1 12/7 -1 1 5/7 -2/7 0| 20/7]\n",
"[ x2| 3/7 1 0 1/7 0 0 1/7 1/7 0| 25/7]\n",
"[ t3|-32/7 0 0 -41/7 1 -1 -13/7 1/7 1| 60/7]\n",
"[-----+-----------------------------------------------------+-----]\n",
"[ W| 32/7 0 0 41/7 -1 1 20/7 6/7 0| 60/7]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(1,3)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & -\\frac{24}{7} & 0 & 1 & -\\frac{29}{7} & 0 & 0 & -\\frac{8}{7} & -\\frac{1}{7} & 1 & \\frac{80}{7} \\\\\n",
"{x}_{2} & \\frac{3}{7} & 1 & 0 & \\frac{1}{7} & 0 & 0 & \\frac{1}{7} & \\frac{1}{7} & 0 & \\frac{25}{7} \\\\\n",
"{x}_{5} & -\\frac{32}{7} & 0 & 0 & -\\frac{41}{7} & 1 & -1 & -\\frac{13}{7} & \\frac{1}{7} & 1 & \\frac{60}{7} \\\\\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 x4 x5 x6 t1 t2 t3| rhs]\n",
"[-----+-----------------------------------------------------+-----]\n",
"[ x3|-24/7 0 1 -29/7 0 0 -8/7 -1/7 1| 80/7]\n",
"[ x2| 3/7 1 0 1/7 0 0 1/7 1/7 0| 25/7]\n",
"[ x5|-32/7 0 0 -41/7 1 -1 -13/7 1/7 1| 60/7]\n",
"[-----+-----------------------------------------------------+-----]\n",
"[ W| 0 0 0 0 0 0 1 1 1| 0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(3,5)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\begin{array}{r|rrrrrr|r}\n",
"{Basic} & {x}_{1} & {x}_{2} & {x}_{3} & {x}_{4} & {x}_{5} & {x}_{6} & {b} \\\\\n",
"\\hline\n",
" {x}_{3} & -\\frac{24}{7} & 0 & 1 & -\\frac{29}{7} & 0 & 0 & \\frac{80}{7} \\\\\n",
"{x}_{2} & \\frac{3}{7} & 1 & 0 & \\frac{1}{7} & 0 & 0 & \\frac{25}{7} \\\\\n",
"{x}_{5} & -\\frac{32}{7} & 0 & 0 & -\\frac{41}{7} & 1 & -1 & \\frac{60}{7} \\\\\n",
"\\hline\n",
" {Z_{ind}} & \\frac{244}{7} & 0 & 0 & \\frac{296}{7} & 0 & 7 & \\frac{615}{7}\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 x6| rhs]\n",
"[-----+-----------------------------------+-----]\n",
"[ x3|-24/7 0 1 -29/7 0 0| 80/7]\n",
"[ x2| 3/7 1 0 1/7 0 0| 25/7]\n",
"[ x5|-32/7 0 0 -41/7 1 -1| 60/7]\n",
"[-----+-----------------------------------+-----]\n",
"[ Z|244/7 0 0 296/7 0 7|615/7]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tt=[0,0,0];faseII(0,tt);"
]
}
],
"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
}