public void AddChild(PNode child) { lock (_children) { _children.Add(child); } }
private static void GetParticipants(PNode pnode, IDictionary<string, ISet<SemanticVersion>> participants) { foreach (PVNode child in pnode.Children) { GetParticipants(child, pnode.Id, participants); } }
private static IDictionary<string, ISet<SemanticVersion>> GetParticipants(PNode pnode) { IDictionary<string, ISet<SemanticVersion>> participants = new Dictionary<string, ISet<SemanticVersion>>(); foreach (PVNode child in pnode.Children) { GetParticipants(child, participants); } return participants; }
public static IDictionary<string, SemanticVersion> FindFirst(PNode pnode, List<Tuple<string, SemanticVersion>>[] lineup) { IDictionary<string, SemanticVersion> solution = null; Permutations.Run(lineup, (candidate) => { IDictionary<string, SemanticVersion> result = new Dictionary<string, SemanticVersion>(); if (MetadataTree.Satisfy(pnode, candidate, result)) { solution = result; return true; } return false; }); return solution; }
public static void Simulate(PNode pnode, List<Tuple<string, SemanticVersion>>[] lineup, bool verbose) { int good = 0; int bad = 0; DateTime before = DateTime.Now; Permutations.Run(lineup, (candidate) => { IDictionary<string, SemanticVersion> result = new Dictionary<string, SemanticVersion>(); if (MetadataTree.Satisfy(pnode, candidate, result)) { if (verbose) { Console.Write("GOOD: "); Print(candidate); Console.WriteLine(); Console.Write("solution: "); Print(result); } good++; } else { if (verbose) { Console.Write("BAD: "); Print(candidate); Console.WriteLine(); } bad++; } return false; }); DateTime after = DateTime.Now; Console.WriteLine("duration: {0} seconds", (after - before).TotalSeconds); Console.WriteLine("good: {0} bad: {1}", good, bad); }
private static void GetParticipants(PNode pnode, HashSet<string> participants) { participants.Add(pnode.Id); foreach (PVNode child in pnode.Children) { GetParticipants(child, participants); } }
public static List<PNode> FindIndependentTrees(PNode original) { List<Subtree> subtrees = new List<Subtree>(); PVNode parent = original.Children.First(); foreach (PNode pnode in parent.Children) { //Console.Write("{0}: ", pnode.Id); HashSet<string> participants = new HashSet<string>(); participants.Add(pnode.Id); GetParticipants(pnode, participants); bool newSubtreeNeeded = true; foreach (Subtree subtree in subtrees) { if (subtree.HasOverlap(participants)) { subtree.Roots.Add(pnode); newSubtreeNeeded = false; break; } } if (newSubtreeNeeded) { Subtree newSubtree = new Subtree(); newSubtree.Roots.Add(pnode); foreach (string s in participants) { newSubtree.Participants.Add(s); } subtrees.Add(newSubtree); } //foreach (string participant in participants) //{ // Console.Write("{0} ", participant); //} //Console.WriteLine(); } List<PNode> result = new List<PNode>(); foreach (Subtree subtree in subtrees) { PNode newRoot = new PNode("$"); PVNode newRootVersion = new PVNode(new SemanticVersion(0)); newRoot.Children.Add(newRootVersion); foreach (PNode newRootChild in subtree.Roots) { newRootVersion.AddChild(newRootChild); } result.Add(newRoot); } return result; }
public static List<Tuple<string, SemanticVersion>>[] Collect(PNode pnode) { return SortParticipants(GetParticipants(pnode)); }
public static List<Package>[] Collect(PNode pnode) { return SortParticipants(GetParticipants(pnode)); }
public static IList<Package> FindFirst(PNode pnode, List<Package>[] lineup) { IList<Package> solution = null; Permutations.Run(lineup, (candidate) => { IList<Package> result = new List<Package>(); if (MetadataTree.Satisfy(pnode, candidate, result)) { solution = result; return true; } return false; }); return solution; }