Changeset 14760 in osm for applications/editors/josm/plugins/routing/src/com
- Timestamp:
- 2009-04-26T13:58:25+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/routing/src/com/innovant/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraph.java
r14404 r14760 97 97 // private WeightedMultigraph<Node, OsmEdge> graph; 98 98 private Graph<Node, OsmEdge> graph; 99 private RoutingGraphDelegator rgDelegator=null; 99 100 100 101 /** … … 126 127 logger.debug("Creating Graph..."); 127 128 graph = new DirectedWeightedMultigraph<Node, OsmEdge>(OsmEdge.class); 128 129 rgDelegator=new RoutingGraphDelegator(graph); 130 rgDelegator.setRouteType(this.routeType); 129 131 // iterate all ways and segments for all nodes: 130 132 for (Way way : data.ways) { … … 159 161 private void addEdge(Way way,Node from, Node to) { 160 162 double length = from.coor.greatCircleDistance(to.coor); 161 // edge = new OsmEdge(way, length);163 162 164 OsmEdge edge = new OsmEdge(way, from, to); 165 edge.setSpeed(12.1); 163 166 graph.addEdge(from, to, edge); 164 167 // weight = getWeight(way); 165 168 double weight = getWeight(way, length); 169 getWeight(edge, length); 166 170 logger.debug("edge for way " + way.id 167 171 + "(from node " + from.id + " to node " … … 180 184 * @return 181 185 */ 186 private void getWeight(OsmEdge osmedge, double length) { 187 188 osmedge.setLength(length); 189 if (this.waySpeeds.containsKey(osmedge.getWay().get("highway"))) 190 osmedge.setSpeed(this.waySpeeds.get(osmedge.getWay().get("highway"))); 191 192 } 193 194 /** 195 * Returns the weight for the given segment depending on the highway type 196 * and the length of the segment. The higher the value, the less it is used 197 * in routing. 198 * 199 * @param way 200 * the way. 201 * @return 202 */ 182 203 private double getWeight(Way way, double length) { 183 204 // Default speed if no setting is found … … 202 223 return length / speed; 203 224 } 204 225 205 226 /** 206 227 * Check is One Way. … … 268 289 else 269 290 g = new AsUndirectedGraph<Node, OsmEdge>((DirectedWeightedMultigraph<Node,OsmEdge>)graph); 270 291 //TODO: Problemas no tiene encuenta el tema de oneway. 271 292 switch (algorithm) { 272 293 case ROUTING_ALG_DIJKSTRA: … … 274 295 DijkstraShortestPath<Node, OsmEdge> routingk = null; 275 296 for (int index = 1; index < nodes.size(); ++index) { 276 routingk = new DijkstraShortestPath<Node, OsmEdge>( g, nodes297 routingk = new DijkstraShortestPath<Node, OsmEdge>(rgDelegator, nodes 277 298 .get(index - 1), nodes.get(index)); 278 299 if (routingk.getPathEdgeList() == null) { … … 287 308 logger.debug("Using Bellman Ford algorithm"); 288 309 for (int index = 1; index < nodes.size(); ++index) { 289 path = BellmanFordShortestPath.findPathBetween( g, nodes310 path = BellmanFordShortestPath.findPathBetween(rgDelegator, nodes 290 311 .get(index - 1), nodes.get(index)); 291 312 if (path == null) { … … 330 351 public void setTypeRoute(RouteType routetype) { 331 352 this.routeType = routetype; 353 this.rgDelegator.setRouteType(routetype); 332 354 } 333 355 -
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraphDelegator.java
r14287 r14760 7 7 import org.jgrapht.Graph; 8 8 import org.jgrapht.graph.GraphDelegator; 9 import org.openstreetmap.josm.data.osm.Node; 10 11 import com.innovant.josm.jrt.core.RoutingGraphDelegator; 12 import com.innovant.josm.jrt.core.RoutingGraph.RouteType; 13 import com.innovant.josm.jrt.osm.OsmEdge; 9 14 10 15 /** … … 12 17 * 13 18 */ 14 public class RoutingGraphDelegator <V, E> extends GraphDelegator<V, E> {19 public class RoutingGraphDelegator extends GraphDelegator<Node, OsmEdge> { 15 20 16 21 /** … … 19 24 static Logger logger = Logger.getLogger(RoutingGraphDelegator.class); 20 25 21 public String name; 26 /** 27 * 28 */ 29 private RouteType routeType; 22 30 31 public RoutingGraphDelegator(Graph<Node, OsmEdge> arg0) { 32 super(arg0); 33 } 23 34 35 36 public RouteType getRouteType() { 37 return routeType; 38 } 39 40 public void setRouteType(RouteType routeType) { 41 this.routeType = routeType; 42 } 43 24 44 25 45 /** … … 28 48 private static final long serialVersionUID = 1L; 29 49 30 public RoutingGraphDelegator(Graph<V, E> arg0) { 31 super(arg0); 32 // TODO Auto-generated constructor stub 50 @Override 51 public double getEdgeWeight(OsmEdge edge) { 52 double weight=Double.MAX_VALUE; 53 54 if (routeType==RouteType.SHORTEST) weight=edge.getLength(); 55 if (routeType==RouteType.FASTEST) weight=edge.getLength() / edge.getSpeed(); 56 // Return the time spent to traverse the way 57 return weight; 33 58 } 34 35 @Override 36 public double getEdgeWeight(E arg0) { 37 logger.debug("call getEdgeWeight"); 38 return super.getEdgeWeight(arg0); 39 } 59 40 60 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/osm/OsmEdge.java
r14287 r14760 32 32 import org.openstreetmap.josm.data.osm.Way; 33 33 34 /** 35 * Class that represents an edge of the graph. 36 * @author jose 37 */ 34 38 public class OsmEdge extends DefaultWeightedEdge { 35 39 /** … … 37 41 */ 38 42 private static final long serialVersionUID = 1L; 43 /** 44 * Way associated 45 */ 39 46 private Way way; 47 /** 48 * Nodes in the edge 49 */ 40 50 private Node from, to; 51 /** 52 * Length edge 53 */ 41 54 private double length; 55 /** 56 * Speed edge. 57 */ 58 private double speed; 42 59 43 /** 60 61 /** 44 62 * Constructor 45 63 * @param way … … 76 94 return length; 77 95 } 96 97 public void setLength(double length) { 98 this.length = length; 99 } 78 100 101 public double getSpeed() { 102 return speed; 103 } 104 105 public void setSpeed(double speed) { 106 this.speed = speed; 107 } 79 108 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java
r14404 r14760 99 99 routingModel.routingGraph.setTypeRoute(RouteType.FASTEST); 100 100 } 101 routingModel.routingGraph.resetGraph();102 routingModel.routingGraph.createGraph();101 // routingModel.routingGraph.resetGraph(); 102 // routingModel.routingGraph.createGraph(); 103 103 //TODO: Change this way 104 104 //FIXME: do not change node but recalculate routing. … … 111 111 112 112 JRadioButtonMenuItem rfaster = new JRadioButtonMenuItem(tr("Fastest")); 113 114 113 group.add(rshorter); 115 114 group.add(rfaster);
Note:
See TracChangeset
for help on using the changeset viewer.