Package general.datastructures

Examples of general.datastructures.PriorityQueue


 
 
  @Test(expected = EmptyListException.class)
  public void testPriorityQueueEmpty() throws EmptyListException
  {
    PriorityQueue pq;
    pq = new PriorityQueue();
   
    assertNotNull(pq);
    assertTrue(pq.isEmpty());
   
    pq.getFirst();
   
  }
View Full Code Here


  }
 
  @Test
  public void testPriorityQueueInsert() throws EmptyListException
  {
    PriorityQueue pq = new PriorityQueue();
    Waypoint wp1, wp2, wp3, wp4, wp5;
    wp1 = new Waypoint(new Vector2f(1,1), 1);
    wp2 = new Waypoint(new Vector2f(2,2), 2);
    wp3 = new Waypoint(new Vector2f(3,3), 3);
    wp4 = new Waypoint(new Vector2f(4,4), 4);
    wp5 = new Waypoint(new Vector2f(5,5), 5);
   
    pq.insert(wp2, 2);
    assertFalse(pq.isEmpty());
    pq.insert(wp4, 4);
    assertFalse(pq.isEmpty());
    pq.insert(wp5, 5);
    assertFalse(pq.isEmpty());
    pq.insert(wp3, 6);
    assertFalse(pq.isEmpty());
    pq.insert(wp1, 1);
    assertFalse(pq.isEmpty());
   
    pq.insert(wp3, 3);
   
    assertEquals(wp1,pq.getFirst());
    assertEquals(wp2,pq.getFirst());
    assertEquals(wp3,pq.getFirst());
    assertEquals(wp4,pq.getFirst());
    assertEquals(wp5,pq.getFirst());
   
    assertTrue(pq.isEmpty());
   
   
  }
View Full Code Here

  }
 
  @Test
  public void testPriorityQueueDublicates() throws EmptyListException
  {
    PriorityQueue pq = new PriorityQueue();
    Waypoint wp1, wp2, wp3;
    wp1 = new Waypoint(new Vector2f(1,1), 1);
    wp2 = new Waypoint(new Vector2f(2,2), 2);
    wp3 = new Waypoint(new Vector2f(3,3), 3);
   
    pq.insert(wp1, 10);
    pq.insert(wp1, 9);
    pq.insert(wp2, 8);
    pq.insert(wp2, 7);
    pq.insert(wp3, 6);
    pq.insert(wp3, 5);
    pq.insert(wp1, 1);
    pq.insert(wp1, 1);
    pq.insert(wp2, 2);
    pq.insert(wp2, 2);
    pq.insert(wp3, 3);
    pq.insert(wp3, 3);
   
    assertEquals(wp1,pq.getFirst());
    assertEquals(wp2,pq.getFirst());
    assertEquals(wp3,pq.getFirst());
    assertTrue(pq.isEmpty());
  }
View Full Code Here

    System.out.println("Exceptions ueberlebt");

    boolean routeFound = false;

    PriorityQueue openlist = new PriorityQueue();
    Vector<Waypoint> closedlist = new Vector<Waypoint>();

    Waypoint wp_to = new Waypoint(mc_to,0);
    Waypoint currentWP;

    Vector<Waypoint> newWaypoints;

    //System.err.println("Fuege Punkt to zu openlist hinzu: " + to.toString());
    openlist.insert(wp_to, 0);

    do{
      //System.err.println(openlist.toString());

      currentWP = openlist.getFirst();
      //System.err.println("Hole Node von der openlist: " + currentWP.toString());


      //if (currentWP.getVector2f().equals(from))
      if (currentWP.getVector2f().isInRange(mc_from, 0.707f))
      {
        System.out.println("Weg gefunden!!");
        routeFound = true;
        break;
      }

      closedlist.add(currentWP);

      // Expand Node
      Vector2f currentpoint = currentWP.getVector2f();

      newWaypoints = new Vector<Waypoint>(8);

      //8er Nachbarschaft hinzufuegen
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()-1 , currentpoint.y()-1 ),   Math.sqrt(2,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()-1 , currentpoint.y() ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()-1 , currentpoint.y()+1 ),   Math.sqrt(2,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x() , currentpoint.y()-1 ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x() , currentpoint.y()+1 ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()+1 , currentpoint.y()-1 ),   Math.sqrt(2,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()+1 , currentpoint.y() ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()+1 , currentpoint.y()+1 ),   Math.sqrt(2,currentWP));

      //System.err.println("Alle punkte zum vektor hinzugefuegt");

      for(Waypoint wp : newWaypoints)
      {
        if ( (closedlist.contains(wp)) || (!map.isInMap(wp.getVector2f())) || (!map.isPassable(vehicletype, wp.getVector2f())) )
        {
          continue;
        }

        double estimatedDistance = wp.getDistance()+wp.getVector2f().getDistanceTo(mc_from);

        openlist.insert(wp, estimatedDistance);
      }

    }
    while (!openlist.isEmpty());

    if (routeFound)
    {   
      Vector<Vector2f> mc_wps = new Vector<Vector2f>();
      Vector<Vector2f> wc_waypoints = new Vector<Vector2f>();
View Full Code Here

TOP

Related Classes of general.datastructures.PriorityQueue

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.