Ejemplo n.º 1
0
        /// Returns whether another conflict was found
        public bool ChooseNextConflict()
        {
            bool hasNext = this.nextConflicts.MoveNext();

            if (hasNext)
            {
                this.conflict = this.nextConflicts.Current;
            }
            return(hasNext);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Chooses an internal conflict to work on.
 /// Resets conflicts iteration if it's used.
 /// </summary>
 public void ChooseConflict()
 {
     if (this.nodeConflicts.Count != 0)
     {
         this.conflict = this.nodeConflicts[0];
     }
     else
     {
         this.conflict = null;
     }
 }
Ejemplo n.º 3
0
        }                                                                                // Nonsense values until Init, just allocate move

        public CFMCbsConstraint(CFMCbsConflict conflict, ProblemInstance instance, bool agentA)
        {
            Move move;
            int  agentNum;
            int  minTime;

            if (agentA)
            {
                minTime = conflict.timeStepAgentA;
            }
            else
            {
                minTime = conflict.timeStepAgentB;
            }

            if (agentA)
            {
                move      = conflict.agentAmove;
                agentNum  = instance.m_vAgents[conflict.agentAIndex].agentIndex;
                this.move = new TimedMove(move, minTime);
            }
            else
            {
                move      = conflict.agentBmove;
                agentNum  = instance.m_vAgents[conflict.agentBIndex].agentIndex;
                this.move = new TimedMove(move, minTime);
            }

            this.agentNum = (byte)agentNum;


            if (conflict.vertex)
            {
                this.move.direction = Move.Direction.NO_DIRECTION;
            }
        }
Ejemplo n.º 4
0
 protected virtual void addToGlobalConflictCount(CFMCbsConflict conflict)
 {
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Create Constraints from conflict
        /// </summary>
        /// <param name="node"></param>
        /// <param name="doLeftChild"></param>
        /// <param name="closedListHitChildCost"></param>
        /// <returns></returns>
        protected CFMCbsNode ConstraintExpand(CFMCbsNode node, bool doLeftChild, out int closedListHitChildCost)
        {
            CFMCbsConflict conflict = node.GetConflict();
            int            conflictingAgentIndex = doLeftChild? conflict.agentAIndex : conflict.agentBIndex;

            CFMCbsNode.ExpansionState expansionsState           = doLeftChild ? node.agentAExpansion : node.agentBExpansion;
            CFMCbsNode.ExpansionState otherChildExpansionsState = doLeftChild ? node.agentBExpansion : node.agentAExpansion;
            string agentSide = doLeftChild? "left" : "right";
            int    groupSize = node.GetGroupSize(conflictingAgentIndex);

            closedListHitChildCost = -1;

            if (expansionsState != CFMCbsNode.ExpansionState.EXPANDED)
            // Agent expansion already skipped in the past or not forcing it from its goal - finally generate the child:
            {
                if (debug)
                {
                    Debug.WriteLine("Generating " + agentSide + " child");
                }

                if (doLeftChild)
                {
                    node.agentAExpansion = CFMCbsNode.ExpansionState.EXPANDED;
                }
                else
                {
                    node.agentBExpansion = CFMCbsNode.ExpansionState.EXPANDED;
                }

                var        newConstraint = new CFMCbsConstraint(conflict, instance, doLeftChild);
                CFMCbsNode child         = new CFMCbsNode(node, newConstraint, conflictingAgentIndex);

                if (closedList.ContainsKey(child) == false)
                {
                    bool success = child.Solve();

                    if (success == false)
                    {
                        return(null); // A timeout probably occured
                    }
                    return(child);
                }
                else
                {
                    this.closedListHits++;
                    closedListHitChildCost = this.closedList[child].totalCost;
                    if (debug)
                    {
                        Debug.WriteLine("Child already in closed list!");
                    }
                }
            }
            else
            {
                if (debug)
                {
                    Debug.WriteLine("Child already generated before");
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="children"></param>
        /// <param name="adoptBy">If not given, adoption is done by expanded node</param>
        /// <returns>true if adopted - need to rerun this method, ignoring the returned children from this call, bacause adoption was performed</returns>
        protected bool ExpandImpl(CFMCbsNode node, out IList <CFMCbsNode> children, out bool reinsertParent)
        {
            CFMCbsConflict conflict = node.GetConflict();

            children = new List <CFMCbsNode>();

            CFMCbsNode child;

            reinsertParent = false;
            int  closedListHitChildCost;
            bool leftSameCost  = false; // To quiet the compiler
            bool rightSameCost = false;


            // Generate left child:
            child = ConstraintExpand(node, true, out closedListHitChildCost);
            if (child != null)
            {
                if (child == node) // Expansion deferred
                {
                    reinsertParent = true;
                }
                else // New child
                {
                    children.Add(child);
                    leftSameCost = child.totalCost == node.totalCost;
                }
            }
            else  // A timeout occured, or the child was already in the closed list.
            {
                if (closedListHitChildCost != -1)
                {
                    leftSameCost = closedListHitChildCost == node.totalCost;
                }
            }

            if (runner.ElapsedMilliseconds() > Constants.MAX_TIME)
            {
                return(false);
            }

            // Generate right child:
            child = ConstraintExpand(node, false, out closedListHitChildCost);
            if (child != null)
            {
                if (child == node) // Expansion deferred
                {
                    reinsertParent = true;
                }
                else // New child
                {
                    children.Add(child);
                    rightSameCost = child.totalCost == node.totalCost;
                }
            }
            else  // A timeout occured, or the child was already in the closed list.
            {
                if (closedListHitChildCost != -1)
                {
                    rightSameCost = closedListHitChildCost == node.totalCost;
                }
            }


            return(false);
        }