Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/09/12 16:20:19 (12 years ago)
Author:
spimming
Message:

#1894:

  • calculate distance in kilometers for two locations
  • generate IGraph from a datasource
  • adapted test program
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm.Data/XmlDataSource.cs

    r8316 r8462  
    11
     2using System;
    23using System.Collections.Generic;
    34using System.IO;
    45using System.Xml;
     6using HeuristicLab.Problems.RoutePlanning.Graph;
    57namespace HeuristicLab.Problems.RoutePlanning.Osm.Data {
    68  public class XmlDataSource : IDataSource {
     
    8284    }
    8385
    84     #endregion
     86    public IGraph GetRoutingGraph() {
     87      IGraph graph = new Graph.Graph();
     88      foreach (Way way in ways.Values) {
     89        List<Node> nodes = way.Nodes;
     90        for (int i = 0; i < way.Nodes.Count - 1; i++) {
     91          Vertex v1 = new Vertex(nodes[i].Id, nodes[i].Longitude, nodes[i].Latitude);
     92          graph.AddVertex(v1);
     93          Vertex v2 = new Vertex(nodes[i + 1].Id, nodes[i + 1].Longitude, nodes[i + 1].Latitude);
     94          if (v1.Id == 370626403) {
     95            Console.WriteLine();
     96          }
     97          graph.AddVertex(v2);
     98          if (way.OneWay) {
     99            Edge<Vertex> edge = new Edge<Vertex>(v1, v2);
     100            edge.Category = (short)way.HighwayTag;
     101            graph.AddEdge(edge);
     102          } else {
     103            Edge<Vertex> edgeForward = new Edge<Vertex>(v1, v2);
     104            edgeForward.Category = (short)way.HighwayTag;
     105            graph.AddEdge(edgeForward);
     106
     107            Edge<Vertex> edgeBackward = new Edge<Vertex>(v2, v1);
     108            edgeForward.Category = (short)way.HighwayTag;
     109            graph.AddEdge(edgeBackward);
     110          }
     111
     112        }
     113      }
     114      return graph;
     115    }
     116
     117    #endregion
     118
     119    #region Private Methods
    85120
    86121    private void ReadData() {
     
    214249      }
    215250    }
     251
     252    #endregion
    216253  }
    217254}
Note: See TracChangeset for help on using the changeset viewer.