Example #1
0
        /// <summary>
        /// Build the generalized MDD
        /// </summary>
        /// <returns></returns>
        private bool buildGeneralMDD()
        {
            MddMatchAndPruneState current     = openList.Dequeue();
            successorIterator     allChildren = new successorIterator(allMDDs.Length);
            int currentLevel = current.stateLevel;

            while (current.stateLevel + 1 != this.solutionDepth) // while not goal
            {
                Expand(current, allChildren);
                if (openList.Count == 0)
                {
                    return(false);
                }
                current = openList.Dequeue();
                if (current.stateLevel != currentLevel)
                {
                    closedList.Clear();
                    currentLevel++;
                }
                if (runner.ElapsedMilliseconds() > Constants.MAX_TIME)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// expands a given node
        /// </summary>
        /// <param name="toExpand"></param>
        private void Expand(MddMatchAndPruneState toExpand, successorIterator allChildren)
        {
            allChildren.initialize(toExpand);
            MddMatchAndPruneState successor;

            while (allChildren.hasNext)
            {
                successor = allChildren.getNext();
                if (closedList.ContainsKey(successor))
                {
                    ((MddMatchAndPruneState)closedList[successor]).addParent(toExpand);
                }
                else
                {
                    CostTreeNodeSolver.matchCounter++;
                    successor.addParent(toExpand);
                    closedList.Add(successor, successor);
                    openList.Enqueue(successor);
                    if (successor.stateLevel + 1 == this.solutionDepth)
                    {
                        goal = successor;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Return the next generated child.
        /// </summary>
        /// <returns></returns>
        public MddMatchAndPruneState getNext()
        {
            //first return than iterate
            MddMatchAndPruneState ans = new MddMatchAndPruneState(nodesFromChildrenList);

            if (nextChild(0) == false)
            {
                hasNext = false;
            }
            return(ans);
        }
Example #4
0
 private void reverseExpand(MddMatchAndPruneState toExpand)
 {
     foreach (MddMatchAndPruneState parent in toExpand.parents)
     {
         for (int i = 0; i < toExpand.allPositions.Length; i++)
         {
             CostTreeSearchSolver.edgesMatrix[i, parent.allPositions[i].getVertexIndex(), parent.allPositions[i].getDirection(toExpand.allPositions[i])] = CostTreeSearchSolver.edgesMatrixCounter + 1;
         }
         if (closedList.ContainsKey(parent) == false)
         {
             openList.Enqueue(parent);
             closedList.Add(parent, parent);
         }
     }
 }
Example #5
0
 public void initialize(MddMatchAndPruneState prevStep)
 {
     this.hasNext  = true;
     this.prevStep = prevStep;
     for (int i = 0; i < nodesFromChildrenList.Length; i++)
     {
         nodesFromChildrenList[i] = prevStep.allPositions[i].children.First; //if crashes check there if there can be a node with no children
         if (nodesFromChildrenList[i] == null)
         {
             this.hasNext = false;
         }
     }
     while (hasNext == true && isLegal(0) == false)
     {
         getNext();
     }
 }
Example #6
0
        /// <summary>
        /// prunes the given MDDs according to each other
        /// </summary>
        public bool pruneMDDs()
        {
            if (legal == false || buildGeneralMDD() == false)
            {
                return(false);
            }

            //Run.resultsWriterdd.Write(CostTreeNodeSolver.matchCounter + ",");
            //Run.resultsWriterdd.WriteLine();
            //Run.resultsWriterdd.Flush();
            //Run.resultsWriterdd.Close();

            if (openList.Count != 0)
            {
                Console.ReadLine(); //should be empty
            }
            MddMatchAndPruneState current = goal;
            int currentLevel = goal.stateLevel;

            closedList.Clear();

            while (current.stateLevel > 0)  //while not root
            {
                if (runner.ElapsedMilliseconds() > Constants.MAX_TIME)
                {
                    return(false);
                }

                if (current.stateLevel < currentLevel)
                {
                    pruneLevel(currentLevel);
                    currentLevel--;
                    CostTreeSearchSolver.edgesMatrixCounter++;
                    closedList.Clear();
                }
                reverseExpand(current);
                current = openList.Dequeue();
            }
            pruneLevel(currentLevel);  //prune level 1
            return(true);
        }
Example #7
0
        public void initialize(MDD[] allMDDs)
        {
            this.allMDDs = allMDDs;
            this.openList.Clear();
            this.closedList.Clear();
            MDDNode[] rootPositions = new MDDNode[allMDDs.Length];
            for (int i = 0; i < allMDDs.Length; i++)
            {
                if (allMDDs[i].levels == null)
                {
                    legal = false;
                    return;
                }
                rootPositions[i]   = allMDDs[i].levels[0].First.Value;
                this.conflicted[i] = false;
            }
            MddMatchAndPruneState root = new MddMatchAndPruneState(rootPositions);

            this.solutionDepth = root.allPositions[0].father.levels.Length;
            openList.Enqueue(root);
            legal = true;
        }
Example #8
0
        public override bool Equals(object obj)
        {
            MddMatchAndPruneState comp = (MddMatchAndPruneState)obj;

            return(this.allPositions.SequenceEqual <MDDNode>(comp.allPositions));
        }
Example #9
0
 public void addParent(MddMatchAndPruneState parent)
 {
     this.parents.AddLast(parent);
     parent.childrens.AddLast(this);
 }