예제 #1
0
        public List <Node> FindPathMST(Node from, IEnumerable <Node> tos, Func <List <Node>, List <Node>, int> selector)
        {
            HashSet <Node> toset = new HashSet <Node>(tos);

            toset.Remove(null);
            bool[]      visited = new bool[nodes.Count];
            List <Node> found   = null;
            List <Node> probing = new List <Node>();

            Tree <Node> tree = BuildTreeMST(from, null);

            foreach (Node to in toset)
            {
                Tree.Node        treeto   = tree.FindNode(to);
                List <Tree.Node> treepath = tree.NodesFromRootTo(treeto);
                List <Node>      path     = tree.GetValue(treepath);
                if (path.Count == 0)
                {
                    continue;
                }
                HDebug.Assert(path.First() == from, path.Last() == to);
                if (found == null || selector(found, path) == 1)
                {
                    found = path;
                }
            }

            return(found);
        }
예제 #2
0
        public Node AddChild(Tree.Node parent, Func <Node, Node> nodebuilder)
        {
            Node child = nodebuilder(parent);

            if (parent == null)
            {
                root = child;
                return(root);
            }
            parent.children.Add(child);
            return(child);
        }
예제 #3
0
파일: TreeT.cs 프로젝트: htna/explsolv
        public Node AddChild(Tree.Node parent, NODE childval)
        {
            if (nodeval_node.ContainsKey(childval))
            {
                HDebug.Assert(false);
                return(null);
            }
            Func <Tree.Node, Tree.Node> nodebuilder = delegate(Tree.Node lparent)
            {
                return(Node.New(lparent, childval));
            };
            Node child = (Node)(AddChild(parent, nodebuilder));

            nodeval_node.Add(childval, child);
            return(child);
        }
예제 #4
0
        void BuildTreeRec(Tuple <Node, Edge> parent, Tuple <Node, Edge> node, HashSet <Node> within, Tree <Tuple <Node, Edge> > tree)
        {
            if (parent != null)
            {
                HDebug.Assert(within.Contains(parent.Item1) == false);
            }
            HDebug.Assert(within.Contains(node.Item1));

            Tree.Node treenode = tree.AddChild(parent, node);
            within.Remove(node.Item1);
            foreach (Node childnode in node.Item1.nexts.Keys)
            {
                if (within.Contains(childnode) == false)
                {
                    continue;
                }
                Edge childedge           = node.Item1.nexts[childnode];
                Tuple <Node, Edge> child = new Tuple <Node, Edge>(childnode, childedge);
                BuildTreeRec(node, child, within, tree);
            }
        }
예제 #5
0
 public Node AddChild(Tree.Node parent)
 {
     return(AddChild(parent, Node.New));
 }
예제 #6
0
파일: TreeT.cs 프로젝트: htna/explsolv
 //public EDGE FindEdge(NODE nodeval1, NODE nodeval2, EDGE nullvalue=default(EDGE))
 //{
 //    if(nodeval_node.ContainsKey(nodeval1) == false) return nullvalue;
 //    if(nodeval_node.ContainsKey(nodeval2) == false) return nullvalue;
 //    Node node1 = nodeval_node[nodeval1];
 //    Node node2 = nodeval_node[nodeval2];
 //    Edge edge = (Edge)FindEdge(node1, node2);
 //    if(edge == null)
 //        return nullvalue;
 //    return edge.value;
 //}
 public NODE GetValue(Tree.Node node)
 {
     return(((Tree <NODE> .Node)node).value);
 }
예제 #7
0
파일: TreeT.cs 프로젝트: htna/explsolv
 public Node AddChild(NODE parentval, NODE childval)
 {
     Tree.Node parent = (parentval != null) ? nodeval_node[parentval] : null;
     return(AddChild(parent, childval));
 }
예제 #8
0
파일: TreeT.cs 프로젝트: htna/explsolv
 public Node(Tree.Node parent, NODE value)
     : base(parent)
 {
     this.value = value;
 }
예제 #9
0
파일: TreeT.cs 프로젝트: htna/explsolv
 public static Node New(Tree.Node parent, NODE value)
 {
     return(new Node(parent, value));
 }