Changeset 8461
- Timestamp:
- 08/09/12 16:17:37 (12 years ago)
- Location:
- branches/RoutePlanning
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/HeuristicLab.Algorithms.GraphRouting.csproj
r8423 r8461 60 60 <Compile Include="AStarAlgorithmV2.cs" /> 61 61 <Compile Include="BidirectionalDijkstraAlgorithm.cs" /> 62 <Compile Include="DijkstraAlgorithmV2.cs" /> 62 63 <Compile Include="DijkstraAlgorithm.cs" /> 63 64 <Compile Include="GraphRoutingAlgorithm.cs" /> -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Edge.cs
r8438 r8461 32 32 return string.Format("{0}->{1}", this.Source, this.Target); 33 33 } 34 35 public override bool Equals(object obj) { 36 if (obj is Edge<Vertex>) { 37 Edge<Vertex> e = (obj as Edge<Vertex>); 38 return (this.source.Equals(e.source)) && (this.target.Equals(e.target)); 39 } 40 return false; 41 } 42 43 public override int GetHashCode() { 44 return source.GetHashCode() ^ target.GetHashCode(); 45 } 34 46 } 35 47 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Graph.cs
r8438 r8461 3 3 using System.Collections.Generic; 4 4 namespace HeuristicLab.Problems.RoutePlanning.Graph { 5 public class Graph {5 public class Graph : IGraph { 6 6 private IDictionary<long, Vertex> vertices; 7 7 private IDictionary<long, List<Edge<Vertex>>> adjacencyMap; … … 11 11 vertices = new Dictionary<long, Vertex>(); 12 12 adjacencyMap = new Dictionary<long, List<Edge<Vertex>>>(); 13 incidenceMap = new Dictionary<long, List<Edge<Vertex>>>(); 13 14 } 14 15 15 16 public void AddVertex(Vertex vertex) { 16 vertices.Add(vertex.Id, vertex); 17 if (!vertices.ContainsKey(vertex.Id)) { 18 vertices.Add(vertex.Id, vertex); 19 } 17 20 } 18 21 … … 32 35 //edge.Category = -1 33 36 34 if (adjacencyMap[start.Id] == null) { 35 adjacencyMap[start.Id] = new List<Edge<Vertex>>(); 37 AddEdge(edge); 38 } 39 40 public void AddEdge(Edge<Vertex> edge) { 41 if (!adjacencyMap.ContainsKey(edge.Source.Id)) { 42 adjacencyMap.Add(edge.Source.Id, new List<Edge<Vertex>>()); 36 43 } 37 adjacencyMap[ start.Id].Add(edge);44 adjacencyMap[edge.Source.Id].Add(edge); 38 45 39 if ( incidenceMap[end.Id] == null) {40 incidenceMap [end.Id] = new List<Edge<Vertex>>();46 if (!incidenceMap.ContainsKey(edge.Target.Id)) { 47 incidenceMap.Add(edge.Target.Id, new List<Edge<Vertex>>()); 41 48 } 42 incidenceMap[end.Id].Add(edge); 49 incidenceMap[edge.Target.Id].Add(edge); 50 } 51 52 public void RemoveEdge(long startId, long endId) { 53 Edge<Vertex> edge = GetEdge(startId, endId); 54 if (edge != null) { 55 adjacencyMap[startId].Remove(edge); 56 incidenceMap[endId].Remove(edge); 57 } 58 } 59 60 public bool HasEdge(long startId, long endId) { 61 Edge<Vertex> edge = GetEdge(startId, endId); 62 return (edge != null); 43 63 } 44 64 … … 55 75 public List<Edge<Vertex>> GetInEdges(long vertexId) { 56 76 return incidenceMap[vertexId]; 77 } 57 78 79 public int GetInDegree(long vertexId) { 80 return incidenceMap[vertexId].Count; 58 81 } 59 82 … … 61 84 return adjacencyMap[vertexId]; 62 85 } 86 87 public int GetOutDegree(long vertexId) { 88 return adjacencyMap[vertexId].Count; 89 } 90 91 public List<Edge<Vertex>> GetEdges(long vertexId) { 92 List<Edge<Vertex>> result = new List<Edge<Vertex>>(); 93 foreach (Edge<Vertex> edge in GetInEdges(vertexId)) { 94 if (!result.Contains(edge)) { 95 result.Add(edge); 96 } 97 } 98 foreach (Edge<Vertex> edge in GetOutEdges(vertexId)) { 99 if (!result.Contains(edge)) { 100 result.Add(edge); 101 } 102 } 103 return result; 104 } 105 106 public Dictionary<long, float> GetNeighborsWithWeight(long id) { 107 Dictionary<long, float> neighbors = new Dictionary<long, float>(); 108 List<Edge<Vertex>> edges = GetOutEdges(id); 109 foreach (Edge<Vertex> edge in edges) { 110 // TODO: check if edge can be traversed (eg. highway tag for car roads, ...) 111 float weight = 1; // TODO: edge.Weight? 112 neighbors[edge.Target.Id] = weight; 113 } 114 return neighbors; 115 } 116 public Dictionary<long, float> GetNeighborsWithWeightReversed(long id) { 117 Dictionary<long, float> neighbors = new Dictionary<long, float>(); 118 List<Edge<Vertex>> edges = GetInEdges(id); 119 foreach (Edge<Vertex> edge in edges) { 120 // TODO: check if edge can be traversed (eg. highway tag for car roads, ...) 121 float weight = 1; // TODO: edge.Weight? 122 neighbors[edge.Source.Id] = weight; 123 } 124 return neighbors; 125 } 63 126 } 64 127 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/IGraph.cs
r8438 r8461 2 2 using System.Collections.Generic; 3 3 namespace HeuristicLab.Problems.RoutePlanning.Graph { 4 interface IGraph {4 public interface IGraph { 5 5 void AddVertex(Vertex vertex); 6 6 Vertex GetVertex(long id); 7 7 void AddEdge(long startId, long endId); 8 void AddEdge(Edge<Vertex> edge); 8 9 void RemoveEdge(long startId, long endId); 9 10 bool HasEdge(long startId, long endId); -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Vertex.cs
r8438 r8461 50 50 if (obj is Vertex) { 51 51 Vertex v = (obj as Vertex); 52 return this.Equals(v);52 return (this.id == v.id); //TODO: 53 53 } 54 54 return false;
Note: See TracChangeset
for help on using the changeset viewer.