View Javadoc

1   /*
2    * @(#)TestTrack.java Oct 9, 2004
3    * 
4    * Copyright (c) 2003, 2004 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  
11  package nl.tudelft.simulation.traffic;
12  
13  import java.util.List;
14  import nl.tudelft.simulation.traffic.track.ComplexTrackLink;
15  import nl.tudelft.simulation.traffic.track.SimpleTrackLink;
16  import nl.tudelft.simulation.traffic.track.StraightTrack;
17  import nl.tudelft.simulation.traffic.track.util.TrackProgression;
18  
19  /***
20   * <br>
21   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
22   * University of Technology </a>, the Netherlands. <br>
23   * See for project information <a href="http://www.simulation.tudelft.nl">
24   * www.simulation.tudelft.nl </a> <br>
25   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
26   * License (GPL) </a>, no warranty <br>
27   * 
28   * @version Oct 9, 2004 <br>
29   * @author <a
30   * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
31   * Verbraeck </a>
32   */
33  public class TestTrack
34  {
35      /***
36       *  
37       */
38      public TestTrack()
39      {
40          super();
41          SimpleTrackLink l1 = new SimpleTrackLink("l1", 0, 0, 0);
42          SimpleTrackLink l2 = new SimpleTrackLink("l2", 100, 0, 0);
43          ComplexTrackLink l3 = new ComplexTrackLink("l3", 200, 0, 0);
44          SimpleTrackLink l4a = new SimpleTrackLink("l4a", 300, 0, 0);
45          SimpleTrackLink l4b = new SimpleTrackLink("l4b", 300, 0, 0);
46          ComplexTrackLink l5 = new ComplexTrackLink("l5", 400, 0, 0);
47          SimpleTrackLink l6 = new SimpleTrackLink("l6", 500, 0, 0);
48          StraightTrack t1 = new StraightTrack("t1", l1, l2);
49          StraightTrack t2 = new StraightTrack("t2", l2, l3);
50          StraightTrack t3a = new StraightTrack("t3a", l3, l4a);
51          /* StraightTrack t3b = */new StraightTrack("t3b", l3, l4b);
52          StraightTrack t4a = new StraightTrack("t4a", l4a, l5);
53          /* StraightTrack t4b = */new StraightTrack("t4b", l4b, l5);
54          StraightTrack t5 = new StraightTrack("t5", l5, l6);
55          t2.getEndLink().setActiveSuccessor(t2, t3a);
56          t4a.getEndLink().setActiveSuccessor(t4a, t5);
57          System.out.println("\nFORWARD ACTIVE:");
58          System.out.println("t1.active(40) = "
59                  + t1.calculateTrackProgressionListActive(40));
60          System.out.println("t1.active(80) = "
61                  + t1.calculateTrackProgressionListActive(80));
62          System.out.println("t1.active(99) = "
63                  + t1.calculateTrackProgressionListActive(99));
64          System.out.println("t1.active(100) = "
65                  + t1.calculateTrackProgressionListActive(100));
66          System.out.println("t1.active(110) = "
67                  + t1.calculateTrackProgressionListActive(110));
68          System.out.println("t1.active(240) = "
69                  + t1.calculateTrackProgressionListActive(240));
70          System.out.println("t1.active(340) = "
71                  + t1.calculateTrackProgressionListActive(340));
72          System.out.println("t1.active(440) = "
73                  + t1.calculateTrackProgressionListActive(440));
74          System.out.println("\nBACKWARD ACTIVE:");
75          System.out.println("t5.active(-40) = "
76                  + t5.calculateTrackProgressionListActive(-40));
77          System.out.println("t5.active(-80) = "
78                  + t5.calculateTrackProgressionListActive(-80));
79          System.out.println("t5.active(-99) = "
80                  + t5.calculateTrackProgressionListActive(-99));
81          System.out.println("t5.active(-100) = "
82                  + t5.calculateTrackProgressionListActive(-100));
83          System.out.println("t5.active(-110) = "
84                  + t5.calculateTrackProgressionListActive(-110));
85          System.out.println("t5.active(-240) = "
86                  + t5.calculateTrackProgressionListActive(-240));
87          System.out.println("t5.active(-340) = "
88                  + t5.calculateTrackProgressionListActive(-340));
89          System.out.println("t5.active(-390) = "
90                  + t5.calculateTrackProgressionListActive(-390));
91          System.out.println("\nFORWARD ALL:");
92          System.out.println("t1.All(40) = "
93                  + printList(t1.calculateTrackProgressionListAll(40)));
94          System.out.println("t1.All(80) = "
95                  + printList(t1.calculateTrackProgressionListAll(80)));
96          System.out.println("t1.All(99) = "
97                  + printList(t1.calculateTrackProgressionListAll(99)));
98          System.out.println("t1.All(100) = "
99                  + printList(t1.calculateTrackProgressionListAll(100)));
100         System.out.println("t1.All(110) = "
101                 + printList(t1.calculateTrackProgressionListAll(110)));
102         System.out.println("t1.All(240) = "
103                 + printList(t1.calculateTrackProgressionListAll(240)));
104         System.out.println("t1.All(340) = "
105                 + printList(t1.calculateTrackProgressionListAll(340)));
106         System.out.println("t1.All(440) = "
107                 + printList(t1.calculateTrackProgressionListAll(440)));
108         System.out.println("\nBACKWARD ALL:");
109         System.out.println("t5.All(-40) = "
110                 + printList(t5.calculateTrackProgressionListAll(-40)));
111         System.out.println("t5.All(-80) = "
112                 + printList(t5.calculateTrackProgressionListAll(-80)));
113         System.out.println("t5.All(-99) = "
114                 + printList(t5.calculateTrackProgressionListAll(-99)));
115         System.out.println("t5.All(-100) = "
116                 + printList(t5.calculateTrackProgressionListAll(-100)));
117         System.out.println("t5.All(-110) = "
118                 + printList(t5.calculateTrackProgressionListAll(-110)));
119         System.out.println("t5.All(-240) = "
120                 + printList(t5.calculateTrackProgressionListAll(-240)));
121         System.out.println("t5.All(-340) = "
122                 + printList(t5.calculateTrackProgressionListAll(-340)));
123         System.out.println("t5.All(-390) = "
124                 + printList(t5.calculateTrackProgressionListAll(-390)));
125     }
126 
127     /***
128      * @param list
129      * @return
130      */
131     private String printList(final List list)
132     {
133         String s = "{";
134         for (int i = 0; i < list.size(); i++)
135         {
136             TrackProgression tp = (TrackProgression) list.get(i);
137             if (s.length() > 1)
138                 s = s + ", ";
139             s = s + tp.toString();
140         }
141         s = s + "}";
142         return s;
143     }
144 
145     /***
146      * @param args
147      */
148     public static void main(final String[] args)
149     {
150         new TestTrack();
151     }
152 }