1 25 41 package org.jgrapht.alg; 42 43 import org.jgrapht.*; 44 45 46 50 final class BellmanFordPathElement<V, E> 51 extends AbstractPathElement<V, E> 52 { 53 54 56 private static final double epsilon = 0.000000001; 57 58 60 private double cost = 0; 61 62 64 71 protected BellmanFordPathElement( 72 Graph<V, E> graph, 73 BellmanFordPathElement<V, E> pathElement, 74 E edge, 75 double cost) 76 { 77 super(graph, pathElement, edge); 78 79 this.cost = cost; 80 } 81 82 87 BellmanFordPathElement(BellmanFordPathElement<V, E> original) 88 { 89 super(original); 90 this.cost = original.cost; 91 } 92 93 98 protected BellmanFordPathElement(V vertex) 99 { 100 super(vertex); 101 102 this.cost = 0; 103 } 104 105 107 112 public double getCost() 113 { 114 return this.cost; 115 } 116 117 129 protected boolean improve( 130 BellmanFordPathElement<V, E> candidatePrevPathElement, 131 E candidateEdge, 132 double candidateCost) 133 { 134 if (candidateCost < (getCost() - epsilon)) { 136 this.prevPathElement = candidatePrevPathElement; 137 this.prevEdge = candidateEdge; 138 this.cost = candidateCost; 139 this.nHops = candidatePrevPathElement.getHopCount() + 1; 140 141 return true; 142 } else { 143 return false; 144 } 145 } 146 } 147 | Popular Tags |