Esempio n. 1
0
    //    public override int hFunction( iThinkState nextState, iThinkState GoalState )
    //    {
    //        return base.hFunction(nextState,GoalState);
    //
    //    }
    public override int hFunction(iThinkState nextState, iThinkState GoalState)
    {
        iThinkState tempState = new iThinkState(GoalState);
        iThinkState curState = new iThinkState(nextState);
        for (int i=0 ; i<depth ; i++)
        {
            foreach (iThinkFact f in curState.getFactList())
            {
                tempState.delFact(f);
            }

            if (tempState.getFactList().Count == 0)
            {
                return i;
            }

            List<iThinkAction> applicableActions = getApplicable(curState, actionManager.getActions());
            iThinkPlan curStep = new iThinkPlan(curState);
            foreach (iThinkAction act in applicableActions)
            {
                iThinkPlan nextStep = progressPositive(curStep, act);
                curStep = nextStep;
            }
            curState = curStep.getState();
        }

        return nonValidHValue;
    }
Esempio n. 2
0
    public override iThinkPlan SearchMethod( iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
    {
        int it = 0;
           iThinkPlan curStep, nextStep;
           iThinkState CurrentState;
           nodesVisited++;
           while ( OpenStates.Count != 0 )
           {
               List<iThinkAction> applicableActions = new List<iThinkAction>();

               curStep = new iThinkPlan( OpenStates[0] );
               CurrentState = OpenStates[0].getState();
               VisitedStates.Add( CurrentState );
               OpenStates.RemoveAt( 0 );

               applicableActions = getApplicable( CurrentState, ActionManager.getActions() );
                if (curStep.getActionCount() < depth)
                {
                        bool flag = true;
                       foreach ( iThinkAction action in applicableActions )
                       {
                           bool found = false;
                           nextStep = progress( curStep, action );
                            nodesVisited++;
                            if ( compareStates( nextStep.getState(), GoalState ) )
                   			{
                                if (flag == true)
                                {
                                    nodesExpanded++;
                                }
                                Debug.Log( "Found Plan (BreadthFS) " + nextStep.getActionCount());
                                Debug.Log("Nodes visited : " + nodesVisited);
                                Debug.Log("Nodes expanded : " + nodesExpanded);

                                Plan.setPlan( nextStep );
                                repoFunct.completed=true;
                                return Plan;
                   			}

                           if (VisitedStates.Contains(nextStep.getState()))
                            {
                                found = true;
                            }

                           if ( found == false )
                           {
                               OpenStates.Add( nextStep );
                                if (flag == true)
                                {
                                    nodesExpanded++;
                                    flag = false;
                                }
                           }
                       }
                    ++it;
            }
           }
           Debug.Log( "Didn't find Plan (BreadthFS)" );
           return null;
    }
Esempio n. 3
0
            /* Returns a new iThinkState, applying only positive effects of this action */
            public iThinkState applyPositiveEffects( iThinkState State )
            {
                iThinkState NewState = new iThinkState( State );

                foreach ( iThinkFact effect in this.effects )
                {
                    if (effect.getPositive())
                    {
                        NewState.addFact(effect);
                    }
                }

                return NewState;
            }
Esempio n. 4
0
            /**
             * Checks whether the action can be applied on iThinkState \a curState
             * @param curState The state to be checked
             * @returns A boolean value
             */
            public bool isApplicable( iThinkState curState )
            {
                int counter = 0;

                foreach ( iThinkFact fact in preconditions )
                {
                    ///@todo Get facts of wanted type/name only
                    foreach ( iThinkFact checkFact in curState.getFactList() )
                    {
                        if ( fact == checkFact )
                            counter++;
                    }
                }
                if ( counter == preconditions.Count ){
                    return true;
                }
                return false;
            }
Esempio n. 5
0
            /// The function performing planning using Forward Search and the specified \a method
            public bool forwardSearch( iThinkState InitialState, iThinkState GoalState, iThinkActionManager ActionManager)
            {
                iThinkPlan ReturnVal;

                _OpenStates.Clear();
                _VisitedStates.Clear();

                iThinkPlan step = new iThinkPlan( InitialState );
                _OpenStates.Add( step );
                _VisitedStates.Add( step.getState() );

                ReturnVal = SearchMethod( GoalState, ActionManager, _OpenStates, _VisitedStates );

                if ( ReturnVal == null )
                    return false;
                else if ( ReturnVal.hasPlan() )
                    return true;
                return false;
            }
Esempio n. 6
0
 public virtual int hFunction( iThinkState nextState, iThinkState GoalState )
 {
     int counter = GoalState.getFactList().Count;
     foreach ( iThinkFact fact in nextState.getFactList() )
     {
         foreach ( iThinkFact goalFact in GoalState.getFactList() )
         {
             if ( fact == goalFact )
             {
                 counter--;
                 break;
             }
         }
     }
     return counter;
 }
Esempio n. 7
0
 public virtual iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
 {
     return null;
 }
Esempio n. 8
0
 /// Checks if goalState is a subset of curState
 public bool compareStates( iThinkState curState, iThinkState goalState )
 {
     int counter = 0;
     foreach ( iThinkFact fact in goalState.getFactList() )
     {
         foreach ( iThinkFact check in curState.getFactList() )
         {
             if ( check == null )
                 return false;
             else if ( check == fact )
                 counter++;
         }
     }
     if ( counter == goalState.getFactList().Count )
         return true;
     return false;
 }
Esempio n. 9
0
            /// Finds all actions applicable to the current \a State from the collection of available \a Actions
            public List<iThinkAction> getApplicable( iThinkState State, List<iThinkAction> Actions )
            {
                List<iThinkAction> ApplicableActions = new List<iThinkAction>();

                foreach ( iThinkAction action in Actions )
                {
                    if ( action == null )
                        break;

                    if ( action.isApplicable( State ) )
                    {
                        ApplicableActions.Add( action );
                    }
                }

                return ApplicableActions;
            }
Esempio n. 10
0
    public override iThinkPlan SearchMethod( iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
    {
        int it = 0;
        iThinkPlan curStep, nextStep;
        iThinkState CurrentState;
        nodesVisited++;
        actionManager = ActionManager;

        while ( OpenStates.Count != 0 )
        {
            List<iThinkAction> applicableActions = new List<iThinkAction>();

            curStep = new iThinkPlan( OpenStates[0] );
            CurrentState = OpenStates[0].getState();
            VisitedStates.Add( CurrentState );
            OpenStates.RemoveAt( 0 );

            applicableActions = getApplicable( CurrentState, ActionManager.getActions() );

            if (curStep.getActionCount() < depth)
            {
                bool flag = true;
                List<iThinkPlan> successors = new List<iThinkPlan>();
                foreach ( iThinkAction action in applicableActions )
                {
                    bool found = false;

                    nextStep = progress( curStep, action );

                    nodesVisited++;
                    if ( compareStates( nextStep.getState(), GoalState ) )
                    {
                        if (flag == true)
                        {
                            nodesExpanded++;
                        }
                        Debug.Log( "Found Plan (H-DepthFS) " + nextStep.getActionCount());
                        //Debug.Log("Nodes visited : " + nodesVisited);
                        //Debug.Log("Nodes expanded : " + nodesExpanded);
                        Plan.setPlan( nextStep );
                        return Plan;
                    }

                    if (VisitedStates.Contains(nextStep.getState()))
                    {
                        found = true;
                    }

                    if ( found == false )
                    {
                        int Cost = hFunction( nextStep.getState(), GoalState );
                        if (Cost != nonValidHValue)
                        {
                            nextStep.getState().setCost( Cost );
                            successors.Add(nextStep);
                            if (flag == true)
                            {
                                flag = false;
                                nodesExpanded++;
                            }
                        }
                    }
                }
                successors.Sort( delegate( iThinkPlan obj1, iThinkPlan obj2 )
                            {
                                if ( obj1.getState().getCost() == obj2.getState().getCost() )
                                    return 0;
                                else if ( obj1.getState().getCost() < obj2.getState().getCost() )
                                    return -1;
                                else
                                    return 1;
                            }
                           );
                OpenStates.InsertRange(0, successors);
                ++it;
            }
        }
        Debug.Log( "Didn't find Plan (H-DepthFS)" );
        return null;
    }
Esempio n. 11
0
 public iThinkPlan( iThinkPlan Step )
 {
     this.State = new iThinkState( Step.State );
     this.Actions = new List<iThinkAction>( Step.Actions );
 }
Esempio n. 12
0
 public iThinkPlan( iThinkState State, List<iThinkAction> Actions )
 {
     this.State = new iThinkState( State );
     this.Actions = new List<iThinkAction>( Actions );
 }
Esempio n. 13
0
    // Use this for initialization
    public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
    {
        int         it = 0;
        iThinkPlan  curStep, nextStep;
        iThinkState CurrentState = null;

        List <iThinkPlan> stateList = null;

        while (OpenStates.Count != 0)
        {
            List <iThinkAction> applicableActions = new List <iThinkAction>();

            stateList = new List <iThinkPlan>();

            curStep      = new iThinkPlan(OpenStates[0]);
            CurrentState = OpenStates[0].getState();
            VisitedStates.Add(CurrentState);

            OpenStates.RemoveAt(0);

            applicableActions = getApplicable(CurrentState, ActionManager.getActions());

            foreach (iThinkAction action in applicableActions)
            {
                bool found = false;
                // todo: Add "statnode" for statistics retrieval
                nextStep = progress(curStep, action);

                if (compareStates(nextStep.getState(), GoalState))
                {
                    Debug.Log("Found Plan (BestFS) " + nextStep.getPlanActions().Count);
                    Plan.setPlan(nextStep);
                    repoFunct.completed = true;
                    return(Plan);
                }

                foreach (iThinkState state in VisitedStates)
                {
                    if (state == nextStep.getState())
                    {
                        found = true;
                        break;
                    }
                }

                if (found == false)
                {
                    int Cost = hFunction(nextStep.getState(), GoalState);
                    nextStep.getState().setCost(Cost);
                    stateList.Add(nextStep);
                }
            }

            OpenStates.AddRange(stateList);
            OpenStates.Sort(delegate(iThinkPlan obj1, iThinkPlan obj2)
            {
                if (obj1.getState().getCost() == obj2.getState().getCost())
                {
                    return(0);
                }
                else if (obj1.getState().getCost() > obj2.getState().getCost())
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
                            );
            ++it;
        }
        //Debug.Log( "Didn't find Plan (BestFS)" );
        return(null);
    }
Esempio n. 14
0
 public override int hFunction( iThinkState nextState, iThinkState GoalState )
 {
     return base.hFunction(nextState,GoalState);
 }
Esempio n. 15
0
 public void setState(iThinkState NewState)
 {
     State = NewState;
 }
Esempio n. 16
0
 public iThinkPlan(iThinkPlan Step)
 {
     this.State   = new iThinkState(Step.State);
     this.Actions = new List <iThinkAction>(Step.Actions);
 }
Esempio n. 17
0
 public iThinkPlan(iThinkState State, List <iThinkAction> Actions)
 {
     this.State   = new iThinkState(State);
     this.Actions = new List <iThinkAction>(Actions);
 }
Esempio n. 18
0
 public iThinkPlan()
 {
     this.State   = null;
     this.Actions = new List <iThinkAction>();
 }
Esempio n. 19
0
 public void setState( iThinkState NewState )
 {
     State = NewState;
 }
Esempio n. 20
0
    public override iThinkPlan SearchMethod( iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
    {
        int it = 0;
        iThinkPlan curStep, nextStep;
        iThinkState CurrentState = null;

        List<iThinkPlan> stateList = null;

        while ( OpenStates.Count != 0 )
        {
            List<iThinkAction> applicableActions = new List<iThinkAction>();

            stateList = new List<iThinkPlan>();

            curStep = new iThinkPlan( OpenStates[0] );
            CurrentState = OpenStates[0].getState();
            //VisitedStates.Add(CurrentState);

            OpenStates.RemoveAt( 0 );
            if (curStep.getActionCount() < depth)
            {
                applicableActions = getApplicable( CurrentState, ActionManager.getActions() );

                foreach ( iThinkAction action in applicableActions )
                {
                    bool found = false;
                    // todo: Add "statnode" for statistics retrieval
                    nextStep = progressPositive( curStep, action );
                    if ( compareStates( nextStep.getState(), GoalState ) )
                    {
                        //Debug.Log( "Found Plan (BestFS) "+nextStep.getPlanActions().Count );
                        Plan.setPlan( nextStep );
                        repoFunct.completed=true;
                        return Plan;
                    }

                    foreach ( iThinkState state in VisitedStates )
                    {
                        if ( state == nextStep.getState() )
                        {
                            found = true;
                            break;
                        }
                    }

                    if ( found == false )
                    {
                        int Cost = hFunction( nextStep.getState(), GoalState );
                        Cost = Cost + nextStep.getPlanActions().Count;
                        nextStep.getState().setCost( Cost );
                        stateList.Add( nextStep );
                    }

                }
                OpenStates.AddRange( stateList );
                OpenStates.Sort( delegate( iThinkPlan obj1, iThinkPlan obj2 )
                            {
                                if ( obj1.getState().getCost() == obj2.getState().getCost() )
                                    return 0;
                                else if ( obj1.getState().getCost() < obj2.getState().getCost() )
                                    return -1;
                                else
                                    return 1;
                            }
                           );
                ++it;
            }

        }
        //Debug.Log( "Didn't find Plan (BestFS)" );
        return null;
    }
Esempio n. 21
0
 public iThinkPlan()
 {
     this.State = null;
     this.Actions = new List<iThinkAction>();
 }