Ignore:
Timestamp:
2009-04-26T13:58:25+02:00 (15 years ago)
Author:
jvidal
Message:
 
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  
    9797//      private WeightedMultigraph<Node, OsmEdge> graph;
    9898        private Graph<Node, OsmEdge> graph;
     99        private RoutingGraphDelegator rgDelegator=null;
    99100
    100101        /**
     
    126127                logger.debug("Creating Graph...");
    127128                graph = new DirectedWeightedMultigraph<Node, OsmEdge>(OsmEdge.class);
    128 
     129                rgDelegator=new RoutingGraphDelegator(graph);
     130                rgDelegator.setRouteType(this.routeType);
    129131                // iterate all ways and segments for all nodes:
    130132                for (Way way : data.ways) {
     
    159161        private void addEdge(Way way,Node from, Node to) {
    160162                double length = from.coor.greatCircleDistance(to.coor);
    161                 // edge = new OsmEdge(way, length);
     163               
    162164                OsmEdge edge = new OsmEdge(way, from, to);
     165                edge.setSpeed(12.1);
    163166                graph.addEdge(from, to, edge);
    164167                // weight = getWeight(way);
    165168                double weight = getWeight(way, length);
     169                getWeight(edge, length);
    166170                logger.debug("edge for way " + way.id
    167171                                     + "(from node " + from.id + " to node "
     
    180184         * @return
    181185         */
     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         */
    182203        private double getWeight(Way way, double length) {
    183204                // Default speed if no setting is found
     
    202223                return length / speed;
    203224        }
    204 
     225       
    205226        /**
    206227         * Check is One Way.
     
    268289                else
    269290                        g = new AsUndirectedGraph<Node, OsmEdge>((DirectedWeightedMultigraph<Node,OsmEdge>)graph);
    270 
     291                //TODO: Problemas no tiene encuenta el tema de oneway.
    271292                switch (algorithm) {
    272293                case ROUTING_ALG_DIJKSTRA:
     
    274295                        DijkstraShortestPath<Node, OsmEdge> routingk = null;
    275296                        for (int index = 1; index < nodes.size(); ++index) {
    276                                 routingk = new DijkstraShortestPath<Node, OsmEdge>(g, nodes
     297                                routingk = new DijkstraShortestPath<Node, OsmEdge>(rgDelegator, nodes
    277298                                                .get(index - 1), nodes.get(index));
    278299                                if (routingk.getPathEdgeList() == null) {
     
    287308                        logger.debug("Using Bellman Ford algorithm");
    288309                        for (int index = 1; index < nodes.size(); ++index) {
    289                                 path = BellmanFordShortestPath.findPathBetween(g, nodes
     310                                path = BellmanFordShortestPath.findPathBetween(rgDelegator, nodes
    290311                                                .get(index - 1), nodes.get(index));
    291312                                if (path == null) {
     
    330351        public void setTypeRoute(RouteType routetype) {
    331352                this.routeType = routetype;
     353                this.rgDelegator.setRouteType(routetype);
    332354        }
    333355
  • applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraphDelegator.java

    r14287 r14760  
    77import org.jgrapht.Graph;
    88import org.jgrapht.graph.GraphDelegator;
     9import org.openstreetmap.josm.data.osm.Node;
     10
     11import com.innovant.josm.jrt.core.RoutingGraphDelegator;
     12import com.innovant.josm.jrt.core.RoutingGraph.RouteType;
     13import com.innovant.josm.jrt.osm.OsmEdge;
    914
    1015/**
     
    1217 *
    1318 */
    14 public class RoutingGraphDelegator<V, E> extends GraphDelegator<V, E> {
     19public class RoutingGraphDelegator extends GraphDelegator<Node, OsmEdge> {
    1520
    1621        /**
     
    1924        static Logger logger = Logger.getLogger(RoutingGraphDelegator.class);
    2025       
    21         public String name;
     26        /**
     27         *
     28         */
     29        private RouteType routeType;
    2230       
     31        public RoutingGraphDelegator(Graph<Node, OsmEdge> arg0) {
     32                super(arg0);
     33        }
    2334       
     35
     36        public RouteType getRouteType() {
     37                return routeType;
     38        }
     39
     40        public void setRouteType(RouteType routeType) {
     41                this.routeType = routeType;
     42        }
     43
    2444
    2545        /**
     
    2848        private static final long serialVersionUID = 1L;
    2949
    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;
    3358        }
    34        
    35         @Override
    36         public double getEdgeWeight(E arg0) {
    37                 logger.debug("call getEdgeWeight");
    38                 return super.getEdgeWeight(arg0);
    39         }
     59
    4060}
  • applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/osm/OsmEdge.java

    r14287 r14760  
    3232import org.openstreetmap.josm.data.osm.Way;
    3333
     34/**
     35 * Class that represents an edge of the graph.
     36 * @author jose
     37 */
    3438public class OsmEdge extends DefaultWeightedEdge {
    3539 /**
     
    3741  */
    3842  private static final long serialVersionUID = 1L;
     43  /**
     44   * Way associated
     45   */
    3946  private Way way;
     47  /**
     48   * Nodes in the edge
     49   */
    4050  private Node from, to;
     51  /**
     52   * Length edge
     53   */
    4154  private double length;
     55  /**
     56   * Speed edge.
     57   */
     58  private double speed;
    4259
    43   /**
     60
     61/**
    4462   * Constructor
    4563   * @param way
     
    7694        return length;
    7795  }
     96 
     97  public void setLength(double length) {
     98        this.length = length;
     99}
    78100
     101public double getSpeed() {
     102                return speed;
     103  }
     104
     105  public void setSpeed(double speed) {
     106                this.speed = speed;
     107  }
    79108}
  • applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java

    r14404 r14760  
    9999                                                routingModel.routingGraph.setTypeRoute(RouteType.FASTEST);
    100100                                        }
    101                                         routingModel.routingGraph.resetGraph();
    102                                         routingModel.routingGraph.createGraph();
     101                                //      routingModel.routingGraph.resetGraph();
     102                                //      routingModel.routingGraph.createGraph();
    103103                                        //TODO: Change this way
    104104                                        //FIXME: do not change node but recalculate routing.
     
    111111
    112112                JRadioButtonMenuItem rfaster = new JRadioButtonMenuItem(tr("Fastest"));
    113 
    114113                group.add(rshorter);
    115114                group.add(rfaster);
Note: See TracChangeset for help on using the changeset viewer.