| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
import java.io.*; |
|---|
| 7 |
|
|---|
| 8 |
public abstract class Edge implements Serializable { |
|---|
| 9 |
static final long serialVersionUID = 2843536174507280704L; |
|---|
| 10 |
|
|---|
| 11 |
public Edge(int a, int b) { |
|---|
| 12 |
aID = a; |
|---|
| 13 |
bID = b; |
|---|
| 14 |
} |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
public Node getNode(int id) { |
|---|
| 18 |
if(aID == id) return a; |
|---|
| 19 |
else if(bID == id) return b; |
|---|
| 20 |
throw new IllegalArgumentException(this + " doesn't have node " + id); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
public int getOtherID(Node n) { |
|---|
| 26 |
if(a == n) return bID; |
|---|
| 27 |
else if(b == n) return aID; |
|---|
| 28 |
throw new IllegalArgumentException(this + " doesn't have node " + n.id); |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
public int getOtherID(int id) { |
|---|
| 33 |
if(aID == id) return bID; |
|---|
| 34 |
else if(bID == id) return aID; |
|---|
| 35 |
throw new IllegalArgumentException(this + " doesn't have node " + id); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
public Node getOtherNode(int id) { |
|---|
| 40 |
if(aID == id) return b; |
|---|
| 41 |
else if(bID == id) return a; |
|---|
| 42 |
throw new IllegalArgumentException(this + " doesn't have node " + id); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
public Node getOtherNode(Node n) { |
|---|
| 47 |
if(a == n) return b; |
|---|
| 48 |
else if(b == n) return a; |
|---|
| 49 |
throw new IllegalArgumentException(this + " doesn't have node " + n.id); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
public boolean hasNode(Node n) { return a == n || b == n; } |
|---|
| 54 |
public boolean hasNode(int id) { return aID == id || bID == id; } |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
public Node getNodeA() { return a; } |
|---|
| 59 |
public Node getNodeB() { return b; } |
|---|
| 60 |
public void setNodeA(Node a) { |
|---|
| 61 |
if(a.id != aID) throw new IllegalArgumentException("a.id != this.aID"); |
|---|
| 62 |
this.a = a; |
|---|
| 63 |
} |
|---|
| 64 |
public void setNodeB(Node b) { |
|---|
| 65 |
if(b.id != bID) throw new IllegalArgumentException("b.id != this.bID"); |
|---|
| 66 |
this.b = b; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
public void setNode(Node n) { |
|---|
| 70 |
if(n.id == aID) a = n; |
|---|
| 71 |
else if(n.id == bID) b = n; |
|---|
| 72 |
else throw new IllegalArgumentException(this + " doesn't have node " + n.id); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
public Node getNodeN(int n) { |
|---|
| 77 |
return n == 0 ? a : b; |
|---|
| 78 |
} |
|---|
| 79 |
public int getNID(int n) { |
|---|
| 80 |
return n == 0 ? aID : bID; |
|---|
| 81 |
} |
|---|
| 82 |
public void setNodeN(int n, Node node) { |
|---|
| 83 |
if(n == 0) setNodeA(node); else setNodeB(node); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
public boolean equals(Object o) { |
|---|
| 90 |
return (o instanceof Edge) && ( |
|---|
| 91 |
(aID == ((Edge)o).aID && bID == ((Edge)o).bID) || |
|---|
| 92 |
(aID == ((Edge)o).bID && bID == ((Edge)o).aID) |
|---|
| 93 |
); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
public int hashCode() { |
|---|
| 98 |
return aID * bID; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
public abstract Cost computeDeltaGCost(Node from, Cost gCostOfFrom, Search s); |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
public boolean isOnMap(BackgroundMap m) { |
|---|
| 109 |
return true; |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
public String toString() { |
|---|
| 113 |
return "Edge(" + aID + ", " + bID + ")"; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
public final int aID, bID; |
|---|
| 117 |
|
|---|
| 118 |
private transient Node a, b; |
|---|
| 119 |
} |
|---|