Beispiel #1
0
        public override IEnumerable <Path <SS, DS> > Compute(SS ss, DS ds, Goal <SS, DS> Goal, Operator <SS, DS>[] Ops)
        {
            this.init(ss, ds, Ops, Goal);
            ExtendedDictionary <DS, Metric> H1   = new ExtendedDictionary <DS, Metric>(x => aS.h(x, aS.Sgoal));
            ExtendedDictionary <DS, DS>     tree = new ExtendedDictionary <DS, DS>(x => null);
            Path <SS, DS> Incumbant         = null;
            int           GlobalSearchLimit = GetGlobalSearchComputationLimit( );

            this.aS.ComputationLimit = GlobalSearchLimit;
            int LocalSearchLimit = GetLocalSearchComputationLimit( );

            foreach (Path <SS, DS> p in AnytimeDStarLiteLookahead(aS, GlobalSearchLimit))
            {
                this.Expansions  += aS.Expansions;
                this.Generations += aS.Generations;
                aS.Expansions     = 0;
                aS.Generations    = 0;
                if (p == null)
                {
                    switch (sm)
                    {
                    /*case ChooseMethodStep.LRTAStar:
                     * yield return LRTAStar<SS, DS>.AStarLookAhead( ss.InitialDynamicState, ss,
                     *    LocalSearchLimit, aS.sv,
                     *    ref this.Expansions, ref this.Generations, false,
                     *    Ops, H1, H, Goal, Metric.One, false );
                     * break;
                     * case ChooseMethodStep.RTAStar:
                     * yield return LRTAStar<SS, DS>.AStarLookAhead( ss.InitialDynamicState, ss,
                     *    LocalSearchLimit, aS.sv,
                     *    ref this.Expansions, ref this.Generations, false,
                     *    Ops, H1, H, Goal, Metric.One, true );
                     * break;*/
                    case ChooseMethodStep.LSSLRTAStar:
                        yield return(LSSLRTAStar <SS, DS> .LSSLRTAStarLookahead(LocalSearchLimit, ss, aS.Sstart,
                                                                                aS.Sgoal, Ops, aS.h, ref Incumbant, ref this.Expansions, aS.sv, tree, H1));

                        break;
                    }
                }
                else
                {
                    yield return(p);
                }
                aS.Sstart = aS.ss.InitialDynamicState;
            }
            yield break;
        }
Beispiel #2
0
        private Path <SS, DS> ChooseStep( )
        {
            try {
                if (!ComputeShortestPathNormalTermination && !rhs(Sstart).Equals(Metric.PositiveInfinity))
                {
                    var ret = this.ExtractPath( );
                    (this.sv as OpenGLStateVisualizer).Global = true;
                    return(ret);
                }
                else
                {
                    (this.sv as OpenGLStateVisualizer).Global = false;
                    if (sm.Equals(ChooseMethodStep.Null))
                    {
                        return(null);
                    }
                    /// Choose a landmark goal state to step towards.
                    DS LandmarkGoal = null;
                    switch (lgm)
                    {
                    case ChooseMethodLandMarkGoal.UTop:
                        LandmarkGoal = U.Top( );
                        break;

                    case ChooseMethodLandMarkGoal.USample:
                        LandmarkGoal = Nearest(Sstart, us);
                        break;

                    case ChooseMethodLandMarkGoal.Goal:
                        LandmarkGoal = Sgoal;
                        break;
                    }
                    if (LandmarkGoal == null)
                    {
                        return(null);
                    }

                    /// Choose the successor nodes we want to consider to move toward.
                    IEnumerable <DS> succ = null;
                    bool             LLR  = false;
                    switch (fsm)
                    {
                    case ChooseMethodFilterSucc.All:
                        succ = Succ(Sstart);
                        break;

                    case ChooseMethodFilterSucc.Lock:
                        succ = Succ(Sstart);
                        if (succ == null)
                        {
                            break;
                        }
                        succ = succ.Where(st => !this.LockedList.Contains(st));
                        if (succ.Count( ) == 0)
                        {
                            succ = Succ(Sstart);
                            LLR  = true;
                            LockedList.Add(Sstart);
                        }
                        // Test if should add to dead end list.
                        if (succ.Where(st => !this.LockedList.Contains(st)).All(
                                ds => h(ds, LandmarkGoal) > h(Sstart, LandmarkGoal)))
                        {
                            LockedList.Add(Sstart);
                        }
                        break;
                    }
                    if (succ == null)
                    {
                        return(null);
                    }

                    /// Choose the state we want to step towards.
                    DS next = null;
                    switch (sm)
                    {
                    case ChooseMethodStep.MinHLandmarkGoal:
                        this.Expansions++;
                        this.Generations += (uint)succ.Count( );
                        next              = succ.ArgMin(ds => h(ds, LandmarkGoal));
                        break;

                    case ChooseMethodStep.MinHAdustedLandmarkGoal:
                        this.Expansions++;
                        this.Generations += (uint)succ.Count( );
                        Metric minV = null;
                        foreach (var s in succ)
                        {
                            Metric h = hAdjusted(s, Sgoal);
                            if (minV == null || (h != null && minV > h))
                            {
                                minV = h;
                                next = s;
                            }
                        }
                        // Update hAdjusted for current state.
                        if (minV != null)
                        {
                            hAdjusted(Sstart, minV + h(next, Sstart));
                        }
                        break;

                    /*case ChooseMethodStep.LRTAStar:
                     * int Expansions = GetLocalSearchComputationLimit( );
                     * var P = LRTAStar<SS, DS>.AStarLookAhead( ss.InitialDynamicState, ss,
                     *    Expansions, sv,
                     *    ref this.Expansions, ref this.Generations, false,
                     *    Ops, HAdjusted, H, new InStateGoal<SS, DS>( LandmarkGoal ), Weight, false );
                     * if ( P == null ) {
                     *  next = null;
                     * } else {
                     *  next = P.Actions.First.Value.PerformOn( Sstart, ss ).First( );
                     * }
                     * break;
                     * case ChooseMethodStep.RTAStar:
                     * Expansions = GetLocalSearchComputationLimit( );
                     * P = LRTAStar<SS, DS>.AStarLookAhead( ss.InitialDynamicState, ss,
                     *    Expansions, sv,
                     *    ref this.Expansions, ref this.Generations, false,
                     *    Ops, HAdjusted, H, new InStateGoal<SS, DS>( LandmarkGoal ), Weight, true );
                     * if ( P == null ) {
                     *  next = null;
                     * } else {
                     *  next = P.Actions.First.Value.PerformOn( Sstart, ss ).First( );
                     * }
                     * break;
                     * case ChooseMethodStep.AStar:
                     * Expansions = GetLocalSearchComputationLimit( );
                     * P = LRTAStar<SS, DS>.AStarLookAhead( ss.InitialDynamicState, ss,
                     *    Expansions, sv,
                     *    ref this.Expansions, ref this.Generations, false,
                     *    Ops, null, H, new InStateGoal<SS, DS>( LandmarkGoal ), Weight, false );
                     * if ( P == null ) {
                     *  next = null;
                     * } else {
                     *  next = P.Actions.First.Value.PerformOn( Sstart, ss ).First( );
                     * }
                     * break;*/
                    case ChooseMethodStep.LSSLRTAStar:
                        int Expansions = GetLocalSearchComputationLimit( );
                        var P          = LSSLRTAStar <SS, DS> .LSSLRTAStarLookahead(Expansions, ss, Sstart,
                                                                                    Sgoal, Ops, h0, ref Incumbant, ref this.Expansions, sv, tree, HLSS);

                        if (P == null)
                        {
                            next = null;
                        }
                        else
                        {
                            next = P.Actions.First.Value.PerformOn(Sstart, ss).First( );
                        }
                        break;
                    }

                    if (next == null)
                    {
                        return(null);
                    }

                    if (LLR)
                    {
                        LockedList.Remove(next);
                        LLR = false;
                    }

                    /// Extract the path info.
                    Operator <SS, DS> Op = null;
                    foreach (var action in Ops)
                    {
                        if (action.IsValidOn(Sstart, ss, false) && action.PerformOn(Sstart, ss).First( ).Equals(next))
                        {
                            Op = action;
                            break;
                        }
                    }
                    if (Op == null)
                    {
                        return(null);
                    }
                    else
                    {
                        return(Operator <SS, DS> .MakePath(Op));
                    }
                }
            } catch (InvalidOperationException) {
                return(null);
            }
        }