private void Print(Vertex[] parents, Vertex parent) { if (RootVertexID != -1) { parents[RootVertexID] = parent; parent = G.Vertices[RootVertexID]; } /*if(Child != null) * { * Child.Print(parents, parent); * }*/ if (Left != null) { Left.Print(parents, parent); } if (Right != null) { Right.Print(parents, parent); } }
public bool TrySolve() { PriorityQueue <PartialSolution> q = new PriorityQueue <PartialSolution>(); HashSet <PartialSolution> processed = new HashSet <PartialSolution>(); foreach (Vertex v in Vertices) { PartialSolution ps = new PartialSolution(this); ps = ps.AddVertex(v); if (ps == null) { continue; } q.Enqueue(ps, ps.DepthBelow); } while (q.Count > 0)// && sw.ElapsedMilliseconds < 1000 * 60 * 3) { PartialSolution ps = q.Dequeue(); if (processed.Contains(ps)) { continue; } int count = ps.Vertices.Count() + ps.Separator.Count(); if (count == Vertices.Length) { //Console.WriteLine("Solution: " + ps.LowerBound); //Console.WriteLine(); PartialSolution result = ps; foreach (Vertex v in ps.Separator) { result = result.AddVertex(v); throw new Exception("Unexpected condition"); } result.Print(); return(true); } foreach (Vertex v in ps.Separator) { PartialSolution newPS = ps.AddVertex(v); if (newPS == null) { continue; } q.Enqueue(newPS, newPS.DepthBelow); int scount = newPS.Separator.Count(); PartialSolution key = new PartialSolution(this); key.VertexSubset = newPS.SeparatorSubset; } List <PartialSolution> toAdd = new List <PartialSolution>(); foreach (PartialSolution mergeCandidate in processed) { PartialSolution newPS = ps.Join(mergeCandidate); if (newPS == null) { continue; } toAdd.Add(newPS); } foreach (PartialSolution newPS in toAdd) { q.Enqueue(newPS, newPS.DepthBelow); int scount = newPS.Separator.Count(); PartialSolution key = new PartialSolution(this); key.VertexSubset = newPS.SeparatorSubset; } processed.Add(ps); } /*if(sw.ElapsedMilliseconds >= 1000 * 60 * 3) * { * Console.WriteLine("Time out at: " + UB); * * return true; * }*/ return(false); }