root/trunk/PhysicalNode.java

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

old pathways project added

Line 
1 // PhysicalNode - copyright Tom Felker, <tfelker2@uiuc.edu>, December 2004
2 //
3 // subclass of Node which adds position to a node
4
5 import java.io.*;
6 import java.awt.geom.*;
7
8 public class PhysicalNode extends Node implements Serializable {
9         static final long serialVersionUID = 4056794241108685089L;
10        
11         public PhysicalNode(int id) {
12                 super(id);
13                 point = new Point2D.Double();
14         }
15
16         public PhysicalNode(int id, double x, double y) {
17                 super(id);
18                 point = new Point2D.Double(x, y);
19         }
20
21        
22         // for debug purposes
23         public String toString() {
24                 return "PhysicalNode\n" + infoToString();
25         }
26
27         public String infoToString() {
28                 return super.infoToString() + "\tx=" + point.getX() + "\n\ty=" + point.getY() + "\n";   
29         }
30        
31        
32         // returns a double representing our distance to the other node
33         // only called by Edges
34         public double distanceTo(PhysicalNode other) {
35                 return point.distance(other.point);
36         }
37
38         //WARNING: HCost cannot use previousNode otherwise it will break BusNode
39         public Cost computeHCost(Search s, Node previousNode) {
40                 // heuristics go here
41                 //return new Cost(0);
42                 return new Cost(point.distance(s.destination.point) / s.fastestTransportationSpeed);
43         }
44
45         // for some stupid reason, points aren't serializable, so we must do it
46         // ourselves - and I could make another serializable class, but i'm lazy
47         // Note, this class is no longer serializeable.
48         private void writeObject(java.io.ObjectOutputStream out) throws IOException {
49                         out.writeDouble(point.x);
50                         out.writeDouble(point.y);
51         }
52
53         private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
54                 point = new Point2D.Double(in.readDouble(), in.readDouble());
55         }
56
57
58         public transient Point2D.Double point;
59 }
Note: See TracBrowser for help on using the browser.