Skip to content

Ari2213/TSP-NearestNeighbor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TSP-NearestNeighbor

TSP - Nearest Neighbor Algorithm

Este repositorio contiene la implementación del algoritmo del Vecino Más Cercano (Nearest Neighbor, NN) para aproximar soluciones al Problema del Vendedor Viajero (Traveling Salesman Problem, TSP). El objetivo es encontrar una ruta que visite todas las ciudades exactamente una vez y regrese al punto de partida, minimizando la distancia total.

Estructura del repositorio

TSP-NearestNeighbor/ │ ├── src/ │ └── tsp_nn.jl │ ├── data/ │ ├── D10x10_random.csv │ └── D50x50_random.csv │ ├── results/ │ └── grafica_costo_iteracion10.png │ └── README.md


Dependencias

Para ejecutar el código se necesita tener instalados los siguientes paquetes en Julia:

using Random
using Plots
using CSV
using DataFrames

import Pkg
Pkg.add("Random")
Pkg.add("Plots")
Pkg.add("CSV")
Pkg.add("DataFrames")

#=Declaraciones de IA 
ESTE ES  MI CODIGO ANTES DE UTILIZAR IA 
# ------------------------------
# Código hecho totalmente por mi, sin ningun apoyo de IA
# ------------------------------
 #= 
 C = [
    0   12  29  22  13  25  17  28  33  21;
    12   0  19  30  25  16  28  14  24  18;
    29  19   0  15  28  27  14  20  23  17;
    22  30  15   0  26  19  23  18  21  31;
    13  25  28  26   0  12  19  22  27  16;
    25  16  27  19  12   0  22  18  24  20;
    17  28  14  23  19  22   0  16  20  25;
    28  14  20  18  22  18  16   0  19  21;
    33  24  23  21  27  24  20  19   0  23;
    21  18  17  31  16  20  25  21  23   0
]
nfilas = size(C, 1) #obtener el número de filas
j = rand(1:nfilas) #generar un número de manera aleatoría de 1 hasta el número de filas
println(j)
#arreglo unidimensional vacío

function mini(j::Int64, C::Matrix{Int}) #Función para encontrar el minimo número diferente de cero dentro de las columnas.
    col = C[:, j] #Esta es la columna j
    return minimum(col[col .!= 0]) #retorna el minimo diferente de cero dentro de j
end

function fila(k::Int, j::Int) #Función para saber a que fila pertenece el minimo, recibe el número minimo retornado de la función mini 
    col = C[:, j] #Columna j
    fila = findfirst(==(k), col) #
    return fila 
end 

function rlista(j::Int64, C::Vector{Int64})
   return j in C
end

function nn(j::Int64, nfilas::Int64,C::Matrix{Int})
    Cn = [j]

    for w in 1:nfilas-1 
        k=mini(j,C)
        m=fila(k,j)
        if rlista(m,Cn)==false
            push!(Cn, m)
            j=m
        end
    end
    return Cn
end 

resultado = nn(j, nfilas,C)
println(resultado)
=#

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages