{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Laboratorio 01\n", "### Curso MA4702 año 2024" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Datos grupo\n", "\n", "Escriba en esta celda el nombre de cada integrante de su grupo.\n", "\n", "- Integrante 1: XXX\n", "\n", "- Integrante 2: YYY\n", "\n", "- Integrante 3: ZZZ\n", "\n", "- Integrante 4: WWW..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Preparacion." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Manifest.toml`\n", "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Manifest.toml`\n", "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Manifest.toml`\n", "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Manifest.toml`\n", "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\spuky\\.julia\\environments\\v1.10\\Manifest.toml`\n" ] } ], "source": [ "using Pkg\n", "Pkg.add(\"JuMP\")\n", "Pkg.add(\"Gurobi\")\n", "Pkg.add(\"CSV\")\n", "Pkg.add(\"Combinatorics\")\n", "Pkg.add(\"DataFrames\")\n", "\n", "# Nota: Luego de instalar estos paquetes\n", "# comente todas las lineas anteriores para que no\n", "# vuelvan a cargarse cuando ejecute el archivo nuevamente\n", "import Pkg\n", "\n", "using JuMP, Gurobi, CSV, Combinatorics, DataFrames" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "leegrafo (generic function with 1 method)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#La siguiente funcion recibe un archivo .csv (tipo estándar para recibir datos) que corresponde a una tabla con 3 columnas de datos donde\n", "# **la primera fila es de la forma n 0 0 y el resto son cero o mas lineas con valores i j w[i j]**\n", "\n", "# la función devuelve un valor n (número de nodos), el conjunto de aristas E \n", "# donde cada arista e en E es un arreglo [e[1],e[2]] con e[1]=15 && sum(X)<=16\n", " println(X)\n", " end\n", "end" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\begin{verbatim}\n", "@elapsed\n", "\\end{verbatim}\n", "A macro to evaluate an expression, discarding the resulting value, instead returning the number of seconds it took to execute as a floating-point number.\n", "\n", "In some cases the system will look inside the \\texttt{@elapsed} expression and compile some of the called code before execution of the top-level expression begins. When that happens, some compilation time will not be counted. To include this time you can run \\texttt{@elapsed @eval ...}.\n", "\n", "See also \\href{@ref}{\\texttt{@time}}, \\href{@ref}{\\texttt{@timev}}, \\href{@ref}{\\texttt{@timed}}, \\href{@ref}{\\texttt{@allocated}}, and \\href{@ref}{\\texttt{@allocations}}.\n", "\n", "\\begin{verbatim}\n", "julia> @elapsed sleep(0.3)\n", "0.301391426\n", "\\end{verbatim}\n" ], "text/markdown": [ "```\n", "@elapsed\n", "```\n", "\n", "A macro to evaluate an expression, discarding the resulting value, instead returning the number of seconds it took to execute as a floating-point number.\n", "\n", "In some cases the system will look inside the `@elapsed` expression and compile some of the called code before execution of the top-level expression begins. When that happens, some compilation time will not be counted. To include this time you can run `@elapsed @eval ...`.\n", "\n", "See also [`@time`](@ref), [`@timev`](@ref), [`@timed`](@ref), [`@allocated`](@ref), and [`@allocations`](@ref).\n", "\n", "```julia-repl\n", "julia> @elapsed sleep(0.3)\n", "0.301391426\n", "```\n" ], "text/plain": [ "\u001b[36m @elapsed\u001b[39m\n", "\n", " A macro to evaluate an expression, discarding the resulting value, instead\n", " returning the number of seconds it took to execute as a floating-point\n", " number.\n", "\n", " In some cases the system will look inside the \u001b[36m@elapsed\u001b[39m expression and\n", " compile some of the called code before execution of the top-level expression\n", " begins. When that happens, some compilation time will not be counted. To\n", " include this time you can run \u001b[36m@elapsed @eval ...\u001b[39m.\n", "\n", " See also \u001b[36m@time\u001b[39m, \u001b[36m@timev\u001b[39m, \u001b[36m@timed\u001b[39m, \u001b[36m@allocated\u001b[39m, and \u001b[36m@allocations\u001b[39m.\n", "\n", "\u001b[36m julia> @elapsed sleep(0.3)\u001b[39m\n", "\u001b[36m 0.301391426\u001b[39m" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "?@elapsed" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Me demoré 0.0051635 segundos en calcular un arreglo de tamaño 39203" ] } ], "source": [ "#Guarda en \"a\" el tiempo en segundos necesarios para construir al conjunto A de todos los subconjuntos de tamaño entre 0 y 8 de [16]\n", "a=@elapsed (A=collect(powerset(1:16,0,8)))\n", "print(String(\"Me demoré $a segundos en calcular un arreglo de tamaño $(size(A,1))\"))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
4×3 DataFrame
Rowprimer_datosegundo_datotiempo
Int8Int8Float64
1000.12
2100.5
3011.99
4115.99
" ], "text/latex": [ "\\begin{tabular}{r|ccc}\n", "\t& primer\\_dato & segundo\\_dato & tiempo\\\\\n", "\t\\hline\n", "\t& Int8 & Int8 & Float64\\\\\n", "\t\\hline\n", "\t1 & 0 & 0 & 0.12 \\\\\n", "\t2 & 1 & 0 & 0.5 \\\\\n", "\t3 & 0 & 1 & 1.99 \\\\\n", "\t4 & 1 & 1 & 5.99 \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m4×3 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m primer_dato \u001b[0m\u001b[1m segundo_dato \u001b[0m\u001b[1m tiempo \u001b[0m\n", " │\u001b[90m Int8 \u001b[0m\u001b[90m Int8 \u001b[0m\u001b[90m Float64 \u001b[0m\n", "─────┼────────────────────────────────────\n", " 1 │ 0 0 0.12\n", " 2 │ 1 0 0.5\n", " 3 │ 0 1 1.99\n", " 4 │ 1 1 5.99" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Usando dataframe, ejemplo ficticio de uso\n", "\n", "df = DataFrame(primer_dato = Int8[], segundo_dato = Int8[], tiempo = Float64[]) #datos y tipos\n", "push!(df, [0, 0, 0.12])\n", "push!(df, [1, 0, 0.50])\n", "push!(df, [0, 1, 1.99])\n", "push!(df, [1, 1, 5.99])\n", "display(df)\n", "\n", "#por ahora solo usaremos push! para poner datos en un dataframe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Ejercicios\n", "\n", "En el pdf de marco teórico usted encontrará 5 modelos diferentes para el problema de MST sobre un grafo $G = (V,E)$ con pesos positivos $w\\colon E \\to \\mathbb{R}^+$.\n", "\n", "Para cada modelo (digamos que se llama nombre) se le pedirá lo siguiente\n", "\n", "1. Escribir una funcion modelo_nombre(n,E,w) que reciba valores N, E, w descritos anteriormente \n", " y que devuelva un modelo en JuMP\n", " \n", "2. Resolver el modelo en una instancia de prueba ubicado en el archivo \"grafo1.csv\"\n", " y añadir instrucciones para que muestre en la pantalla el valor del MST encontrado y el conjunto de aristas del MST encontrado \n", " \n", "3. Escribir una función sin entrada, que genere un dataframe a partir de las instancias \"grafo1.csv\" hasta \"grafo9.csv\" donde cada fila consista en el nombre de una instancia, su valor objetivo, su tiempo de creación del modelo, y su tiempo de optimización.\n", "\n", "4. Ejecutar la función anterior y mostrar el dataframe resultante.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ejercicio 1. Modelo corte\n", "$$\n", "\\begin{align*}\n", "(\\text{M1}) \\quad \\min \\sum_{e\\in E}&w_e x_e\\\\\n", "x(\\delta_E(S))&\\geq 1, \\qquad \\text{para todo $S\\subseteq V, S\\neq \\emptyset, S\\neq V$.}\\\\\n", "x(E) &= n-1\\\\\n", "0\\leq x_e &\\leq 1, \\qquad \\text{para todo $e\\in E$}\\\\\n", "x_e &\\in \\mathbb{Z}\n", "\\end{align*}\n", "$$" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "modelo_cortes (generic function with 1 method)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Escribir funcion\n", "\n", "function modelo_cortes(N,E,w)\n", " # 1. Crear modelo, asignar Gurobi como el optimizador\n", " mimodelo = Model()\n", " set_optimizer(mimodelo, Gurobi.Optimizer)\n", " set_attribute(mimodelo, \"output_flag\", false)\n", " \n", " # 2. Declarar variables de decisión (recomendamos usar este formato)\n", " @variable(mimodelo, 0<=x[i in 1:N,j in 1:N; [i,j] in E]<=1, Int) \n", " \n", " #3. Función objetivo\n", " @objective(mimodelo, Min, sum(x[e[1],e[2]]*w[e] for e in E))\n", "\n", " # 3. Escribir restricciones (llenar)\n", " @constraint(mimodelo, corte[S in powerset(1:N, 1, N-1)], \n", " sum(x[e[1],e[2]] for e in E if ( (e[1] in S && !(e[2] in S)) || ((e[2] in S && !(e[1] in S)))) ) >=1)\n", " @constraint(mimodelo, cardinalidadtotal, sum(x)==N-1)\n", " \n", " return mimodelo\n", "end\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Grafo con 8 nodos y 15 aristas\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Demoré 4.7593764 segundos en crear el modelo y 2.3572849 en resolverlo\n", "El valor objetivo es: 35.0\n", "El conjunto de aristas es: [[1, 2], [1, 3], [1, 6], [1, 8], [2, 3], [2, 5], [3, 4], [3, 8], [4, 5], [4, 7], [4, 8], [5, 6], [5, 7], [6, 7], [7, 8]]\n" ] } ], "source": [ "# Resolver MST, usando el modelo, en una instancia de prueba ubicado en el archivo \"grafo1.csv\". \n", "N,E,w=leegrafo(\"grafo1.csv\")\n", "println(\"Grafo con $N nodos y $(size(E,1)) aristas\")\n", "tiempo_modelo= @elapsed ( mimodelo = modelo_cortes(N,E,w));\n", "tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", "println(String(\"Demoré $tiempo_modelo segundos en crear el modelo y $tiempo_ejecucion en resolverlo\"))\n", "println(String(\"El valor objetivo es: $(objective_value(mimodelo))\"))\n", "println(String(\"El conjunto de aristas es: $E\"))\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "prueba_cortes (generic function with 1 method)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Escribir una función sin entrada, que genere un dataframe a partir de las instancias \"grafo1.csv\" hasta \"grafo5.csv\" \n", "# donde cada fila consista en el nombre de una instancia, su valor objetivo, su tiempo de creación del modelo, y su tiempo de optimización.\n", "\n", "function prueba_cortes()\n", " dfcortes = DataFrame(nombre = String[], num_nodos = Int[], num_aristas = Int[], num_vars=Int[], num_rest=Int[], valor_objetivo = Float64[], tiempo_modelo = Float64[], tiempo_ejecucion = Float64[]) #datos y tipos\n", " for i in 1:5\n", " archivo=String(\"grafo$i.csv\")\n", " N,E,w=leegrafo(archivo)\n", " tiempo_modelo= @elapsed mimodelo = modelo_cortes(N,E,w);\n", " tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", " valor_objetivo = objective_value(mimodelo)\n", " nc=num_constraints(mimodelo, count_variable_in_set_constraints=false)\n", " nv=num_variables(mimodelo)\n", " push!(dfcortes, [archivo, N, size(E,1),nv,nc, valor_objetivo, tiempo_modelo, tiempo_ejecucion])\n", " end\n", " return dfcortes\n", "end" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
5×8 DataFrame
Rownombrenum_nodosnum_aristasnum_varsnum_restvalor_objetivotiempo_modelotiempo_ejecucion
StringInt64Int64Int64Int64Float64Float64Float64
1grafo1.csv8151525535.00.00437140.006689
2grafo2.csv1034341023233.00.01146880.0431255
3grafo3.csv1241414095159.00.04120890.172429
4grafo4.csv14696916383110.00.3109041.73213
5grafo5.csv16797965535201.01.261456.34218
" ], "text/latex": [ "\\begin{tabular}{r|cccccccc}\n", "\t& nombre & num\\_nodos & num\\_aristas & num\\_vars & num\\_rest & valor\\_objetivo & tiempo\\_modelo & \\\\\n", "\t\\hline\n", "\t& String & Int64 & Int64 & Int64 & Int64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & grafo1.csv & 8 & 15 & 15 & 255 & 35.0 & 0.0043714 & $\\dots$ \\\\\n", "\t2 & grafo2.csv & 10 & 34 & 34 & 1023 & 233.0 & 0.0114688 & $\\dots$ \\\\\n", "\t3 & grafo3.csv & 12 & 41 & 41 & 4095 & 159.0 & 0.0412089 & $\\dots$ \\\\\n", "\t4 & grafo4.csv & 14 & 69 & 69 & 16383 & 110.0 & 0.310904 & $\\dots$ \\\\\n", "\t5 & grafo5.csv & 16 & 79 & 79 & 65535 & 201.0 & 1.26145 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m5×8 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m nombre \u001b[0m\u001b[1m num_nodos \u001b[0m\u001b[1m num_aristas \u001b[0m\u001b[1m num_vars \u001b[0m\u001b[1m num_rest \u001b[0m\u001b[1m valor_objetivo \u001b[0m\u001b[1m\u001b[0m ⋯\n", " │\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ grafo1.csv 8 15 15 255 35.0 ⋯\n", " 2 │ grafo2.csv 10 34 34 1023 233.0\n", " 3 │ grafo3.csv 12 41 41 4095 159.0\n", " 4 │ grafo4.csv 14 69 69 16383 110.0\n", " 5 │ grafo5.csv 16 79 79 65535 201.0 ⋯\n", "\u001b[36m 2 columns omitted\u001b[0m" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Ejecutar prueba\n", "df=prueba_cortes()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ejercicio 2. Modelo ciclos\n", "\n", "$$\n", "\\begin{align*}\n", "(\\text{M2}) \\quad \\min \\sum_{e\\in E}&w_e x_e\\\\\n", "x(E[S])&\\leq |S|-1, \\qquad \\text{para todo $S\\subseteq V, S\\neq \\emptyset, S\\neq V$.}\\\\\n", "x(E) &= n-1\\\\\n", "0\\leq x_e &\\leq 1, \\qquad \\text{para todo $e\\in E$}\\\\\n", "x_e &\\in \\mathbb{Z}\n", "\\end{align*}\n", "$$" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "modelo_ciclos (generic function with 1 method)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function modelo_ciclos(N,E,w)\n", " # 1. Crear modelo, asignar Gurobi como el optimizador\n", " mimodelo = Model()\n", " set_optimizer(mimodelo, Gurobi.Optimizer)\n", " set_attribute(mimodelo, \"output_flag\", false)\n", " \n", " # 2. Declarar variables de decisión (recomendamos usar este formato)\n", " @variable(mimodelo, 0<=x[i in 1:N,j in 1:N; [i,j] in E]<=1, Int) \n", " \n", " #3. Función objetivo\n", " @objective(mimodelo, Min, sum(x[e[1],e[2]]*w[e] for e in E))\n", "\n", " # 3. Escribir restricciones (llenar)\n", " @constraint(mimodelo, corte[S in powerset(1:N, 1, N-1)], \n", " sum(x[e[1],e[2]] for e in E if ( (e[1] in S && (e[2] in S)) )) <= size(S,1)-1)\n", " @constraint(mimodelo, cardinalidadtotal, sum(x)==N-1)\n", " \n", " return mimodelo\n", "end" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Grafo con 8 nodos y 15 aristas\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Demoré 0.6031611 segundos en crear el modelo y 0.1098311 en resolverlo\n", "El valor objetivo es: 35.0\n", "El conjunto de aristas es: [[1, 2], [1, 3], [1, 6], [1, 8], [2, 3], [2, 5], [3, 4], [3, 8], [4, 5], [4, 7], [4, 8], [5, 6], [5, 7], [6, 7], [7, 8]]\n" ] } ], "source": [ "# Resolver MST, usando el modelo, en una instancia de prueba ubicado en el archivo \"grafo1.csv\". \n", "N,E,w=leegrafo(\"grafo1.csv\")\n", "println(\"Grafo con $N nodos y $(size(E,1)) aristas\")\n", "tiempo_modelo= @elapsed ( mimodelo = modelo_ciclos(N,E,w));\n", "tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", "println(String(\"Demoré $tiempo_modelo segundos en crear el modelo y $tiempo_ejecucion en resolverlo\"))\n", "println(String(\"El valor objetivo es: $(objective_value(mimodelo))\"))\n", "println(String(\"El conjunto de aristas es: $E\"))\n", "\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "prueba_ciclos (generic function with 1 method)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Escribir una función sin entrada, que genere un dataframe a partir de las instancias \"grafo1.csv\" hasta \"grafo9.csv\" \n", "# donde cada fila consista en el nombre de una instancia, su valor objetivo, su tiempo de creación del modelo, y su tiempo de optimización.\n", "\n", "function prueba_ciclos()\n", " dfcortes = DataFrame(nombre = String[], num_nodos = Int[], num_aristas = Int[], num_vars=Int[], num_rest=Int[], valor_objetivo = Float64[], tiempo_modelo = Float64[], tiempo_ejecucion = Float64[]) #datos y tipos\n", " for i in 1:5\n", " archivo=String(\"grafo$i.csv\")\n", " N,E,w=leegrafo(archivo)\n", " tiempo_modelo= @elapsed mimodelo = modelo_ciclos(N,E,w);\n", " tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", " valor_objetivo = objective_value(mimodelo)\n", " nc=num_constraints(mimodelo, count_variable_in_set_constraints=false)\n", " nv=num_variables(mimodelo)\n", " push!(dfcortes, [archivo, N, size(E,1),nv,nc, valor_objetivo, tiempo_modelo, tiempo_ejecucion])\n", " end\n", " return dfcortes\n", "end" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
5×8 DataFrame
Rownombrenum_nodosnum_aristasnum_varsnum_restvalor_objetivotiempo_modelotiempo_ejecucion
StringInt64Int64Int64Int64Float64Float64Float64
1grafo1.csv8151525535.00.00409830.004297
2grafo2.csv1034341023233.00.00903030.0272524
3grafo3.csv1241414095159.00.03066090.114233
4grafo4.csv14696916383110.00.5210821.22248
5grafo5.csv16797965535201.00.7276196.45226
" ], "text/latex": [ "\\begin{tabular}{r|cccccccc}\n", "\t& nombre & num\\_nodos & num\\_aristas & num\\_vars & num\\_rest & valor\\_objetivo & tiempo\\_modelo & \\\\\n", "\t\\hline\n", "\t& String & Int64 & Int64 & Int64 & Int64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & grafo1.csv & 8 & 15 & 15 & 255 & 35.0 & 0.0040983 & $\\dots$ \\\\\n", "\t2 & grafo2.csv & 10 & 34 & 34 & 1023 & 233.0 & 0.0090303 & $\\dots$ \\\\\n", "\t3 & grafo3.csv & 12 & 41 & 41 & 4095 & 159.0 & 0.0306609 & $\\dots$ \\\\\n", "\t4 & grafo4.csv & 14 & 69 & 69 & 16383 & 110.0 & 0.521082 & $\\dots$ \\\\\n", "\t5 & grafo5.csv & 16 & 79 & 79 & 65535 & 201.0 & 0.727619 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m5×8 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m nombre \u001b[0m\u001b[1m num_nodos \u001b[0m\u001b[1m num_aristas \u001b[0m\u001b[1m num_vars \u001b[0m\u001b[1m num_rest \u001b[0m\u001b[1m valor_objetivo \u001b[0m\u001b[1m\u001b[0m ⋯\n", " │\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ grafo1.csv 8 15 15 255 35.0 ⋯\n", " 2 │ grafo2.csv 10 34 34 1023 233.0\n", " 3 │ grafo3.csv 12 41 41 4095 159.0\n", " 4 │ grafo4.csv 14 69 69 16383 110.0\n", " 5 │ grafo5.csv 16 79 79 65535 201.0 ⋯\n", "\u001b[36m 2 columns omitted\u001b[0m" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Ejecutar funcion anterior\n", "df=prueba_ciclos()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ejercicio 3. Modelo arborescencia\n", "\n", "$$\\begin{align*}\n", "(\\text{M3}) \\quad \\min \\sum_{e\\in E}&w_e x_e\\\\\n", "x(E) &= n-1\\\\\n", "y_{i,j}+y_{j,i}&= x_e, \\qquad\\text{para todo $e=ij\\in E$}\\\\\n", "y(\\delta^-(i))&= 1, \\qquad \\text{para todo $i\\in V-r$}\\\\\n", "y(\\delta^-(r))&= 0,\\\\\n", "y_a&\\geq 0, \\qquad \\text{para todo $a\\in A$}\\\\\n", "0\\leq x_e &\\leq 1, \\qquad \\text{para todo $e\\in E$}\\\\\n", "x_e &\\in \\mathbb{Z}, \\qquad \\text{para todo $e\\in E$}\\\\\n", "y_a &\\in \\mathbb{Z}, \\qquad \\text{para todo $a\\in A$}\\\\\n", "\\end{align*}\n", "$$" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "modelo_arborescencia (generic function with 1 method)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function modelo_arborescencia(N,E,w)\n", " # nota: puede crear el conjunto A primero, use r=1\n", " # De preferencia acá indexe las variables \"y\" por pares ordenados \n", " # y[i in ..., j in...; [i,j] in ...], no por y[a in A], pues de esta ultima manera debe usar y[[i,j]] para trabajar.\n", " # ..\n", " # nota: No necesita usar for para crear restricciones simples, puede indexarlas directamente\n", " # @constraint(mimodelo, [i in 1:N], restriccion para i)\n", " # return mimodelo\n", "\n", " # 1. Crear modelo, asignar Gurobi como el optimizador\n", " r=1\n", " # se definen los arcos\n", " A=hcat(E,[[e[2],e[1]] for e in E]) \n", " # concatena horizontalmente (hcat) E con su reverso, es decir, para cada e in E los da vuelta y concatena\n", " \n", " mimodelo = Model()\n", " set_optimizer(mimodelo, Gurobi.Optimizer)\n", " set_attribute(mimodelo, \"output_flag\", false)\n", " \n", " # 2. Declarar variables de decisión (recomendamos usar este formato)\n", " @variable(mimodelo, 0<=x[i in 1:N,j in 1:N; [i,j] in E]<=1, Int) \n", " @variable(mimodelo, 0<=y[i in 1:N,j in 1:N; [i,j] in A], Int) \n", " \n", " #3. Función objetivo\n", " @objective(mimodelo, Min, sum(x[e[1],e[2]]*w[e] for e in E))\n", "\n", " # 3. Escribir restricciones (llenar)\n", " \n", " @constraint(mimodelo, cardinalidadtotal, sum(x)==N-1)\n", " @constraint(mimodelo, bidireccion[e in E], \n", " y[e[1],e[2]]+y[e[2],e[1]] == x[e[1],e[2]])\n", " @constraint(mimodelo, outroot, sum(y[r,j] for j in 1:N if [r,j] in A)==0)\n", " @constraint(mimodelo, outnonroot[i in 1:N; i != r], sum(y[i,j] for j in 1:N if [i,j] in A)==1)\n", " \n", " return mimodelo\n", "end" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Grafo con 8 nodos y 15 aristas\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Demoré 1.4184599 segundos en crear el modelo y 0.0040586 en resolverlo\n", "El valor objetivo es: 35.0\n", "El conjunto de aristas es: [[1, 2], [1, 3], [1, 6], [1, 8], [2, 3], [2, 5], [3, 4], [3, 8], [4, 5], [4, 7], [4, 8], [5, 6], [5, 7], [6, 7], [7, 8]]\n" ] } ], "source": [ "## Resolver MST, usando el modelo, en una instancia de prueba ubicado en el archivo \"grafo1.csv\". \n", "N,E,w=leegrafo(\"grafo1.csv\")\n", "println(\"Grafo con $N nodos y $(size(E,1)) aristas\")\n", "tiempo_modelo= @elapsed ( mimodelo = modelo_arborescencia(N,E,w));\n", "tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", "println(String(\"Demoré $tiempo_modelo segundos en crear el modelo y $tiempo_ejecucion en resolverlo\"))\n", "println(String(\"El valor objetivo es: $(objective_value(mimodelo))\"))\n", "println(String(\"El conjunto de aristas es: $E\"))\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "prueba_arborescencia (generic function with 1 method)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Escribir una función sin entrada, que genere un dataframe a partir de las instancias \"grafo1.csv\" hasta \"grafo9.csv\" \n", "# donde cada fila consista en el nombre de una instancia, su valor objetivo, su tiempo de creación del modelo, y su tiempo de optimización.\n", "\n", "function prueba_arborescencia()\n", " dfcortes = DataFrame(nombre = String[], num_nodos = Int[], num_aristas = Int[], num_vars=Int[], num_rest=Int[], valor_objetivo = Float64[], tiempo_modelo = Float64[], tiempo_ejecucion = Float64[]) #datos y tipos\n", " for i in 1:9\n", " archivo=String(\"grafo$i.csv\")\n", " N,E,w=leegrafo(archivo)\n", " tiempo_modelo= @elapsed mimodelo = modelo_arborescencia(N,E,w);\n", " tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", " valor_objetivo = objective_value(mimodelo)\n", " nc=num_constraints(mimodelo, count_variable_in_set_constraints=false)\n", " nv=num_variables(mimodelo)\n", " push!(dfcortes, [archivo, N, size(E,1),nv,nc, valor_objetivo, tiempo_modelo, tiempo_ejecucion])\n", " end\n", " return dfcortes\n", "end" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
9×8 DataFrame
Rownombrenum_nodosnum_aristasnum_varsnum_restvalor_objetivotiempo_modelotiempo_ejecucion
StringInt64Int64Int64Int64Float64Float64Float64
1grafo1.csv815452435.00.00325630.0037426
2grafo2.csv103410245233.00.00341720.0046717
3grafo3.csv124112354159.00.00347020.0053969
4grafo4.csv146920784110.00.00419920.0061077
5grafo5.csv167923796201.00.00420450.006865
6grafo6.csv1896288115232.00.00546630.007572
7grafo7.csv20120360141216.00.00582640.008814
8grafo8.csv124112354159.00.00350640.0053467
9grafo9.csv24186558211180.00.00755420.0123261
" ], "text/latex": [ "\\begin{tabular}{r|cccccccc}\n", "\t& nombre & num\\_nodos & num\\_aristas & num\\_vars & num\\_rest & valor\\_objetivo & tiempo\\_modelo & \\\\\n", "\t\\hline\n", "\t& String & Int64 & Int64 & Int64 & Int64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & grafo1.csv & 8 & 15 & 45 & 24 & 35.0 & 0.0032563 & $\\dots$ \\\\\n", "\t2 & grafo2.csv & 10 & 34 & 102 & 45 & 233.0 & 0.0034172 & $\\dots$ \\\\\n", "\t3 & grafo3.csv & 12 & 41 & 123 & 54 & 159.0 & 0.0034702 & $\\dots$ \\\\\n", "\t4 & grafo4.csv & 14 & 69 & 207 & 84 & 110.0 & 0.0041992 & $\\dots$ \\\\\n", "\t5 & grafo5.csv & 16 & 79 & 237 & 96 & 201.0 & 0.0042045 & $\\dots$ \\\\\n", "\t6 & grafo6.csv & 18 & 96 & 288 & 115 & 232.0 & 0.0054663 & $\\dots$ \\\\\n", "\t7 & grafo7.csv & 20 & 120 & 360 & 141 & 216.0 & 0.0058264 & $\\dots$ \\\\\n", "\t8 & grafo8.csv & 12 & 41 & 123 & 54 & 159.0 & 0.0035064 & $\\dots$ \\\\\n", "\t9 & grafo9.csv & 24 & 186 & 558 & 211 & 180.0 & 0.0075542 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m9×8 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m nombre \u001b[0m\u001b[1m num_nodos \u001b[0m\u001b[1m num_aristas \u001b[0m\u001b[1m num_vars \u001b[0m\u001b[1m num_rest \u001b[0m\u001b[1m valor_objetivo \u001b[0m\u001b[1m\u001b[0m ⋯\n", " │\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ grafo1.csv 8 15 45 24 35.0 ⋯\n", " 2 │ grafo2.csv 10 34 102 45 233.0\n", " 3 │ grafo3.csv 12 41 123 54 159.0\n", " 4 │ grafo4.csv 14 69 207 84 110.0\n", " 5 │ grafo5.csv 16 79 237 96 201.0 ⋯\n", " 6 │ grafo6.csv 18 96 288 115 232.0\n", " 7 │ grafo7.csv 20 120 360 141 216.0\n", " 8 │ grafo8.csv 12 41 123 54 159.0\n", " 9 │ grafo9.csv 24 186 558 211 180.0 ⋯\n", "\u001b[36m 2 columns omitted\u001b[0m" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Ejecutar funcion anterior\n", "df=prueba_arborescencia()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ejercicio 4. Modelo multiflujo\n", "\n", "$$\n", "\\begin{align*}\n", "(\\text{M4}) \\quad \\min \\sum_{e\\in E}&w_e x_e\\\\\n", "x(E) &= n-1\\\\\n", "y_{i,j}+y_{j,i}&= x_e, \\qquad \\text{para todo $e=ij\\in E$}\\\\\n", "f^k(\\delta_A^+(k))-f^k(\\delta_A^-(k))&= +1, \\qquad \\text{para todo $k\\in V-r$}\\\\\n", "f^k(\\delta_A^+(r))-f^k(\\delta_A^-(r))&= -1, \\qquad \\text{para todo $k\\in V-r$}\\\\\n", "f^k(\\delta_A^+(v))-f^k(\\delta_A^-(v))&= 0, \\qquad \\text{para todo $k\\in V-r$, para todo $v\\in V\\setminus\\{r,k\\}$}\\\\\n", "0\\leq f^k_a&\\leq y_a, \\qquad \\text{para todo $a \\in A$, para todo $k\\in V-r$}\\\\\n", "0\\leq x_e &\\leq 1, \\qquad \\text{para todo $e\\in E$}\\\\\n", "x_e &\\in \\mathbb{Z}, \\qquad \\text{para todo $e\\in E$}\\\\\n", "y_a &\\in \\mathbb{Z}, \\qquad \\text{para todo $a\\in A$}\\\\\n", "f^k(a)&\\in \\mathbb{Z}, \\qquad \\text{para todo $a\\in A$, para todo $k\\in V-r$}\n", "\\end{align*}\n", "$$" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "modelo_multiflujos (generic function with 1 method)" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function modelo_multiflujos(N,E,w)\n", " # De preferencia acá indexe las variables \"f\" por tríos ordenados \n", " # f[i in ..., j in..., k in ...; [i,j] in ..., k in ..]\n", "\n", " r=3\n", " A=hcat(E,[[e[2],e[1]] for e in E]) \n", " \n", " mimodelo = Model()\n", " set_optimizer(mimodelo, Gurobi.Optimizer)\n", " set_attribute(mimodelo, \"output_flag\", false)\n", " \n", " # 2. Declarar variables de decisión (recomendamos usar este formato)\n", " @variable(mimodelo, 0<=x[i in 1:N,j in 1:N; [i,j] in E]<=1, Int) \n", " @variable(mimodelo, 0<=y[i in 1:N,j in 1:N; [i,j] in A], Int) \n", " @variable(mimodelo, 0<=f[i in 1:N,j in 1:N, k in 1:N; [i,j] in A && k !=r], Int) \n", " \n", " #3. Función objetivo\n", " @objective(mimodelo, Min, sum(x[e[1],e[2]]*w[e] for e in E))\n", "\n", " # 3. Escribir restricciones (llenar)\n", " @constraint(mimodelo, cardinalidadtotal, sum(x)==N-1)\n", " @constraint(mimodelo, bidireccion[e in E], \n", " y[e[1],e[2]]+y[e[2],e[1]] == x[e[1],e[2]])\n", " @constraint(mimodelo, cota[k in 1:N, a in A; k!=r], \n", " f[a[1],a[2],k]<=y[a[1],a[2]])\n", " @constraint(mimodelo, outroot[k in 1:N; k!=r], sum(f[k,i,k]-f[i,k,k] for i in 1:N if [k,i] in A)==1)\n", " @constraint(mimodelo, inroot[k in 1:N; k != r], sum(f[r,i,k]-f[i,r,k] for i in 1:N if [r,i] in A)==-1)\n", " @constraint(mimodelo, flow[k in 1:N, v in 1:N; k != r&& v!=r&& v!=k], sum(f[v,i,k]-f[i,v,k] for i in 1:N if [v,i] in A)==0)\n", " \n", " \n", " return mimodelo\n", "end" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Grafo con 12 nodos y 41 aristas\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Demoré 3.5924511 segundos en crear el modelo y 0.0499674 en resolverlo\n", "El valor objetivo es: 159.0\n", "El conjunto de aristas es: [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [2, 5], [2, 8], [2, 9], [2, 10], [2, 12], [3, 11], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [6, 7], [6, 10], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 11], [8, 12], [9, 10], [9, 12], [10, 12]]\n" ] } ], "source": [ "# Resolver MST, usando el modelo, en una instancia de prueba ubicado en el archivo \"grafo1.csv\". \n", "N,E,w=leegrafo(\"grafo8.csv\")\n", "println(\"Grafo con $N nodos y $(size(E,1)) aristas\")\n", "tiempo_modelo= @elapsed ( mimodelo = modelo_multiflujos(N,E,w));\n", "tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", "println(String(\"Demoré $tiempo_modelo segundos en crear el modelo y $tiempo_ejecucion en resolverlo\"))\n", "println(String(\"El valor objetivo es: $(objective_value(mimodelo))\"))\n", "println(String(\"El conjunto de aristas es: $E\"))\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "prueba_multiflujo (generic function with 1 method)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Escribir una función sin entrada, que genere un dataframe a partir de las instancias \"grafo1.csv\" hasta \"grafo9.csv\" \n", "# donde cada fila consista en el nombre de una instancia, su valor objetivo, su tiempo de creación del modelo, y su tiempo de optimización.\n", "\n", "function prueba_multiflujo()\n", "dfcortes = DataFrame(nombre = String[], num_nodos = Int[], num_aristas = Int[], num_vars=Int[], num_rest=Int[], valor_objetivo = Float64[], tiempo_modelo = Float64[], tiempo_ejecucion = Float64[]) #datos y tipos\n", " for i in 1:9\n", " archivo=String(\"grafo$i.csv\")\n", " N,E,w=leegrafo(archivo)\n", " tiempo_modelo= @elapsed mimodelo = modelo_multiflujos(N,E,w);\n", " tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", " valor_objetivo = objective_value(mimodelo)\n", " nc=num_constraints(mimodelo, count_variable_in_set_constraints=false)\n", " nv=num_variables(mimodelo)\n", " push!(dfcortes, [archivo, N, size(E,1),nv,nc, valor_objetivo, tiempo_modelo, tiempo_ejecucion])\n", " end\n", " return dfcortes\n", "end" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
9×8 DataFrame
Rownombrenum_nodosnum_aristasnum_varsnum_restvalor_objetivotiempo_modelotiempo_ejecucion
StringInt64Int64Int64Int64Float64Float64Float64
1grafo1.csv81525528235.00.00502750.0233562
2grafo2.csv1034714737233.00.00883170.028598
3grafo3.csv124110251076159.00.01132530.0358395
4grafo4.csv146920012046110.00.02059760.0723608
5grafo5.csv167926072690201.00.02750410.101781
6grafo6.csv189635523667232.00.0405610.207886
7grafo7.csv2012049205061216.00.0554760.154681
8grafo8.csv124110251076159.00.01151460.0398864
9grafo9.csv2418691149295180.00.1155850.761138
" ], "text/latex": [ "\\begin{tabular}{r|cccccccc}\n", "\t& nombre & num\\_nodos & num\\_aristas & num\\_vars & num\\_rest & valor\\_objetivo & tiempo\\_modelo & \\\\\n", "\t\\hline\n", "\t& String & Int64 & Int64 & Int64 & Int64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & grafo1.csv & 8 & 15 & 255 & 282 & 35.0 & 0.0050275 & $\\dots$ \\\\\n", "\t2 & grafo2.csv & 10 & 34 & 714 & 737 & 233.0 & 0.0088317 & $\\dots$ \\\\\n", "\t3 & grafo3.csv & 12 & 41 & 1025 & 1076 & 159.0 & 0.0113253 & $\\dots$ \\\\\n", "\t4 & grafo4.csv & 14 & 69 & 2001 & 2046 & 110.0 & 0.0205976 & $\\dots$ \\\\\n", "\t5 & grafo5.csv & 16 & 79 & 2607 & 2690 & 201.0 & 0.0275041 & $\\dots$ \\\\\n", "\t6 & grafo6.csv & 18 & 96 & 3552 & 3667 & 232.0 & 0.040561 & $\\dots$ \\\\\n", "\t7 & grafo7.csv & 20 & 120 & 4920 & 5061 & 216.0 & 0.055476 & $\\dots$ \\\\\n", "\t8 & grafo8.csv & 12 & 41 & 1025 & 1076 & 159.0 & 0.0115146 & $\\dots$ \\\\\n", "\t9 & grafo9.csv & 24 & 186 & 9114 & 9295 & 180.0 & 0.115585 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m9×8 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m nombre \u001b[0m\u001b[1m num_nodos \u001b[0m\u001b[1m num_aristas \u001b[0m\u001b[1m num_vars \u001b[0m\u001b[1m num_rest \u001b[0m\u001b[1m valor_objetivo \u001b[0m\u001b[1m\u001b[0m ⋯\n", " │\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ grafo1.csv 8 15 255 282 35.0 ⋯\n", " 2 │ grafo2.csv 10 34 714 737 233.0\n", " 3 │ grafo3.csv 12 41 1025 1076 159.0\n", " 4 │ grafo4.csv 14 69 2001 2046 110.0\n", " 5 │ grafo5.csv 16 79 2607 2690 201.0 ⋯\n", " 6 │ grafo6.csv 18 96 3552 3667 232.0\n", " 7 │ grafo7.csv 20 120 4920 5061 216.0\n", " 8 │ grafo8.csv 12 41 1025 1076 159.0\n", " 9 │ grafo9.csv 24 186 9114 9295 180.0 ⋯\n", "\u001b[36m 2 columns omitted\u001b[0m" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Ejecutar funcion anterior\n", "df=prueba_multiflujo()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ejercicio 5. Formulacion del MST por componentes\n", " \n", "$$\\begin{align*}\n", " (\\text{M5}) \\quad \\min \\sum_{e\\in E}&w_e x_e\\\\\n", " x(E) &= N-1\\\\\n", " z_{i,j,k}+z_{j,i,k}&= x_{\\{i,j\\}}, \\qquad\\text{para todo $(i,j,k)\\in S$}\\\\\n", " x_{\\{i,k\\}} + \\sum_{j\\in V\\colon (i,j,k)\\in S}z_{i,j,k}&=1, \\qquad\\text{para todo $(i,k): \\{i,k\\}\\in E$}\\\\\n", " z_{i,j,k}&\\geq 0, \\qquad \\text{para todo $(i,j,k)\\in S$}\\\\\n", " x_e &\\in \\mathbb{Z}, \\qquad \\text{para todo $e\\in E$}\\\\\n", " z_{i,j,k} &\\in \\mathbb{Z}, \\qquad \\text{para todo $(i,j,k)\\in S$}\\\\\n", " \\end{align*}\n", "$$\n", " " ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "modelo_componentes (generic function with 1 method)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function modelo_componentes(N,E,w)\n", " # nota: puede crear el conjunto S primero\n", " S=[]\n", " for e in E\n", " for k in 1:N\n", " if k!=e[1] && k!=e[2]\n", " push!(S,[e[1],e[2],k])\n", " push!(S,[e[2],e[1],k])\n", " end\n", " end\n", " end\n", " mimodelo = Model()\n", " set_optimizer(mimodelo, Gurobi.Optimizer)\n", " set_attribute(mimodelo, \"output_flag\", false)\n", " \n", " # 2. Declarar variables de decisión (recomendamos usar este formato)\n", " @variable(mimodelo, 0<=x[i in 1:N,j in 1:N; [i,j] in E]<=1, Int) \n", " @variable(mimodelo, 0<=z[i in 1:N,j in 1:N, k in 1:N; [i,j,k] in S], Int) \n", " \n", " #3. Función objetivo\n", " @objective(mimodelo, Min, sum(x[e[1],e[2]]*w[e] for e in E))\n", "\n", " # 3. Escribir restricciones (llenar)\n", " @constraint(mimodelo, cardinalidadtotal, sum(x)==N-1)\n", " @constraint(mimodelo, bidireccion[q in S], \n", " z[q[1],q[2],q[3]]+z[q[2],q[1],q[3]] == x[min(q[1],q[2]),max(q[1],q[2])])\n", " @constraint(mimodelo, borde1[e in E], x[e[1],e[2]]+sum(z[e[1],j,e[2]] for j in 1:N if [e[1],j,e[2]] in S) ==1)\n", " @constraint(mimodelo, borde2[e in E], x[e[1],e[2]]+sum(z[e[2],j,e[1]] for j in 1:N if [e[2],j,e[1]] in S) ==1)\n", " return mimodelo\n", "end" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Grafo con 12 nodos y 41 aristas\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Demoré 1.6147861 segundos en crear el modelo y 0.0285408 en resolverlo\n", "El valor objetivo es: 159.0\n", "El conjunto de aristas es: [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [2, 5], [2, 8], [2, 9], [2, 10], [2, 12], [3, 11], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [6, 7], [6, 10], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 11], [8, 12], [9, 10], [9, 12], [10, 12]]\n" ] } ], "source": [ "## Resolver MST, usando el modelo, en una instancia de prueba ubicado en el archivo \"grafo1.csv\". \n", "N,E,w=leegrafo(\"grafo8.csv\")\n", "println(\"Grafo con $N nodos y $(size(E,1)) aristas\")\n", "tiempo_modelo= @elapsed ( mimodelo = modelo_componentes(N,E,w));\n", "tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", "println(String(\"Demoré $tiempo_modelo segundos en crear el modelo y $tiempo_ejecucion en resolverlo\"))\n", "println(String(\"El valor objetivo es: $(objective_value(mimodelo))\"))\n", "println(String(\"El conjunto de aristas es: $E\"))\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "prueba_componentes (generic function with 1 method)" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Escribir una función sin entrada, que genere un dataframe a partir de las instancias \"grafo1.csv\" hasta \"grafo9.csv\" \n", "# donde cada fila consista en el nombre de una instancia, su valor objetivo, su tiempo de creación del modelo, y su tiempo de optimización.\n", "\n", "function prueba_componentes()\n", "\n", "dfcortes = DataFrame(nombre = String[], num_nodos = Int[], num_aristas = Int[], num_vars=Int[], num_rest=Int[], valor_objetivo = Float64[], tiempo_modelo = Float64[], tiempo_ejecucion = Float64[]) #datos y tipos\n", " for i in 1:9\n", " archivo=String(\"grafo$i.csv\")\n", " N,E,w=leegrafo(archivo)\n", " tiempo_modelo= @elapsed mimodelo = modelo_componentes(N,E,w);\n", " tiempo_ejecucion = @elapsed ( optimize!(mimodelo));\n", " valor_objetivo = objective_value(mimodelo)\n", " nc=num_constraints(mimodelo, count_variable_in_set_constraints=false)\n", " nv=num_variables(mimodelo)\n", " push!(dfcortes, [archivo, N, size(E,1),nv,nc, valor_objetivo, tiempo_modelo, tiempo_ejecucion])\n", " end\n", " return dfcortes\n", "end" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
9×8 DataFrame
Rownombrenum_nodosnum_aristasnum_varsnum_restvalor_objetivotiempo_modelotiempo_ejecucion
StringInt64Int64Int64Int64Float64Float64Float64
1grafo1.csv81519521135.00.00967190.0072353
2grafo2.csv1034578613233.00.03574010.0358926
3grafo3.csv1241861903159.00.1169620.0275043
4grafo4.csv146917251795110.00.2534640.0561033
5grafo5.csv167922912371201.00.4954680.0788712
6grafo6.csv189631683265232.00.9659710.0969374
7grafo7.csv2012044404561216.01.838910.140641
8grafo8.csv1241861903159.00.09520860.0324898
9grafo9.csv2418683708557180.05.972990.255574
" ], "text/latex": [ "\\begin{tabular}{r|cccccccc}\n", "\t& nombre & num\\_nodos & num\\_aristas & num\\_vars & num\\_rest & valor\\_objetivo & tiempo\\_modelo & \\\\\n", "\t\\hline\n", "\t& String & Int64 & Int64 & Int64 & Int64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & grafo1.csv & 8 & 15 & 195 & 211 & 35.0 & 0.0096719 & $\\dots$ \\\\\n", "\t2 & grafo2.csv & 10 & 34 & 578 & 613 & 233.0 & 0.0357401 & $\\dots$ \\\\\n", "\t3 & grafo3.csv & 12 & 41 & 861 & 903 & 159.0 & 0.116962 & $\\dots$ \\\\\n", "\t4 & grafo4.csv & 14 & 69 & 1725 & 1795 & 110.0 & 0.253464 & $\\dots$ \\\\\n", "\t5 & grafo5.csv & 16 & 79 & 2291 & 2371 & 201.0 & 0.495468 & $\\dots$ \\\\\n", "\t6 & grafo6.csv & 18 & 96 & 3168 & 3265 & 232.0 & 0.965971 & $\\dots$ \\\\\n", "\t7 & grafo7.csv & 20 & 120 & 4440 & 4561 & 216.0 & 1.83891 & $\\dots$ \\\\\n", "\t8 & grafo8.csv & 12 & 41 & 861 & 903 & 159.0 & 0.0952086 & $\\dots$ \\\\\n", "\t9 & grafo9.csv & 24 & 186 & 8370 & 8557 & 180.0 & 5.97299 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m9×8 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m nombre \u001b[0m\u001b[1m num_nodos \u001b[0m\u001b[1m num_aristas \u001b[0m\u001b[1m num_vars \u001b[0m\u001b[1m num_rest \u001b[0m\u001b[1m valor_objetivo \u001b[0m\u001b[1m\u001b[0m ⋯\n", " │\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Int64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ grafo1.csv 8 15 195 211 35.0 ⋯\n", " 2 │ grafo2.csv 10 34 578 613 233.0\n", " 3 │ grafo3.csv 12 41 861 903 159.0\n", " 4 │ grafo4.csv 14 69 1725 1795 110.0\n", " 5 │ grafo5.csv 16 79 2291 2371 201.0 ⋯\n", " 6 │ grafo6.csv 18 96 3168 3265 232.0\n", " 7 │ grafo7.csv 20 120 4440 4561 216.0\n", " 8 │ grafo8.csv 12 41 861 903 159.0\n", " 9 │ grafo9.csv 24 186 8370 8557 180.0 ⋯\n", "\u001b[36m 2 columns omitted\u001b[0m" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Ejecutar funcion anterior\n", "df=prueba_componentes()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Ejercicio 6. Pequeña prueba de la calidad de cada formulación" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "resumen (generic function with 1 method)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function resumen(instancia)\n", " N,E,w=leegrafo(instancia)\n", " df=DataFrame(\n", " cortesintegral = Float64[], cortesfraccional = Float64[], \n", " ciclosintegral = Float64[], ciclosfraccional = Float64[], \n", " arborescenciaintegral = Float64[], arborescenciafraccional = Float64[], \n", " multiflujosintegral = Float64[], multiflujosfraccional = Float64[], \n", " componentesintegral = Float64[], componentesfraccional = Float64[]\n", " )\n", " mimodelo = modelo_cortes(N,E,w)\n", " optimize!(mimodelo)\n", " obj1=objective_value(mimodelo)\n", " unset_integer.(mimodelo[:x])\n", " optimize!(mimodelo)\n", " obj2=objective_value(mimodelo)\n", "\n", " mimodelo = modelo_ciclos(N,E,w)\n", " optimize!(mimodelo)\n", " obj3=objective_value(mimodelo)\n", " unset_integer.(mimodelo[:x])\n", " optimize!(mimodelo)\n", " obj4=objective_value(mimodelo)\n", "\n", " mimodelo = modelo_arborescencia(N,E,w)\n", " optimize!(mimodelo)\n", " obj5=objective_value(mimodelo)\n", " unset_integer.(mimodelo[:x])\n", " unset_integer.(mimodelo[:y])\n", " optimize!(mimodelo)\n", " obj6=objective_value(mimodelo)\n", "\n", " mimodelo = modelo_multiflujos(N,E,w)\n", " optimize!(mimodelo)\n", " obj7=objective_value(mimodelo)\n", " unset_integer.(mimodelo[:x])\n", " unset_integer.(mimodelo[:y])\n", " unset_integer.(mimodelo[:f])\n", " optimize!(mimodelo)\n", " obj8=objective_value(mimodelo)\n", "\n", " mimodelo = modelo_componentes(N,E,w)\n", " optimize!(mimodelo)\n", " obj9=objective_value(mimodelo)\n", " unset_integer.(mimodelo[:x])\n", " unset_integer.(mimodelo[:z])\n", " optimize!(mimodelo)\n", " obj10=objective_value(mimodelo)\n", "\n", " push!(df,[obj1,obj2,obj3,obj4,obj5,obj6,obj7,obj8,obj9,obj10])\n", " return df\n", "end" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
1×10 DataFrame
Rowcortesintegralcortesfraccionalciclosintegralciclosfraccionalarborescenciaintegralarborescenciafraccionalmultiflujosintegralmultiflujosfraccionalcomponentesintegralcomponentesfraccional
Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
135.035.035.035.035.035.035.035.035.035.0
" ], "text/latex": [ "\\begin{tabular}{r|cccccc}\n", "\t& cortesintegral & cortesfraccional & ciclosintegral & ciclosfraccional & arborescenciaintegral & \\\\\n", "\t\\hline\n", "\t& Float64 & Float64 & Float64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & 35.0 & 35.0 & 35.0 & 35.0 & 35.0 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m1×10 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m cortesintegral \u001b[0m\u001b[1m cortesfraccional \u001b[0m\u001b[1m ciclosintegral \u001b[0m\u001b[1m ciclosfraccional \u001b[0m\u001b[1m arb\u001b[0m ⋯\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Flo\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ 35.0 35.0 35.0 35.0 ⋯\n", "\u001b[36m 6 columns omitted\u001b[0m" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
1×10 DataFrame
Rowcortesintegralcortesfraccionalciclosintegralciclosfraccionalarborescenciaintegralarborescenciafraccionalmultiflujosintegralmultiflujosfraccionalcomponentesintegralcomponentesfraccional
Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
1233.0230.5233.0233.0233.0233.0233.0233.0233.0233.0
" ], "text/latex": [ "\\begin{tabular}{r|cccccc}\n", "\t& cortesintegral & cortesfraccional & ciclosintegral & ciclosfraccional & arborescenciaintegral & \\\\\n", "\t\\hline\n", "\t& Float64 & Float64 & Float64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & 233.0 & 230.5 & 233.0 & 233.0 & 233.0 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m1×10 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m cortesintegral \u001b[0m\u001b[1m cortesfraccional \u001b[0m\u001b[1m ciclosintegral \u001b[0m\u001b[1m ciclosfraccional \u001b[0m\u001b[1m arb\u001b[0m ⋯\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Flo\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ 233.0 230.5 233.0 233.0 ⋯\n", "\u001b[36m 6 columns omitted\u001b[0m" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
1×10 DataFrame
Rowcortesintegralcortesfraccionalciclosintegralciclosfraccionalarborescenciaintegralarborescenciafraccionalmultiflujosintegralmultiflujosfraccionalcomponentesintegralcomponentesfraccional
Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
1159.0153.5159.0159.0159.0159.0159.0159.0159.0159.0
" ], "text/latex": [ "\\begin{tabular}{r|cccccc}\n", "\t& cortesintegral & cortesfraccional & ciclosintegral & ciclosfraccional & arborescenciaintegral & \\\\\n", "\t\\hline\n", "\t& Float64 & Float64 & Float64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & 159.0 & 153.5 & 159.0 & 159.0 & 159.0 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m1×10 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m cortesintegral \u001b[0m\u001b[1m cortesfraccional \u001b[0m\u001b[1m ciclosintegral \u001b[0m\u001b[1m ciclosfraccional \u001b[0m\u001b[1m arb\u001b[0m ⋯\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Flo\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ 159.0 153.5 159.0 159.0 ⋯\n", "\u001b[36m 6 columns omitted\u001b[0m" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
1×10 DataFrame
Rowcortesintegralcortesfraccionalciclosintegralciclosfraccionalarborescenciaintegralarborescenciafraccionalmultiflujosintegralmultiflujosfraccionalcomponentesintegralcomponentesfraccional
Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
1110.0108.5110.0110.0110.0110.0110.0110.0110.0110.0
" ], "text/latex": [ "\\begin{tabular}{r|cccccc}\n", "\t& cortesintegral & cortesfraccional & ciclosintegral & ciclosfraccional & arborescenciaintegral & \\\\\n", "\t\\hline\n", "\t& Float64 & Float64 & Float64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & 110.0 & 108.5 & 110.0 & 110.0 & 110.0 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m1×10 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m cortesintegral \u001b[0m\u001b[1m cortesfraccional \u001b[0m\u001b[1m ciclosintegral \u001b[0m\u001b[1m ciclosfraccional \u001b[0m\u001b[1m arb\u001b[0m ⋯\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Flo\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ 110.0 108.5 110.0 110.0 ⋯\n", "\u001b[36m 6 columns omitted\u001b[0m" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
1×10 DataFrame
Rowcortesintegralcortesfraccionalciclosintegralciclosfraccionalarborescenciaintegralarborescenciafraccionalmultiflujosintegralmultiflujosfraccionalcomponentesintegralcomponentesfraccional
Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
1201.0201.0201.0201.0201.0201.0201.0201.0201.0201.0
" ], "text/latex": [ "\\begin{tabular}{r|cccccc}\n", "\t& cortesintegral & cortesfraccional & ciclosintegral & ciclosfraccional & arborescenciaintegral & \\\\\n", "\t\\hline\n", "\t& Float64 & Float64 & Float64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & 201.0 & 201.0 & 201.0 & 201.0 & 201.0 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m1×10 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m cortesintegral \u001b[0m\u001b[1m cortesfraccional \u001b[0m\u001b[1m ciclosintegral \u001b[0m\u001b[1m ciclosfraccional \u001b[0m\u001b[1m arb\u001b[0m ⋯\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Flo\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ 201.0 201.0 201.0 201.0 ⋯\n", "\u001b[36m 6 columns omitted\u001b[0m" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for i in 1:5\n", " display(resumen(String(\"grafo$i.csv\")))\n", "end" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n", "Set parameter Username\n", "Academic license - for non-commercial use only - expires 2025-03-14\n" ] }, { "data": { "text/html": [ "
1×10 DataFrame
Rowcortesintegralcortesfraccionalciclosintegralciclosfraccionalarborescenciaintegralarborescenciafraccionalmultiflujosintegralmultiflujosfraccionalcomponentesintegralcomponentesfraccional
Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
1159.0153.5159.0159.0159.0159.0159.0159.0159.0159.0
" ], "text/latex": [ "\\begin{tabular}{r|cccccc}\n", "\t& cortesintegral & cortesfraccional & ciclosintegral & ciclosfraccional & arborescenciaintegral & \\\\\n", "\t\\hline\n", "\t& Float64 & Float64 & Float64 & Float64 & Float64 & \\\\\n", "\t\\hline\n", "\t1 & 159.0 & 153.5 & 159.0 & 159.0 & 159.0 & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m1×10 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m cortesintegral \u001b[0m\u001b[1m cortesfraccional \u001b[0m\u001b[1m ciclosintegral \u001b[0m\u001b[1m ciclosfraccional \u001b[0m\u001b[1m arb\u001b[0m ⋯\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Flo\u001b[0m ⋯\n", "─────┼──────────────────────────────────────────────────────────────────────────\n", " 1 │ 159.0 153.5 159.0 159.0 ⋯\n", "\u001b[36m 6 columns omitted\u001b[0m" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ " display(resumen(String(\"grafo8.csv\")))" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.10.2", "language": "julia", "name": "julia-1.10" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.2" } }, "nbformat": 4, "nbformat_minor": 4 }