Commits

David Lin committed 0194f44

Test Data #101

  • Participants
  • Parent commits c4df655

Comments (0)

Files changed (7)

src/Edge/Alive.java

-package dp2011.group05.delivery;
-
-public class Alive extends AbstractEdgeDecorator
-{
-  public Alive(Edge edge)
-  {
-    super(edge);
-  }
-  
-  @Override
-  public int getCost()
-  {
-    return 1000 + super.edge.getCost();
-  }
-  
-  @Override
-  public int getTime()
-  {
-    return super.edge.getTime();
-  }
-  
-  @Override
-  public int getLoadWeight()
-  {
-    return super.edge.getLoadWeight();
-  }
-  
-  @Override
-  protected boolean acceptPackage(Package visitor)
-  {
-    return visitor.visit(this);
-  }
-  
-  @Override
-  public String toString()
-  {
-    return super.edge.toString() + ", alive";
-  }
-}

src/Edge/Fragile.java

-package dp2011.group05.delivery;
-
-public class Fragile extends AbstractEdgeDecorator
-{
-  public Fragile(Edge edge)
-  {
-    super(edge);
-  }
-  
-  @Override
-  public int getCost()
-  {
-    return 800 + super.edge.getCost();
-  }
-  
-  @Override
-  public int getTime()
-  {
-    return super.edge.getTime();
-  }
-  
-  @Override
-  public int getLoadWeight()
-  {
-    return super.edge.getLoadWeight();
-  }
-  
-  @Override
-  protected boolean acceptPackage(Package visitor)
-  {
-    return visitor.visit(this);
-  }
-  
-  @Override
-  public String toString()
-  {
-    return super.edge.toString() + ", fragile";
-  }
-}

src/Edge/TimeLimit.java

-package dp2011.group05.delivery;
-
-public class TimeLimit extends AbstractEdgeDecorator
-{
-  public TimeLimit(Edge edge)
-  {
-    super(edge);
-  }
-  
-  @Override
-  public int getCost()
-  {
-    return 500 + super.edge.getCost();
-  }
-  
-  //uh, not sure
-  @Override
-  public int getTime()
-  {
-    return 24 * 3;
-  }
-  
-  @Override
-  public int getLoadWeight()
-  {
-    return super.edge.getLoadWeight();
-  }
-  
-  @Override
-  protected boolean acceptPackage(Package visitor)
-  {
-    return visitor.visit(this);
-  }
-  
-  @Override
-  public String toString()
-  {
-    return super.edge.toString() + ", timelimited";
-  }
-  
-}

src/Location/Airport.java

+package dp2011.group05.delivery;
+
+public class Airport extends AbstractLocation{
+  // ctor
+  public Airport(String name)
+  {
+    super(name);
+  }
+  
+}

src/Location/Port.java

+package dp2011.group05.delivery;
+
+public class Port extends AbstractLocation{
+  // ctor
+  public Port(String name)
+  {
+    super(name);
+  }
+  
+}

src/Location/Station.java

+package dp2011.group05.delivery;
+
+public class Station extends AbstractLocation{
+  // ctor
+  public Station(String name)
+  {
+    super(name);
+  }
+  
+}
 
 public class Main{
   
-  // app main
-  public static void main(String args[])
+  //
+  public static void test100()
   {
     ShortestPath sp = new ShortestPath();
     Map<String, Location> locations = new HashMap<String, Location>();
     e.setTime(2);
     sp.addEdge(e);
     
-    Package pak = new Meat(10);
+    Package pak = new NormalPackage(10);
     Location from = locations.get("A"), to = locations.get("F");
     List<Edge> result = sp.compute(from, to, pak);
     
     for(Edge ed : result){
       System.out.println(ed.toString());
     }
+  }
+  
+  //
+  public static void test101()
+  {
+    ShortestPath sp = new ShortestPath();
+    Map<String, Location> locations = new HashMap<String, Location>();
+    
+    locations.put("Hsinchu City", new City("Hsinchu City"));
+    locations.put("Taipei City", new City("Taipei City"));
+    locations.put("Taipei Main Station", 
+                  new Station("Taipei Main Station"));
+    locations.put("Hsinchu TRA Station", 
+                  new Station("Hsinchu TRA Station"));
+    locations.put("Hsinchu THSRC Station", 
+                  new Station("Hsinchu THSRC Station"));
+    
+    Location from, to;
+    AbstractEdge e;
+    
+    // Hsinchu City <-> Hsinchu TRA
+    from = locations.get("Hsinchu City");
+    to = locations.get("Hsinchu TRA Station");
+    e = new Road(from, to);
+    e.setTime(5);
+    e.setCost(1);
+    sp.addEdge(e);
+    
+    e = new Road(to, from);
+    e.setTime(5);
+    e.setCost(1);
+    sp.addEdge(e);
+    
+    // Hsinchu TRA <-> Taipei Main Station
+    from = locations.get("Hsinchu TRA Station");
+    to = locations.get("Taipei Main Station");
+    e = new Rail(from, to);
+    e.setTime(90);
+    e.setCost(100);
+    sp.addEdge(e);
+    
+    e = new Rail(to, from);
+    e.setTime(90);
+    e.setCost(100);
+    sp.addEdge(e);
+    
+    // Hsinchu City <-> Hsinchu THSRC
+    from = locations.get("Hsinchu City");
+    to = locations.get("Hsinchu THSRC Station");
+    e = new Road(from, to);
+    e.setTime(30);
+    e.setCost(10);
+    sp.addEdge(e);
+    
+    e = new Road(to, from);
+    e.setTime(30);
+    e.setCost(10);
+    sp.addEdge(e);
+    
+    // Hsinchu THSRC <-> Taipei Main Station
+    from = locations.get("Hsinchu THSRC Station");
+    to = locations.get("Taipei Main Station");
+    e = new Rail(from, to);
+    e.setTime(30);
+    e.setCost(290);
+    sp.addEdge(e);
+    
+    e = new Rail(to, from);
+    e.setTime(30);
+    e.setCost(290);
+    sp.addEdge(e);
+    
+    // Hsinchu City <-> Taipei City
+    from = locations.get("Hsinchu City");
+    to = locations.get("Taipei City");
+    e = new Road(from, to);
+    e.setTime(80);
+    e.setCost(100);
+    sp.addEdge(e);
+    
+    e = new Road(to, from);
+    e.setTime(80);
+    e.setCost(100);
+    sp.addEdge(e);
+    
+    // Taipei City <-> Taipei Main Station
+    from = locations.get("Taipei City");
+    to = locations.get("Taipei Main Station");
+    e = new Road(from, to);
+    e.setTime(5);
+    e.setCost(1);
+    sp.addEdge(e);
+    
+    e = new Road(to, from);
+    e.setTime(5);
+    e.setCost(1);
+    sp.addEdge(e);
+    
+    /////
+    
+    Package pak;
+    List<Edge> result;
+    
+    from = locations.get("Hsinchu City");
+    to = locations.get("Taipei City");
+    
+    pak = new NormalPackage(10);
+    
+    sp.setEdgeComparator(new EdgeTimeComparator());
+    result = sp.compute(from, to, pak);
+    System.out.println("result for shortest time:");
+    for(Edge ed : result)
+      System.out.println(ed.toString());
+    
+    sp.setEdgeComparator(new EdgeCostComparator());
+    result = sp.compute(from, to, pak);
+    System.out.println("result for least cost:");
+    for(Edge ed : result)
+      System.out.println(ed.toString());
+    
+  }
+  
+  // app main
+  public static void main(String args[])
+  {
+    System.out.println("==== Test 100 ====");
+    test100();
+    System.out.println("==================");
     
+    System.out.println("==== Test 101 ====");
+    test101();
+    System.out.println("==================");
   }
   
 }