public IHttpActionResult CreateGraph() { Graph graph = _graphService.NewGraph(true); Node nodeA = _graphService.AddNode(ref graph, "nodeA"); Node nodeB = _graphService.AddNode(ref graph, "nodeB"); Node nodeC = _graphService.AddNode(ref graph, "nodeC"); _graphService.AddEdge(nodeA, nodeB, ref graph); _graphService.AddEdge(nodeB, nodeC, ref graph); _graphService.AddEdge(nodeC, nodeA, ref graph, 10.0D); // _graphService.AddEdge(nodeC, nodeA, ref graph, 7.0D); _graphService.SaveGraph(graph); return(Ok(graph)); }
public void AddEdgeTest() { var graph = _graphService.NewGraph(true); var nodeA = _graphService.AddNode(ref graph, "nodeA"); var nodeB = _graphService.AddNode(ref graph, "nodeB"); var nodeC = _graphService.AddNode(ref graph, "nodeC"); _graphService.AddEdge(nodeA, nodeB, ref graph, 10.0D); GraphPart graphPart = graph.GraphPart.ToList().Find(part => part.Node.Uid == nodeA.Uid); Assert.That(graphPart.IsNotNull); Edge edgeFromAToB = graphPart.Edge.ToList().Find(edge => edge.Destination.Uid == nodeB.Uid); Assert.NotNull(edgeFromAToB); Assert.That(edgeFromAToB.Weight.IsNotNull); Assert.That(edgeFromAToB.Uid.IsNotNull); Assert.That(edgeFromAToB.Weight == 10.0D); // Assert.NotNull(edgeFromAToB.GraphPart); - nie można sprawdzić bo ustawia to pole entity framework _graphService.AddEdge(nodeA, nodeB, ref graph, 5.0D); GraphPart graphPart1 = graph.GraphPart.ToList().Find(part => part.Node.Uid == nodeA.Uid); Assert.That(graphPart1.IsNotNull); Assert.That(graphPart.Edge.Count == 1); Edge edgeFromAToBMod = graphPart.Edge.ToList().Find(edge => edge.Destination.Uid == nodeB.Uid); Assert.NotNull(edgeFromAToBMod); Assert.That(edgeFromAToBMod.Weight == 5.0D); Assert.That(edgeFromAToB.Uid == edgeFromAToBMod.Uid); }
public void AddEdgeIntegrationTest() { Assert.Inconclusive("TODO."); IGraphService target = CreateIGraphService(); // TODO: Initialize to an appropriate value EdgeSpecification definition = null; // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.AddEdge(definition); Assert.AreEqual(expected, actual); }
public void TestBFSToAll() { var graph = _graphService.NewGraph(true); var nodeA = _graphService.AddNode(ref graph, "nodeA"); var nodeB = _graphService.AddNode(ref graph, "nodeB"); var nodeC = _graphService.AddNode(ref graph, "nodeC"); _graphService.AddEdge(nodeA, nodeB, ref graph, 10.0D); _graphService.AddEdge(nodeB, nodeA, ref graph, 12.0D); _graphService.AddEdge(nodeC, nodeA, ref graph, 5.0D); Dictionary <string, HashSet <string> > adjList = GraphAsAdjacencyList(graph); foreach (KeyValuePair <string, HashSet <string> > kpv in adjList) { Console.WriteLine(kpv.Key + ": "); foreach (var s in kpv.Value) { Console.Write(s + ", "); } Console.WriteLine(); } var result = ShortestPathToAll(graph, nodeA); Console.WriteLine("Od {0}", nodeA.Label); foreach (KeyValuePair <Node, int> kpv in result) { Console.WriteLine("do {0} - długość {1}", kpv.Key.Label, kpv.Value); } }