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; }
// 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); }
// 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; }
public iThinkPlanner() { nodesExpanded = 0; nodesVisited = 0; Plan = new iThinkPlan(); _OpenStates = new List <iThinkPlan>(); _VisitedStates = new List <iThinkState>(); }
public iThinkPlanner() { nodesExpanded = 0; nodesVisited = 0; Plan = new iThinkPlan(); _OpenStates = new List<iThinkPlan>(); _VisitedStates = new List<iThinkState>(); }
/*new progress function, where only the positive effects of actions will be applied */ public iThinkPlan progressPositive(iThinkPlan Step, iThinkAction Action) { iThinkPlan NewStep = new iThinkPlan(Step); List <iThinkAction> curActions; curActions = NewStep.getPlanActions(); curActions.Add(Action); NewStep.setState(Action.applyPositiveEffects(Step.getState())); return(NewStep); }
/// 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; }
/// 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); }
public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates) { int it = 0; actionManager = ActionManager; iThinkPlan curStep, nextStep; iThinkState CurrentState = null; List <iThinkPlan> stateList = null; nodesVisited++; 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) { bool flag = true; applicableActions = getApplicable(CurrentState, ActionManager.getActions()); foreach (iThinkAction action in applicableActions) { bool found = false; // todo: Add "statnode" for statistics retrieval nextStep = progress(curStep, action); nodesVisited++; if (compareStates(nextStep.getState(), GoalState)) { if (flag == true) { nodesExpanded++; } Debug.Log("Found Plan (AstarFS) " + nextStep.getPlanActions().Count + ", Nodes Expanded :" + nodesExpanded); //Debug.Log( "Nodes visited : " + nodesVisited); Plan.setPlan(nextStep); repoFunct.completed = true; return(Plan); } if (VisitedStates.Contains(nextStep.getState())) { found = true; } if (found == false) { int Cost = hFunction(nextStep.getState(), GoalState); Cost = Cost + nextStep.getPlanActions().Count; nextStep.getState().setCost(Cost); stateList.Add(nextStep); if (flag == true) { nodesExpanded++; flag = false; } } } 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 (AstarFS)" ); return(null); }
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; }
/*new progress function, where only the positive effects of actions will be applied */ public iThinkPlan progressPositive( iThinkPlan Step, iThinkAction Action ) { iThinkPlan NewStep = new iThinkPlan( Step ); List<iThinkAction> curActions; curActions = NewStep.getPlanActions(); curActions.Add( Action ); NewStep.setState( Action.applyPositiveEffects( Step.getState() ) ); return NewStep; }
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; }
public void setPlan( iThinkPlan plan ) { Actions = new List<iThinkAction>( plan.getPlanActions() ); }
public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates) { int it = 0; iThinkPlan curStep, nextStep; iThinkState CurrentState; nodesExpanded = 0; 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()); int count = 0; 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 (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) { OpenStates.Insert(count, nextStep); count++; if (flag == true) { nodesExpanded++; flag = false; } } } ++it; } } //Debug.Log( "Didn't find Plan (DepthFS) " + it ); return(null); }
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); }
public iThinkPlan(iThinkPlan Step) { this.State = new iThinkState(Step.State); this.Actions = new List <iThinkAction>(Step.Actions); }
public void showPlan(iThinkPlan p, string g) { plan = p; hasPlan = true; goal = g; }
public void setPlan(iThinkPlan plan) { Actions = new List <iThinkAction>(plan.getPlanActions()); }
public iThinkPlan( iThinkPlan Step ) { this.State = new iThinkState( Step.State ); this.Actions = new List<iThinkAction>( Step.Actions ); }