public void TestLiveEdgeDynamicGraphEdge10000() { int count = 10000; IDynamicGraph <LiveEdge> graph = this.CreateGraph(); uint vertex1 = graph.AddVertex(51, 1); while (count > 0) { uint vertex2 = graph.AddVertex(51, 1); graph.AddArc(vertex1, vertex2, new LiveEdge() { Tags = 0, Forward = false }, null); KeyValuePair <uint, LiveEdge>[] arcs = graph.GetArcs(vertex1); Assert.AreEqual(10000 - count + 1, arcs.Length); graph.AddArc(vertex2, vertex1, new LiveEdge() { Tags = 0, Forward = false }, null); arcs = graph.GetArcs(vertex2); Assert.AreEqual(1, arcs.Length); Assert.AreEqual(0, arcs[0].Value.Tags); Assert.AreEqual(vertex1, arcs[0].Key); count--; } }
public void TestLiveEdgeDynamicGraphEdge() { IDynamicGraph <LiveEdge> graph = this.CreateGraph(); uint vertex1 = graph.AddVertex(51, 1); uint vertex2 = graph.AddVertex(51, 2); graph.AddArc(vertex1, vertex2, new LiveEdge() { Forward = true, Tags = 0 }, null); KeyValuePair <uint, LiveEdge>[] arcs = graph.GetArcs(vertex1); Assert.AreEqual(1, arcs.Length); Assert.AreEqual(0, arcs[0].Value.Tags); Assert.AreEqual(vertex2, arcs[0].Key); graph.AddArc(vertex2, vertex1, new LiveEdge() { Forward = true, Tags = 0 }, null); arcs = graph.GetArcs(vertex2); Assert.AreEqual(1, arcs.Length); Assert.AreEqual(0, arcs[0].Value.Tags); Assert.AreEqual(vertex1, arcs[0].Key); }
/// <summary> /// Adds a new vertex to this graph. /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="neighboursEstimate"></param> /// <returns></returns> public uint AddVertex(float latitude, float longitude, byte neighboursEstimate) { uint vertex = _graph.AddVertex(latitude, longitude, neighboursEstimate); _vertexIndex.Add(new GeoCoordinate(latitude, longitude), vertex); return(vertex); }
private List<long> runFile(string file, IDynamicGraph alg, int resolution, int repeatCount) { InputFile graph = readFile(file); Stopwatch sw = new Stopwatch(); List<List<long>> times = new List<List<long>>(); List<List<long>> timesVector = new List<List<long>>(); for (int i = 0; i < repeatCount; i++) { alg.ResetAll(graph.n); int skip = 0; times.Add(new List<long>()); for (int n = 0; n < graph.n; n++) alg.AddVertex(); do { sw.Start(); foreach(var edge in graph.edges.Skip(skip).Take(resolution)) { alg.AddEdge(edge.from, edge.to); } sw.Stop(); times[i].Add(sw.ElapsedTicks); sw.Reset(); skip += resolution; } while (skip < graph.edges.Count); } var ret = Transpose(times).ConvertAll(item => ((long)item.Average())); return ret; }
private MinAvgMax RunFolderDynamicGraph(string folder, IDynamicGraph alg) { var values = new List<long>(); var sw = new Stopwatch(); foreach (var file in Directory.EnumerateFiles(folder)) { var graph = readFile(file); alg.ResetAll(graph.n, graph.m); for(int i = 0; i < graph.n; i++) alg.AddVertex(); sw.Reset(); //force gc GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); sw.Start(); foreach (var edge in graph.edges) { alg.AddEdge(edge.from, edge.to); } var top = alg.Topology(); sw.Stop(); values.Add(sw.ElapsedTicks); } return new MinAvgMax(values.Min(), (long)values.Average(), values.Max()); }
/// <summary> /// Adds a node that is at least part of one road. /// </summary> /// <param name="nodeId"></param> /// <returns></returns> private uint?AddRoadNode(long nodeId) { uint id; // try and get existing node. if (!_idTransformations.TryGetValue(nodeId, out id)) { // get coordinates. float[] coordinates; if (_coordinates.TryGetValue(nodeId, out coordinates)) { // the coordinate is present. id = _dynamicGraph.AddVertex( coordinates[0], coordinates[1]); _coordinates.Remove(nodeId); // free the memory again! if (_usedTwiceOrMore.Contains(nodeId)) { _idTransformations[nodeId] = id; } return(id); } return(null); } return(id); }
/// <summary> /// Adds a new vertex. /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public uint AddVertex(float latitude, float longitude) { uint vertex = _graph.AddVertex(latitude, longitude); if (_vertexIndex != null) { _vertexIndex.Add(new GeoCoordinate(latitude, longitude), vertex); } return(vertex); }
public void TestLiveEdgeDynamicGraphVertex() { IDynamicGraph <LiveEdge> graph = this.CreateGraph(); uint vertex = graph.AddVertex(51, 4); float latitude, longitude; graph.GetVertex(vertex, out latitude, out longitude); Assert.AreEqual(51, latitude); Assert.AreEqual(4, longitude); KeyValuePair <uint, LiveEdge>[] arcs = graph.GetArcs(vertex); Assert.AreEqual(0, arcs.Length); }
public void TestLiveEdgeDynamicGraphVertex10000() { IDynamicGraph <LiveEdge> graph = this.CreateGraph(); int count = 10000; while (count > 0) { uint vertex = graph.AddVertex(51, 4); float latitude, longitude; graph.GetVertex(vertex, out latitude, out longitude); Assert.AreEqual(51, latitude); Assert.AreEqual(4, longitude); KeyValuePair <uint, LiveEdge>[] arcs = graph.GetArcs(vertex); Assert.AreEqual(0, arcs.Length); count--; } Assert.AreEqual((uint)10000, graph.VertexCount); }