Ejemplo n.º 1
0
        public static void InitGraph(Item root, List<Item> items)
        {
            path = root;
            tree = path.ToNode();
            Controller.items = items;

            SetGraph(tree);
            FindPath(tree, new List<string>(), 0f);

            FileReader.StreamOut(outputFileName);
        }
Ejemplo n.º 2
0
 private static void SetGraph(Node node)
 {
     foreach (var i in items)
     {
         if (node.name.Equals(i.start))
         {
             var temp = new Node(i.end, i.weight);
             SetGraph(temp);
             node.AddChild(temp);
         }
     }
 }
Ejemplo n.º 3
0
        private static void FindPath(Node node, List<string> route, float weight)
        {
            route.Add(node.name);
            var length = weight + node.weight;

            if (node.children.Count == 0 || node.name == path.end)
            {   
                if (route.Contains(path.start) && route.Contains(path.end))
                    allPaths.Add(route, length);
                
                return;
            }
                
            foreach (var i in node.children)
            {
                var list = route.ToList();
                FindPath(i, list, length);
            }
        }
Ejemplo n.º 4
0
 public void AddChild(Node child)
 {
     children.Add(child);
 }