-
Notifications
You must be signed in to change notification settings - Fork 795
/
NondeterministicVacuumEnvironmentDemo.java
50 lines (44 loc) · 1.98 KB
/
NondeterministicVacuumEnvironmentDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package aima.gui.demo.agent;
import aima.core.agent.Action;
import aima.core.agent.impl.SimpleActionTracker;
import aima.core.environment.vacuum.*;
import aima.core.environment.vacuum.VacuumEnvironment.*;
import aima.core.search.agent.NondeterministicSearchAgent;
import aima.core.search.nondeterministic.NondeterministicProblem;
/**
* Applies AND-OR-GRAPH-SEARCH to a non-deterministic version of the Vacuum World.
* @author Andrew Brown
* @author Ruediger Lunde
*/
public class NondeterministicVacuumEnvironmentDemo {
public static void main(String[] args) {
System.out.println("NON-DETERMINISTIC-VACUUM-ENVIRONMENT DEMO");
System.out.println("");
startAndOrSearch();
}
private static void startAndOrSearch() {
System.out.println("AND-OR-GRAPH-SEARCH");
// create environment and agent
VacuumEnvironment world = new NondeterministicVacuumEnvironment(LocationState.Dirty, LocationState.Dirty);
NondeterministicSearchAgent<VacuumPercept, VacuumEnvironmentState, Action> agent =
new NondeterministicSearchAgent<>(VacuumWorldFunctions::getState);
world.addAgent(agent, VacuumEnvironment.LOCATION_A);
// add a listener to the environment to store executed actions
SimpleActionTracker actionTracker = new SimpleActionTracker();
world.addEnvironmentListener(actionTracker);
// provide the agent with a problem formulation so that a contingency plan can be computed
NondeterministicProblem<VacuumEnvironmentState, Action> problem = new NondeterministicProblem<>(
world.getCurrentState(),
VacuumWorldFunctions::getActions,
VacuumWorldFunctions.createResultsFunctionFor(agent),
VacuumWorldFunctions::testGoal,
(s, a, sPrimed) -> 1.0);
agent.makePlan(problem);
// show and execute the plan
System.out.println("initial plan: " + agent.getPlan());
world.stepUntilDone();
System.out.println("actions taken: " + actionTracker.getActions());
System.out.println("final plan: " + agent.getPlan());
System.out.println("final state: " + world.getCurrentState());
}
}