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); }
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); }
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); }
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); } }
public Node AddChild(Tree.Node parent) { return(AddChild(parent, Node.New)); }
//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); }
public Node AddChild(NODE parentval, NODE childval) { Tree.Node parent = (parentval != null) ? nodeval_node[parentval] : null; return(AddChild(parent, childval)); }
public Node(Tree.Node parent, NODE value) : base(parent) { this.value = value; }
public static Node New(Tree.Node parent, NODE value) { return(new Node(parent, value)); }