Ejemplo n.º 1
0
        public static LinearDecomposition ConvertDecomposition(Decomposition decomposition)
        {
            BinTree tree = (BinTree)decomposition.Tree;
            tree.Tilt();
            BooleanChain chain = BooleanChain.DepthFirstSearch(tree.Left.Item, decomposition.MaxNeighborhoodSize, int.MaxValue, BooleanChain.FromGraph(decomposition.Graph, tree.Left.Item).ToArray());

            BinTree node = tree;
            while (node.Right != null)
            {
                node = node.Right;
                if (node.Left == null)
                {
                    chain = new BooleanChain(chain, node.Item.First());
                }
                else if (node.Left.Item.Count == 1)
                {
                    chain = new BooleanChain(chain, node.Left.Item.First());
                }
                else
                {
                    chain = BooleanChain.DepthFirstSearch(node.Left.Item, decomposition.MaxNeighborhoodSize, int.MaxValue, chain);
                }
            }
            return (LinearDecomposition)chain;
        }
Ejemplo n.º 2
0
 public BooleanChain(BooleanChain chain, int vertex)
 {
     this.Previous = chain;
     this.Graph = chain.Graph;
     this.Vertex = vertex;
     this.CalculateBooleanWidth();
 }
Ejemplo n.º 3
0
        public static BooleanChain BestFirstSearch(BitSet items, long max, params BooleanChain[] chains)
        {
            PriorityQueue<double, BooleanChain> queue = new PriorityQueue<double, BooleanChain>(Comparer<double>.Default);
            foreach (BooleanChain item in chains)
            {
                if (item.MaxNeighborhoodSize <= max)
                {
                    queue.Enqueue(item.BooleanWidth * (item.Right * items).Count, item);
                }
            }

            BooleanChain chain;
            while (queue.TryDequeue(out chain))
            {
                BitSet bitSet = chain.Right * items;

                bool empty = true;
                foreach (int item in bitSet)
                {
                    empty = false;
                    BooleanChain next = new BooleanChain(chain, item);
                    if (next.MaxNeighborhoodSize <= max)
                    {
                        queue.Enqueue(next.BooleanWidth * (next.Right * items).Count, next);
                    }
                }

                if (empty)
                {
                    return chain;
                }
            }

            return null;
        }