예제 #1
0
        // Constructor for creating a new representative table. We directly fill the table depending on the given sequence.
        public RepresentativeTable(Graph graph, Tree tree)
        {
            // Initialize the table
            Table = new Dictionary<BitSet, RepresentativeList>();

            Queue<BitSet> queue = new Queue<BitSet>();
            queue.Enqueue(tree.Root);
            Table[new BitSet(0, graph.Size)] = new RepresentativeList();

            int i = 0;

            while (queue.Count != 0)
            {
                BitSet node = queue.Dequeue();

                FillTable(graph, node);
                FillTable(graph, graph.Vertices - node);

                if (tree.LeftChild.ContainsKey(node))
                {
                    queue.Enqueue(tree.LeftChild[node]);
                }
                if (tree.RightChild.ContainsKey(node))
                {
                    queue.Enqueue(tree.RightChild[node]);
                }
            }
        }
예제 #2
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);
        }
예제 #3
0
 /*************************/
 // Constructor
 /*************************/
 public Decomposition(Graph graph, Tree tree)
 {
     Tree = tree;
     Graph = graph;
 }
예제 #4
0
        // 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;
        }
예제 #5
0
 /*************************/
 // Constructor
 /*************************/
 // Basic constructor
 public GenericSolver(Decomposition decomposition)
 {
     // The graph and binary decomposition tree that we are working on
     Graph = decomposition.Graph;
     Tree = decomposition.Tree;
 }