{
"cells": [
{
"cell_type": "code",
"execution_count": 29,
"id": "8dee9577",
"metadata": {},
"outputs": [
{
"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}{lcrcrcrcrcrcl}\n",
" \\max \\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} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{5} \\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} 4 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{5} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 2 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 3 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} + \\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} 6 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 2 x_{1} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 2 x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 3 x_{5} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 7 \\\\\n",
" \\mspace{-6mu}&\\mspace{-6mu} \\mspace{-6mu}&\\mspace{-6mu} 6 x_{1} \\mspace{-6mu}&\\mspace{-6mu} - \\mspace{-6mu}&\\mspace{-6mu} 3 x_{2} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} x_{3} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 5 x_{4} \\mspace{-6mu}&\\mspace{-6mu} + \\mspace{-6mu}&\\mspace{-6mu} 6 x_{5} \\mspace{-6mu}&\\mspace{-6mu} = \\mspace{-6mu}&\\mspace{-6mu} 15 \\\\\n",
"\\end{array} \\\\\n",
"x_{1}, x_{2}, x_{3}, x_{4}, x_{5} \\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{39}{4}$$"
],
"text/plain": [
"39/4"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/latex": [
"$$\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left(\\frac{7}{2},\\,\\frac{21}{4},\\,\\frac{39}{4},\\,0,\\,0\\right)$$"
],
"text/plain": [
"(7/2, 21/4, 39/4, 0, 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} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {\\color{red}{t}}_{1} & 1 & -4 & 2 & 1 & 2 & 1 & 0 & 0 & 0 & 2 \\\\\n",
"{\\color{red}{t}}_{2} & 3 & 1 & -1 & 2 & 1 & 0 & 1 & 0 & 0 & 6 \\\\\n",
"{\\color{red}{t}}_{3} & 2 & 0 & 0 & 2 & 3 & 0 & 0 & 1 & 0 & 7 \\\\\n",
"{\\color{red}{t}}_{4} & 6 & -3 & 1 & 5 & 6 & 0 & 0 & 0 & 1 & 15 \\\\\n",
"\\hline\n",
" {W_{ind}} & -12 & 6 & -2 & -10 & -12 & 0 & 0 & 0 & 0 & 30\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 t1 t2 t3 t4|rhs]\n",
"[---+-----------------------------------+---]\n",
"[ t1| 1 -4 2 1 2 1 0 0 0| 2]\n",
"[ t2| 3 1 -1 2 1 0 1 0 0| 6]\n",
"[ t3| 2 0 0 2 3 0 0 1 0| 7]\n",
"[ t4| 6 -3 1 5 6 0 0 0 1| 15]\n",
"[---+-----------------------------------+---]\n",
"[ W|-12 6 -2 -10 -12 0 0 0 0| 30]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tipo ='max' # Problema de tipo max o min\n",
"\n",
"n=5 # número de variables x's\n",
"m=4 # número de restricciones (distintas de las de signo)\n",
"\n",
"c=matrix(QQ,1,n,[3,-2,1,2,3] ) # vector de costos\n",
"\n",
"A=matrix(QQ,m,n,[ # coeficientes de las variables x's\n",
"[1,-4,2,1,2],\n",
"[3,1,-1,2,1],\n",
"[2,0,0,2,3],\n",
"[6,-3,1,5,6]\n",
"])\n",
"\n",
"b=matrix(QQ,m,1,[2,6,7,15]) # vector de la derecha\n",
"\n",
"\n",
"h=matrix(ZZ,1,m,[0,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,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=(6,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": 30,
"id": "f5e4b055",
"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} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{1} & 1 & -4 & 2 & 1 & 2 & 1 & 0 & 0 & 0 & 2 \\\\\n",
"{\\color{red}{t}}_{2} & 0 & 13 & -7 & -1 & -5 & -3 & 1 & 0 & 0 & 0 \\\\\n",
"{\\color{red}{t}}_{3} & 0 & 8 & -4 & 0 & -1 & -2 & 0 & 1 & 0 & 3 \\\\\n",
"{\\color{red}{t}}_{4} & 0 & 21 & -11 & -1 & -6 & -6 & 0 & 0 & 1 & 3 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & -42 & 22 & 2 & 12 & 12 & 0 & 0 & 0 & 6\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 t1 t2 t3 t4|rhs]\n",
"[---+-----------------------------------+---]\n",
"[ x1| 1 -4 2 1 2 1 0 0 0| 2]\n",
"[ t2| 0 13 -7 -1 -5 -3 1 0 0| 0]\n",
"[ t3| 0 8 -4 0 -1 -2 0 1 0| 3]\n",
"[ t4| 0 21 -11 -1 -6 -6 0 0 1| 3]\n",
"[---+-----------------------------------+---]\n",
"[ W| 0 -42 22 2 12 12 0 0 0| 6]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(1,1)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "b224b027",
"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} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{1} & 1 & 0 & -\\frac{2}{13} & \\frac{9}{13} & \\frac{6}{13} & \\frac{1}{13} & \\frac{4}{13} & 0 & 0 & 2 \\\\\n",
"{x}_{2} & 0 & 1 & -\\frac{7}{13} & -\\frac{1}{13} & -\\frac{5}{13} & -\\frac{3}{13} & \\frac{1}{13} & 0 & 0 & 0 \\\\\n",
"{\\color{red}{t}}_{3} & 0 & 0 & \\frac{4}{13} & \\frac{8}{13} & \\frac{27}{13} & -\\frac{2}{13} & -\\frac{8}{13} & 1 & 0 & 3 \\\\\n",
"{\\color{red}{t}}_{4} & 0 & 0 & \\frac{4}{13} & \\frac{8}{13} & \\frac{27}{13} & -\\frac{15}{13} & -\\frac{21}{13} & 0 & 1 & 3 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 0 & -\\frac{8}{13} & -\\frac{16}{13} & -\\frac{54}{13} & \\frac{30}{13} & \\frac{42}{13} & 0 & 0 & 6\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 t1 t2 t3 t4| rhs]\n",
"[------+--------------------------------------------------------------+------]\n",
"[ x1| 1 0 -2/13 9/13 6/13 1/13 4/13 0 0| 2]\n",
"[ x2| 0 1 -7/13 -1/13 -5/13 -3/13 1/13 0 0| 0]\n",
"[ t3| 0 0 4/13 8/13 27/13 -2/13 -8/13 1 0| 3]\n",
"[ t4| 0 0 4/13 8/13 27/13 -15/13 -21/13 0 1| 3]\n",
"[------+--------------------------------------------------------------+------]\n",
"[ W| 0 0 -8/13 -16/13 -54/13 30/13 42/13 0 0| 6]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(2,2)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "709be7fa",
"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} & {\\color{red}{t}}_{1} & {\\color{red}{t}}_{2} & {\\color{red}{t}}_{3} & {\\color{red}{t}}_{4} & {b} \\\\\n",
"\\hline\n",
" {x}_{1} & 1 & 0 & -\\frac{2}{9} & \\frac{5}{9} & 0 & \\frac{1}{9} & \\frac{4}{9} & -\\frac{2}{9} & 0 & \\frac{4}{3} \\\\\n",
"{x}_{2} & 0 & 1 & -\\frac{13}{27} & \\frac{1}{27} & 0 & -\\frac{7}{27} & -\\frac{1}{27} & \\frac{5}{27} & 0 & \\frac{5}{9} \\\\\n",
"{x}_{5} & 0 & 0 & \\frac{4}{27} & \\frac{8}{27} & 1 & -\\frac{2}{27} & -\\frac{8}{27} & \\frac{13}{27} & 0 & \\frac{13}{9} \\\\\n",
"{\\color{red}{t}}_{4} & 0 & 0 & 0 & 0 & 0 & -1 & -1 & -1 & 1 & 0 \\\\\n",
"\\hline\n",
" {W_{ind}} & 0 & 0 & 0 & 0 & 0 & 2 & 2 & 2 & 0 & 0\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5 t1 t2 t3 t4| rhs]\n",
"[------+--------------------------------------------------------------+------]\n",
"[ x1| 1 0 -2/9 5/9 0 1/9 4/9 -2/9 0| 4/3]\n",
"[ x2| 0 1 -13/27 1/27 0 -7/27 -1/27 5/27 0| 5/9]\n",
"[ x5| 0 0 4/27 8/27 1 -2/27 -8/27 13/27 0| 13/9]\n",
"[ t4| 0 0 0 0 0 -1 -1 -1 1| 0]\n",
"[------+--------------------------------------------------------------+------]\n",
"[ W| 0 0 0 0 0 2 2 2 0| 0]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cambio(3,5)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "8bc3eb06",
"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} & {x}_{4} & {x}_{5} & {b} \\\\\n",
"\\hline\n",
" {x}_{1} & 1 & 0 & -\\frac{2}{9} & \\frac{5}{9} & 0 & \\frac{4}{3} \\\\\n",
"{x}_{2} & 0 & 1 & -\\frac{13}{27} & \\frac{1}{27} & 0 & \\frac{5}{9} \\\\\n",
"{x}_{5} & 0 & 0 & \\frac{4}{27} & \\frac{8}{27} & 1 & \\frac{13}{9} \\\\\n",
"\\hline\n",
" {Z_{ind}} & 0 & 0 & \\frac{7}{27} & -\\frac{13}{27} & 0 & \\frac{65}{9}\n",
"\\end{array}\\right)$$"
],
"text/plain": [
"[ B| x1 x2 x3 x4 x5| rhs]\n",
"[------+----------------------------------+------]\n",
"[ x1| 1 0 -2/9 5/9 0| 4/3]\n",
"[ x2| 0 1 -13/27 1/27 0| 5/9]\n",
"[ x5| 0 0 4/27 8/27 1| 13/9]\n",
"[------+----------------------------------+------]\n",
"[ Z| 0 0 7/27 -13/27 0| 65/9]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tt=(0,0,0,1); faseII(1,tt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e706c2d",
"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
}