Beispiel #1
0
        // Parses a decomposition given the filename of the decomposition and the graph files.
        public static Decomposition ParseDecomposition(string decompositionFilename, string graphFilename)
        {
            Graph graph = ParseGraph(graphFilename);
            StreamReader sr = new StreamReader(decompositionFilename);
            string line;
            Tree tree = new Tree();

            // Each line is simply an integer, which is the sequence of the linear decomposition
            while ((line = sr.ReadLine()) != null)
            {
                // Skip comments
                if (line.StartsWith("c ")) continue;

                string[] s = line.Trim().Split(' ');
                BitSet node = new BitSet(0, graph.Size);
                foreach (string vertex in s)
                    node.Add(int.Parse(vertex) - 1); // -1 because internally we work with [0,...,n)
                tree.Insert(node);
            }

            return new Decomposition(graph, tree);
        }
        // Retreives the actual ordering of a certain ordering that will not validate our bound
        private static Tree RetrieveTree(Graph graph)
        {
            Tree tree = new Tree();

            Queue<BitSet> queue = new Queue<BitSet>();
            queue.Enqueue(graph.Vertices);

            while (queue.Count != 0)
            {
                BitSet A = queue.Dequeue();
                tree.Insert(A);

                if (OptimalChild[A].IsEmpty) continue;

                queue.Enqueue(OptimalChild[A]);
                queue.Enqueue(A - OptimalChild[A]);
            }

            return tree;
        }