/// <summary> /// Used when WorldState objects are put in the open list priority queue /// </summary> /// <param name="other"></param> /// <returns></returns> public virtual int CompareTo(IBinaryHeapItem other) { WorldState that = (WorldState)other; /* * if (conflictRange == -1) * return CompareToPRobust(that); */ int thisF = this.h + this.g; int thatF = that.h + that.g; if (thisF < thatF) { return(-1); } if (thisF > thatF) { return(1); } // Tie breaking: bool thisIsGoal = this.GoalTest(); bool thatIsGoal = that.GoalTest(); if (thisIsGoal == true && thatIsGoal == false) // The elaborate form is necessary to keep the comparison consistent. Otherwise goalA<goalB and goalB<goalA { return(-1); } if (thatIsGoal == true && thisIsGoal == false) { return(1); } // Independence Detection framework conflicts: if (this.potentialConflictsCount < that.potentialConflictsCount) { return(-1); } if (this.potentialConflictsCount > that.potentialConflictsCount) { return(1); } // CBS framework conflicts: // It makes sense to prefer nodes that conflict less, and not just nodes that don't conflict at all, // because a 3-way conflict takes more work to resolve than if (this.cbsInternalConflictsCount < that.cbsInternalConflictsCount) { return(-1); } if (this.cbsInternalConflictsCount > that.cbsInternalConflictsCount) { return(1); } // //M-Star: prefer nodes with smaller collision sets: //if (this.collisionSets != null) // than M-Star is running //{ // // The collision sets change during collision set backpropagation and closed list hits. // // Backpropagation goes from a node's child to the node, so it's tempting to think // // it only happens when the node is already expanded and out of the open list, // // but partial expansion makes that false. // // Closed list hits can also happen while the node is waiting to be expanded. // // So the max rank can change while the node is in the open list - // // it can't be used for tie breaking :(. // if (this.collisionSets.maxRank < that.collisionSets.maxRank) // return -1; // if (that.collisionSets.maxRank > this.collisionSets.maxRank) // return 1; //} // f, collision sets, conflicts and internal conflicts being equal, prefer nodes with a larger g // - they're closer to the goal so less nodes would probably be generated by them on the way to it. if (this.g < that.g) { return(1); } if (this.g > that.g) { return(-1); } return(0); }
/// <summary> /// Used when WorldState objects are put in the open list priority queue /// </summary> /// <param name="other"></param> /// <returns></returns> public virtual int CompareTo(IBinaryHeapItem other) { WorldState that = (WorldState)other; int thisF = this.h + this.g; int thatF = that.h + that.g; if (thisF < thatF) { return(-1); } if (thisF > thatF) { return(1); } // Tie breaking: bool thisIsGoal = this.GoalTest(); bool thatIsGoal = that.GoalTest(); if (thisIsGoal == true && thatIsGoal == false) // The elaborate form is necessary to keep the comparison consistent. Otherwise goalA<goalB and goalB<goalA { return(-1); } if (thatIsGoal == true && thisIsGoal == false) { return(1); } // Independence Detection framework conflicts: if (this.potentialConflictsCount < that.potentialConflictsCount) { return(-1); } if (this.potentialConflictsCount > that.potentialConflictsCount) { return(1); } // CBS framework conflicts: // It makes sense to prefer nodes that conflict less, and not just nodes that don't conflict at all, // because a 3-way conflict takes more work to resolve than if (this.cbsInternalConflictsCount < that.cbsInternalConflictsCount) { return(-1); } if (this.cbsInternalConflictsCount > that.cbsInternalConflictsCount) { return(1); } // f, conflicts and internal conflicts being equal, prefer nodes with a larger g // - they're closer to the goal so less nodes would probably be generated by them on the way to it. if (this.g < that.g) { return(1); } if (this.g > that.g) { return(-1); } return(0); }