Package net.wigis.greg

Examples of net.wigis.greg.ShortestPath


    private static ArrayList<ShortestPath> ShortestPath(ArrayList<DNVNode> list, DNVNode source){
     
      ArrayList<ShortestPath> SP = new ArrayList<ShortestPath>();
     
     
      ShortestPath object = new ShortestPath();
      int index = 0;
      int alt = 0;
      boolean end = false;
      boolean stop = false;
     
      ShortestPath node1 = new ShortestPath();
      ShortestPath node2 = new ShortestPath();
     
      //Initialization
      for(int i=0;i<list.size();i++){
        object = new ShortestPath();
        object.setSource(list.get(i));
        object.setDistance(999999999);
        SP.add(object);
      }
     
      //get the source index and set its distance to 0
      for(int i=0;i<SP.size();i++){
        if(source.toString().compareToIgnoreCase(SP.get(i).getSource().toString()) == 0){
          SP.get(i).setDistance(0);
        }
         
      }    
          
      while(list.isEmpty() == false && end == false){       
        //get the node with the lowest distance value
        node1 = getLowerDistanceValueObject(SP,list);
       
        //if the visited node's distance == 9999999999 then we break
        if(node1.getDistance() != 999999999){
         
          list.remove(list.indexOf(node1.getSource()));
            //get all neighbors of the current node
          List<DNVNode> tmp = new ArrayList<DNVNode>(node1.getSource().getNeighbors(true));
            for(int i=0;i<tmp.size();i++){
              //get the DNVNode source value
              DNVNode tempNode = new DNVNode();
             
            tempNode = tmp.get(i);
              //change the previous node2 by the new one
              for(int x=0;x<SP.size();x++){
                if(SP.get(x).getSource().toString().compareToIgnoreCase(tempNode.toString()) == 0){
                  node2 = SP.get(x);
                }
              }          
             
              //get the new distance between both nodes             
              alt = node1.getDistance()+1;
              //if new distance is lower than the previous one, set the new distance and the new previous node
              if(alt < node2.getDistance()){
                node2.setDistance(alt);
                node2.setPreviousNode(node1.getSource());
              }
            }
        }else{
          end = true;
        }
View Full Code Here


     * @param source
     * @param destination
     */
    static void highlightPath(ArrayList<ShortestPath> SP, DNVNode source, DNVNode destination){

      ShortestPath currentNode = new ShortestPath();
      boolean loop = true;
     
      //Look for the destination node into the SP list
      for (int i=0;i<SP.size();i++){
        if(SP.get(i).getSource().toString().compareToIgnoreCase(destination.toString()) == 0){
          currentNode = SP.get(i);
        }
      }
     
      destination.setHighlighted(true);

     
      //Loop until the source node is reached
      while(loop){
        //Get the current node's previous node
        DNVNode previousNode = currentNode.getPreviousNode();
        DNVNode nodeVisited = currentNode.getSource();
       
       
        DNVEdge edge = nodeVisited.getEdgeToNeighbor(previousNode.getId());
        edge.setHighlighted(true);
       
View Full Code Here

TOP

Related Classes of net.wigis.greg.ShortestPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.