All pastes #430744 Raw Edit

Stuff

public text v1 · immutable
·published 2007-04-09 06:52 UTC
rendered paste body
public int[] Dijkstra() {
        Node temp;
        int[] shortestPaths = new int[this.size()];
        int path, newpath;
        PriorityQueue pq = new PriorityQueue(this.size());
        
        for (int row=0; row<adjMatrix.length; row++){
            shortestPaths[row] = 9999; // Represents infinite (unknown) path distance
        }
    
        for (int i=0; i<this.size(); i++){
            pq.insert(this.nodes[i]);
        }
       
        temp = pq.deleteMin();
        temp.setDistance(0);
        temp.addToCloud();
        shortestPaths[temp.getName()] = temp.getDistance();
      
        while (!(pq.isEmpty())) {
            //System.out.println("Im going in here");
            if(temp.hasEdges()){
                for(int row=0; row<this.size(); row++){
                    if(nodes[row].inCloud()){
                        path = temp.getAdjacentNodeWeight(nodes[row]);
                        if(path < 9999){
                            if(shortestPaths[nodes[row].getName()] == 9999){
                                newpath = path + temp.getDistance();      
                            }
                            else if(shortestPaths[nodes[row].getName()] < (path + temp.getDistance())){
                                newpath = shortestPaths[nodes[row].getName()];
                            }
                            else{
                                newpath =  path + temp.getDistance();
                            }      
                            shortestPaths[nodes[row].getName()] = newpath;
                            nodes[row].setDistance(newpath);   
                        }                   
                    }
                }
            }
            
            pq.emptyPQ();
                            
            for(int i=0; i<this.size(); i++){
                if(nodes[i].inCloud() == false){
                    pq.insert(nodes[i]);
                }
            }
            
            temp = pq.deleteMin();
            temp.addToCloud();
        }
        
        return shortestPaths;
    }