Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/13/12 17:31:23 (12 years ago)
Author:
spimming
Message:

#1894:

  • temporarily added weight and heuristic function to graph
  • store category information and max speed with edge
  • adapted Distance method
Location:
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Edge.cs

    r8461 r8479  
    4444      return source.GetHashCode() ^ target.GetHashCode();
    4545    }
     46
     47    public int GetMaxSpeed() {
     48      int speed = 0;
     49
     50      //TODO:
     51      switch (category) {
     52        case 23:
     53        case 17:
     54        case 18:
     55        case 22:
     56        case 21:
     57        case 24:
     58        case 0:
     59          speed = 1;
     60          break;
     61
     62        case 20:
     63        case 15:
     64        case 12:
     65        case 11:
     66          speed = 15;
     67          break;
     68
     69        case 19:
     70        case 16:
     71          speed = 30;
     72          break;
     73
     74        case 9:
     75        case 10:
     76        case 7:
     77        case 8:
     78          speed = 80;
     79          break;
     80
     81        case 14:
     82        case 13:
     83          speed = 50;
     84          break;
     85
     86        case 3:
     87        case 4:
     88        case 5:
     89        case 6:
     90          speed = 100;
     91          break;
     92
     93        case 1:
     94        case 2:
     95          speed = 130;
     96          break;
     97
     98        default:
     99          speed = 1;
     100          break;
     101      }
     102      return speed;
     103    }
    46104  }
    47105}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Graph.cs

    r8461 r8479  
    22using System;
    33using System.Collections.Generic;
     4using HeuristicLab.Problems.RoutePlanning.Osm;
    45namespace HeuristicLab.Problems.RoutePlanning.Graph {
    56  public class Graph : IGraph {
     
    7475
    7576    public List<Edge<Vertex>> GetInEdges(long vertexId) {
    76       return incidenceMap[vertexId];
     77      List<Edge<Vertex>> edges;
     78      if (incidenceMap.TryGetValue(vertexId, out edges)) {
     79        return edges;
     80      } else {
     81        return new List<Edge<Vertex>>();
     82      }
    7783    }
    7884
     
    8288
    8389    public List<Edge<Vertex>> GetOutEdges(long vertexId) {
    84       return adjacencyMap[vertexId];
     90      List<Edge<Vertex>> edges;
     91      if (adjacencyMap.TryGetValue(vertexId, out edges)) {
     92        return edges;
     93      } else {
     94        return new List<Edge<Vertex>>();
     95      }
     96
    8597    }
    8698
     
    109121      foreach (Edge<Vertex> edge in edges) {
    110122        // TODO: check if edge can be traversed (eg. highway tag for car roads, ...)
    111         float weight = 1; // TODO:  edge.Weight?
     123        float weight = GetWeight(edge); // TODO:  edge.Weight?
    112124        neighbors[edge.Target.Id] = weight;
    113125      }
     
    119131      foreach (Edge<Vertex> edge in edges) {
    120132        // TODO: check if edge can be traversed (eg. highway tag for car roads, ...)
    121         float weight = 1; // TODO:  edge.Weight?
     133        float weight = GetWeight(edge); // TODO:  edge.Weight?
    122134        neighbors[edge.Source.Id] = weight;
    123135      }
    124136      return neighbors;
    125137    }
     138
     139    public float GetWeight(Edge<Vertex> edge) {
     140      double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude,
     141                                       edge.Target.Logitude, edge.Target.Latitude);
     142      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
     143      int speed = edge.GetMaxSpeed();
     144      double weight = (distance / speed) * 3.6;
     145      //double weight = (distance / speed);
     146      return (float)weight;
     147    }
     148
     149    public float EstimatedCosts(long sourceId, long targetId) {
     150      Vertex source = GetVertex(sourceId);
     151      Vertex target = GetVertex(targetId);
     152      return EstimatedCosts(source, target);
     153    }
     154
     155    public float EstimatedCosts(Vertex source, Vertex target) {
     156      double distance = Utils.Distance(source.Logitude, source.Latitude,
     157                                       target.Logitude, target.Latitude);
     158      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
     159      int speed = 130;
     160      double costs = (distance / speed) * 3.6;
     161      //double costs = (distance / speed);
     162      return (float)costs;
     163    }
    126164  }
    127165}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/IGraph.cs

    r8461 r8479  
    1717    int GetOutDegree(long id);
    1818    int GetInDegree(long id);
     19
     20    float EstimatedCosts(long sourceId, long targetId);
    1921  }
    2022}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm/Utils.cs

    r8462 r8479  
    77      double dx = p2.X - p1.X;
    88      double dy = p2.Y - p1.Y;
     9      return Math.Sqrt(dx * dx + dy * dy);
     10    }
     11
     12    public static double Distance(double startX, double startY, double endX, double endY) {
     13      double dx = endX - startX;
     14      double dy = endY - startY;
    915      return Math.Sqrt(dx * dx + dy * dy);
    1016    }
Note: See TracChangeset for help on using the changeset viewer.