Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Data.Osm.Core/Way.cs @ 15301

Last change on this file since 15301 was 8520, checked in by spimming, 12 years ago

#1894:

  • extended datasource interface to get routing graph for a specific vehicle type
  • use ICostCalculator to calculate edge weights
  • moved common enums in own file
  • removed method to estimate cost from graph; use ICostCalculator
File size: 3.3 KB
Line 
1
2using System;
3using System.Collections.Generic;
4using HeuristicLab.Problems.RoutePlanning.Data.Core;
5namespace HeuristicLab.Problems.RoutePlanning.Data.Osm.Core {
6  public class Way : OsmBase {
7    private List<Node> nodes;
8
9    public Way() {
10      nodes = new List<Node>();
11    }
12
13    public Way(long id)
14      : base(id) {
15      nodes = new List<Node>();
16    }
17
18    public List<Node> Nodes {
19      get { return nodes; }
20    }
21
22    public HighwayType HighwayTag {
23      get {
24        if (!base.Tags.ContainsKey(TagConstants.HighwayTagKey)) {
25          return HighwayType.null_type;
26        }
27        if (Enum.IsDefined(typeof(HighwayType), base.Tags[TagConstants.HighwayTagKey])) {
28          HighwayType ht = (HighwayType)Enum.Parse(
29            typeof(HighwayType),
30            base.Tags[TagConstants.HighwayTagKey],
31            true);
32          return ht;
33        } else {
34          return HighwayType.null_type;
35        }
36      }
37    }
38
39    public bool OneWay {
40      get {
41        if (base.Tags.ContainsKey(TagConstants.OneWayTag)) {
42          string value = base.Tags[TagConstants.OneWayTag];
43          return value.Equals(TagConstants.YesValue);
44        } else {
45          return false;
46        }
47      }
48    }
49
50    public bool CanBeTraversed(Node source, Node target) {
51      // check if way can be traveld by a specific vehicle (car, public transport, pedestiran, bicycle)
52      // if (!CanBeTraversed(Vehicle)) return false
53      if (OneWay) {
54        // if vehicle == pedestrian or bicylce -> return true
55        int sourceIndex = Nodes.IndexOf(source);
56        int targetIndex = Nodes.IndexOf(target);
57        // order of the nodes determines the driving direction
58        return (sourceIndex < targetIndex);
59      }
60      return true;
61    }
62
63    //public bool CanBeTraversed(Vehicle) {}
64
65    public int GetMaxSpeed() {
66      int speed = 0;
67
68      //TODO:
69      HighwayType highwayType = HighwayTag;
70      switch (highwayType) {
71        case HighwayType.bridleway:
72        case HighwayType.bus_guideway:
73        case HighwayType.raceway:
74        case HighwayType.cycleway:
75        case HighwayType.footway:
76        case HighwayType.steps:
77        case HighwayType.null_type:
78          speed = 1;
79          break;
80
81        case HighwayType.path:
82        case HighwayType.service:
83        case HighwayType.pedestrian:
84        case HighwayType.living_street:
85          speed = 15;
86          break;
87
88        case HighwayType.road:
89        case HighwayType.track:
90          speed = 30;
91          break;
92
93        case HighwayType.tertiary:
94        case HighwayType.tertiary_link:
95        case HighwayType.secondary:
96        case HighwayType.secondary_link:
97          speed = 80;
98          break;
99
100        case HighwayType.unclassified:
101        case HighwayType.residential:
102          speed = 50;
103          break;
104
105        case HighwayType.trunk:
106        case HighwayType.trunk_link:
107        case HighwayType.primary:
108        case HighwayType.primary_link:
109          speed = 100;
110          break;
111        case HighwayType.motorway:
112        case HighwayType.motorway_link:
113          speed = 130;
114          break;
115
116        default:
117          speed = 1;
118          break;
119      }
120      return speed;
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.