Ejemplo n.º 1
0
 public int CompareTo(ThreatenedLinkFlaw other)
 {
     if (other == null)
     {
         return(1);
     }
     if (threatener.ID == other.threatener.ID)
     {
         if (causallink.Predicate.Equals(other.causallink.Predicate))
         {
             if (causallink.Head.ID != other.causallink.Head.ID)
             {
                 if (causallink.Head.ID < other.causallink.Head.ID)
                 {
                     return(-1);
                 }
                 else
                 {
                     return(1);
                 }
             }
             else if (causallink.Tail.ID != other.causallink.Tail.ID)
             {
                 if (causallink.Tail.ID < other.causallink.Tail.ID)
                 {
                     return(-1);
                 }
                 else
                 {
                     return(1);
                 }
             }
             // causal link is the same, and the threat is the same
             throw new System.Exception();
         }
         else
         {
             return(PredicateComparer.CompareTo(causallink.Predicate, other.causallink.Predicate));
         }
     }
     else if (threatener.ID < other.threatener.ID)
     {
         return(-1);
     }
     else
     {
         return(1);
     }
 }
Ejemplo n.º 2
0
        public int CompareTo(OpenCondition other)
        {
            if (other == null)
            {
                return(1);
            }

            // check static
            if (isStatic && !other.isStatic)
            {
                return(-1);
            }
            else if (other.isStatic && !isStatic)
            {
                return(1);
            }

            if (step.Depth > other.step.Depth)
            {
                return(1);
            }
            else if (step.Depth < other.step.Depth)
            {
                return(-1);
            }

            // MW-Loc-Conf = {threats} LIFO / {unsafe} MW_add / {local} MW_add

            // if one is unsafe and the other is not.
            if (risks > 0 && other.risks == 0)
            {
                return(-1);
            }
            else if (other.risks > 0 && risks == 0)
            {
                return(1);
            }
            if (other.risks > 0 && risks == other.risks)
            {
                // if they are both unsafe, choose one with most work
                if (addReuseHeuristic > other.addReuseHeuristic)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }

            // Local step's open conditions first. Lower planstep ID == added to plan earlier
            if (step.ID < other.step.ID)
            {
                return(-1);
            }
            else if (step.ID > other.step.ID)
            {
                return(1);
            }

            // If they are of the same step, only then do we select between mos work...
            if (addReuseHeuristic > other.addReuseHeuristic)
            {
                return(-1);
            }
            else if (addReuseHeuristic < other.addReuseHeuristic)
            {
                return(1);
            }

            // tiebreaker if they are the same work
            if (precondition.Equals(other.precondition))
            {
                throw new System.Exception();
            }
            else
            {
                return(PredicateComparer.CompareTo(precondition, other.precondition));
            }
        }
Ejemplo n.º 3
0
        public int CompareTo(OpenCondition other)
        {
            if (other == null)
            {
                return(1);
            }

            // check static
            if (isStatic && !other.isStatic)
            {
                return(-1);
            }
            else if (other.isStatic && !isStatic)
            {
                return(1);
            }

            // {dummyGoal} LIFO

            // take care of open conditions arising from substeps that are found in initial step.
            //if (isDummyGoal && !other.isDummyGoal)
            //{
            //    return -1;
            //}
            //else if (other.isDummyGoal && !isDummyGoal)
            //{
            //    return 1;
            //}
            //else if (other.isDummyGoal && isDummyGoal)
            //{
            //    if (addReuseHeuristic > other.addReuseHeuristic)
            //    {
            //        return -1;
            //    }
            //    else
            //    {
            //        return 1;
            //    }
            //}

            ////take care of open conditions arising from substeps that are found in initial step.
            //if (hasDummyInit && !other.hasDummyInit)
            //{
            //    return -1;
            //}
            //else if (other.hasDummyInit && !hasDummyInit)
            //{
            //    return 1;
            //}
            //else if (other.hasDummyInit && hasDummyInit)
            //{
            //    if (addReuseHeuristic > other.addReuseHeuristic)
            //    {
            //        return -1;
            //    }
            //    else
            //    {
            //        return 1;
            //    }
            //}

            if (step.Depth > other.step.Depth)
            {
                return(1);
            }
            else if (step.Depth < other.step.Depth)
            {
                return(-1);
            }

            if (precondition.Name.Equals("obss") || precondition.Name.Equals("obs-starts"))
            {
                if (other.precondition.Name.Equals("obss") || other.precondition.Name.Equals("obs-starts"))
                {
                    if (risks > 0 && other.risks == 0)
                    {
                        return(-1);
                    }
                    else if (other.risks > 0 && risks == 0)
                    {
                        return(1);
                    }
                    if (other.risks > 0 && risks == other.risks)
                    {
                        // if they are both unsafe, choose one with most work
                        if (addReuseHeuristic > other.addReuseHeuristic)
                        {
                            return(-1);
                        }
                        else
                        {
                            return(1);
                        }
                    }

                    // Local step's open conditions first. Lower planstep ID == added to plan earlier
                    if (step.ID < other.step.ID)
                    {
                        return(-1);
                    }
                    else if (step.ID > other.step.ID)
                    {
                        return(1);
                    }

                    // If they are of the same step, only then do we select between mos work...
                    if (addReuseHeuristic > other.addReuseHeuristic)
                    {
                        return(-1);
                    }
                    else if (addReuseHeuristic < other.addReuseHeuristic)
                    {
                        return(1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            else if (other.precondition.Name.Equals("obs-starts") || other.precondition.Name.Equals("obss"))
            {
                return(1);
            }

            // MW-Loc-Conf = {threats} LIFO / {unsafe} MW_add / {local} MW_add

            // if one is unsafe and the other is not.
            if (risks > 0 && other.risks == 0)
            {
                return(-1);
            }
            else if (other.risks > 0 && risks == 0)
            {
                return(1);
            }
            if (other.risks > 0 && risks == other.risks)
            {
                // if they are both unsafe, choose one with most work
                if (addReuseHeuristic > other.addReuseHeuristic)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }

            // Local step's open conditions first. Lower planstep ID == added to plan earlier
            if (step.ID < other.step.ID)
            {
                return(-1);
            }
            else if (step.ID > other.step.ID)
            {
                return(1);
            }

            // If they are of the same step, only then do we select between mos work...
            if (addReuseHeuristic > other.addReuseHeuristic)
            {
                return(-1);
            }
            else if (addReuseHeuristic < other.addReuseHeuristic)
            {
                return(1);
            }

            // tiebreaker if they are the same work
            if (precondition.Equals(other.precondition))
            {
                throw new System.Exception();
            }
            else
            {
                return(PredicateComparer.CompareTo(precondition, other.precondition));
            }
        }
Ejemplo n.º 4
0
        public int CompareTo(OpenCondition other)
        {
            if (other == null)
            {
                return(1);
            }

            // check static
            if (isStatic && !other.isStatic)
            {
                return(-1);
            }
            else if (other.isStatic && !isStatic)
            {
                return(1);
            }

            // check init
            if (isInit && !other.isInit)
            {
                return(-1);
            }
            else if (other.isInit && !isInit)
            {
                return(1);
            }

            // check risks
            if (risks > 0 || other.risks > 0)
            {
                if (risks > other.risks)
                {
                    return(-1);
                }
                else if (risks < other.risks)
                {
                    return(1);
                }
            }

            // check cndts
            if (cndts > other.cndts)
            {
                return(-1);
            }
            else if (cndts < other.cndts)
            {
                return(1);
            }

            // resort to tiebreak criteria
            if (step.ID == other.step.ID)
            {
                if (precondition.Equals(other.precondition))
                {
                    throw new System.Exception();
                }
                else
                {
                    return(PredicateComparer.CompareTo(precondition, other.precondition));
                }
            }
            else if (step.ID < other.step.ID)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }