001 package dk.deepthought.sidious.planner.graph;
002
003 import dk.deepthought.sidious.supportsystem.Step;
004
005 /**
006 * This class represent an edge in an A*-graph.
007 *
008 * @author Deepthought
009 *
010 */
011 public final class AStarEdge implements Edge {
012
013 /**
014 * The start vertex.
015 */
016 private final Vertex startVertex;
017
018 /**
019 * The end vertex.
020 */
021 private final Vertex endVertex;
022
023 /**
024 * The cost of this edge.
025 */
026 private final double cost;
027
028 /**
029 * The step of to this edge.
030 */
031 private final Step step;
032
033 /**
034 * @param startVertex
035 * a vertex defining the startpoint of this edge
036 * @param endVertex
037 * a vertex defining the endpoint of this edge
038 * @param step
039 * the origin of this edge
040 * @param cost
041 * the weight of this edge
042 */
043 public AStarEdge(Vertex startVertex, Vertex endVertex, Step step,
044 double cost) {
045 this.startVertex = startVertex;
046 this.endVertex = endVertex;
047 this.step = step;
048 this.cost = cost;
049 }
050
051 /*
052 * (non-Javadoc)
053 *
054 * @see dk.deepthought.sidious.planner.Edge#getCost()
055 */
056 public double getCost() {
057 return cost;
058 }
059
060 /*
061 * (non-Javadoc)
062 *
063 * @see dk.deepthought.sidious.planner.Edge#getEndVertex()
064 */
065 public Vertex getEndVertex() {
066 return endVertex;
067 }
068
069 /*
070 * (non-Javadoc)
071 *
072 * @see dk.deepthought.sidious.planner.Edge#getStartVertex()
073 */
074 public Vertex getStartVertex() {
075 return startVertex;
076 }
077
078 /*
079 * (non-Javadoc)
080 *
081 * @see dk.deepthought.sidious.planner.Edge#getStep()
082 */
083 public Step getStep() {
084 return step;
085 }
086
087 /*
088 * (non-Javadoc)
089 *
090 * @see java.lang.Object#toString()
091 */
092 @Override
093 public String toString() {
094 return getClass().getSimpleName() + "[step=" + step + "]";
095 }
096
097 /*
098 * (non-Javadoc)
099 *
100 * @see java.lang.Object#hashCode()
101 */
102 @Override
103 public int hashCode() {
104 final int PRIME = 31;
105 int result = 1;
106 long temp;
107 temp = Double.doubleToLongBits(cost);
108 result = PRIME * result + (int) (temp ^ (temp >>> 32));
109 result = PRIME * result
110 + ((endVertex == null) ? 0 : endVertex.hashCode());
111 result = PRIME * result
112 + ((startVertex == null) ? 0 : startVertex.hashCode());
113 result = PRIME * result + ((step == null) ? 0 : step.hashCode());
114 return result;
115 }
116
117 /*
118 * (non-Javadoc)
119 *
120 * @see java.lang.Object#equals(java.lang.Object)
121 */
122 @Override
123 public boolean equals(Object obj) {
124 if (this == obj)
125 return true;
126 if (obj == null)
127 return false;
128 if (getClass() != obj.getClass())
129 return false;
130 final AStarEdge other = (AStarEdge) obj;
131 if (Double.doubleToLongBits(cost) != Double
132 .doubleToLongBits(other.cost))
133 return false;
134 if (endVertex == null) {
135 if (other.endVertex != null)
136 return false;
137 } else if (!endVertex.equals(other.endVertex))
138 return false;
139 if (startVertex == null) {
140 if (other.startVertex != null)
141 return false;
142 } else if (!startVertex.equals(other.startVertex))
143 return false;
144 if (step == null) {
145 if (other.step != null)
146 return false;
147 } else if (!step.equals(other.step))
148 return false;
149 return true;
150 }
151 }
|