Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public void AddNodeTest()
        {
            var graph = _graphService.NewGraph(true);
            var nodeA = _graphService.AddNode(ref graph, "nodeA");
            var nodeB = _graphService.AddNode(ref graph, "nodeB");

            Assert.That(graph.GraphPart.Count == 2);
            foreach (GraphPart graphPart in graph.GraphPart)
            {
                Assert.That(graphPart.Node.Equals(nodeA) || graphPart.Node.Equals(nodeB));
                Assert.NotNull(graphPart.Edge);
                Assert.NotNull(graphPart.Uid);
            }
        }