root/trunk/BusNode.java

Revision 3, 3.6 kB (checked in by dpaola2, 1 week ago)

old pathways project added

Line 
1 /**
2  * <p>Title: Bus Node </p>
3  *
4  * <p>Description:
5  * To explain how bus nodes work, each bus node represents a whole route. For
6  * a search to consider riding a bus, this is how it works....
7  *
8  * PhysicalNode(GetOn) -> BusNode -> PhysicalNode(GetOff)
9  *
10  * PhysicalNode(GetOn) is the physical location where you get on the bus
11  * PhysicalNode(GetOff) is the physical location where you get off the bus
12  *
13  * DeltaGCost PhysicalNode(GetOn) -> BusNode is equal to the time to wait to
14  * get on the bus
15  *
16  * DeltaGCost BusNode -> PhysicalNode(GetOff) is equal to the time it takes for
17  * the bus to transit from the stop at PhysicalNode(GetOn) to the stop at
18  * PhysicalNode(GetOff)
19  *
20  * HCost (BusNode) -> To make our implementation fit validity in A* search, I have
21  * the HCost computed to be the same as the HCost for PhysicalNode(GetOn)</p>
22  *
23  * <p>Copyright: Copyright (c) 2005</p>
24  *
25  * <p>Group: Special Interest Group for Software Engineering</p>
26  *
27  *
28  * @author not attributable
29  * @version 1.0
30  */
31
32 import java.io.*;
33 import java.awt.geom.*;
34
35 public class BusNode extends Node implements Serializable
36 {
37     //map from a busEdge object to an ID in the bus schedule.
38     int[] mappingIds;
39
40     //the bus schedule object will keep track of ALL bus schedules
41     DummyBusSchedule busSchedules;
42
43     public BusNode(int pId) {
44         super(pId);
45         //
46     }
47
48     public BusNode(int pId, DummyBusSchedule pSched, String pRouteIdentifier, int length)
49     {
50         super(pId);
51         busSchedules = pSched;
52         super.setDescription(pRouteIdentifier);
53         mappingIds = new int[length];
54     }
55
56     public BusNode(String pRouteIdentifier, int pId)
57     {
58         super(pId);
59         super.setDescription(pRouteIdentifier);
60     }
61
62     public int GetNodeIndex(int nodeId)
63     {
64         for(int i = 0; i < mappingIds.length; i++)
65         {
66             if(mappingIds[i] == nodeId)
67             {
68                 return i;
69             }
70         }
71         return -1;
72     }
73
74
75     public void BindPhyisicalNodeToIndex(int nodeId, int index)
76     {
77         mappingIds[index] = nodeId;
78     }
79
80     public int RouteLength()
81     {
82         return mappingIds.length;
83     }
84
85     public String RouteIdentifier(int index)
86     {
87         //HACK:
88         return "";
89     }
90
91     public Cost ComputeWaitTime(Node busRideOrigination, Cost gCostOrigination, Search s)
92     {
93         //store the from id into the cost object so it can be retrieved
94         // when computing transit time
95
96         //the returned cost object will be the g cost for the bus node
97         int originationIndex = this.GetNodeIndex(busRideOrigination.id);
98         Cost gCostBusNode = busSchedules.eWaitTimeForRoute(this.id, originationIndex, gCostOrigination);
99         gCostBusNode.physicalNodeGotOntoBus = busRideOrigination;
100         return gCostBusNode;
101     }
102
103     public Cost ComputeTransitTime(Node busRideDestination, Cost gCostBusNode, Search s)
104     {
105         //TODO: what if no from edge given for sure?
106
107         //Edgeid of from is stored in cost.
108         int fromIndex = this.GetNodeIndex(gCostBusNode.physicalNodeGotOntoBus.id);
109         int toIndex = this.GetNodeIndex(busRideDestination.id);
110         return busSchedules.eTransTimeFor(this.id, fromIndex, toIndex, gCostBusNode);
111     }
112
113     public Cost computeHCost(Search S, Node previousNode)
114     {
115             // I really think this is will very often overestimate the h-cost,
116             // which is bad - since we don't know, it's better to return 0.
117             // I'll leave it for now because I don't have time to test changes,
118             // and because this whole class is a bit of a hack anyway.
119             // -- Tom
120             return previousNode.computeHCost(S, this);
121     }
122 }
Note: See TracBrowser for help on using the browser.