|
Revision 3, 1.7 kB
(checked in by dpaola2, 1 week ago)
|
old pathways project added
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 33 |
|
|---|
| 34 |
public double distanceTo(PhysicalNode other) { |
|---|
| 35 |
return point.distance(other.point); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
public Cost computeHCost(Search s, Node previousNode) { |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
return new Cost(point.distance(s.destination.point) / s.fastestTransportationSpeed); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 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 |
} |
|---|