Resultados 1 al 4 de 4

Tema: Dijkstra

  1. #1
    Roba-posts Avatar de *CN!
    Riquisimo!




    Ingreso: Jun 2005
    Edad: 29
    Mensajes: 316

    Dijkstra

    El otro día me puse a investigar este algoritmo... hice la implementación en java.. quedo linda

    Código:
    package com.cumbianena.dijkstra;
    
    public class DijkstraEngine {
            
        public int[] execute(int[][] graph, int node) {
            
            final boolean settledNodes[] = new boolean[graph.length];
            final int shortestDistances[] = new int[graph.length];
            
            settledNodes[0] = true;
            
            for (int i = 1; i < shortestDistances.length; i++) {
                if (graph[node][i] != 0) shortestDistances[i] = graph[node][i];
                else shortestDistances[i] = Integer.MAX_VALUE;
            }
            
            for (int i = 0; i < (shortestDistances.length - 1); i++){
                final int next = minVertex(shortestDistances, settledNodes);
                settledNodes[next] = true;
                
                for (int j = 0; j < graph[0].length; j++) {
                    final int d = shortestDistances[next] + graph[next][j];
                    if ( shortestDistances[j] > d) shortestDistances[j] = shortestDistances[next] + graph[next][j];
                }            
            }
            
            return shortestDistances;
        }
        
        
        private static int minVertex (int [] shortestDistances, boolean [] settledNodes) {
            int x = Integer.MAX_VALUE;
            int y = -1;
            for (int i = 0; i < shortestDistances.length; i++) {
                if (!settledNodes[i] && shortestDistances[i] < x) {
                    y = i;
                    x = shortestDistances[i];
                }
            }
            return y;
        }
    }

    jejeje salutes
    *CN! no ha iniciado sesión

  2. #2
    aiz
    Un poco groso Avatar de aiz
    Coma sushi, me hace bien


    Administrador
    Super Moderador
    Moderador
    Staff Prysmax
    Admin CSS
    Admin SB



    Ingreso: Jan 2005
    Ubicación: Palermo Gólico
    Mensajes: 3,109
    Entradas de Blog: 1

    En VB .Net son 2 lineas.
    Cuantas te llevó en java?

    O sino lo sacas del framework directamente... está en System.Dijkstra.Elmasfacil

    Saludos,
    AiZ




    aiz no ha iniciado sesión

  3. #3
    Roba-posts Avatar de *CN!
    Riquisimo!




    Ingreso: Jun 2005
    Edad: 29
    Mensajes: 316

    Por eso no me gusta .NET, me gusta hacer las cosas solito. No que me digan como hacerlo
    *CN! no ha iniciado sesión

  4. #4
    Un poco groso Avatar de Alduath
    Admin DD/Gunz


    Staff Prysmax



    Ingreso: Oct 2006
    Mensajes: 4,117

    Fijate de tratar de no hacerlo objetoso, a ver si java no te dice como hacerlo entonces! (?)

    (Btw, im against .net)

    Alduath no ha iniciado sesión

Información de Tema

Usuarios Viendo este Tema

Actualmente hay 1 usuarios viendo este tema. (0 miembros y 1 visitantes)

     

Temas Similares

  1. KoRn vs Dijkstra
    Por KoRnFaN en el foro Desafios/Duelos
    Respuestas: 0
    Último Mensaje: 11-06-2007, 02:21 AM

Permisos de Publicación

  • No puedes crear nuevos temas
  • No puedes responder temas
  • No puedes subir archivos adjuntos
  • No puedes editar tus mensajes
  •