burlap.shell.visual.VisualExplorer Java Examples

The following examples show how to use burlap.shell.visual.VisualExplorer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HelloGridWorld.java    From burlap_examples with MIT License 6 votes vote down vote up
public static void main(String[] args) {

		GridWorldDomain gw = new GridWorldDomain(11,11); //11x11 grid world
		gw.setMapToFourRooms(); //four rooms layout
		gw.setProbSucceedTransitionDynamics(0.8); //stochastic transitions with 0.8 success rate
		SADomain domain = gw.generateDomain(); //generate the grid world domain

		//setup initial state
		State s = new GridWorldState(new GridAgent(0, 0), new GridLocation(10, 10, "loc0"));

		//create visualizer and explorer
		Visualizer v = GridWorldVisualizer.getVisualizer(gw.getMap());
		VisualExplorer exp = new VisualExplorer(domain, v, s);

		//set control keys to use w-s-a-d
		exp.addKeyAction("w", GridWorldDomain.ACTION_NORTH, "");
		exp.addKeyAction("s", GridWorldDomain.ACTION_SOUTH, "");
		exp.addKeyAction("a", GridWorldDomain.ACTION_WEST, "");
		exp.addKeyAction("d", GridWorldDomain.ACTION_EAST, "");

		exp.initGUI();

	}
 
Example #2
Source File: ExampleGridWorld.java    From burlap_examples with MIT License 6 votes vote down vote up
public static void main(String [] args){

		ExampleGridWorld gen = new ExampleGridWorld();
		gen.setGoalLocation(10, 10);
		SADomain domain = gen.generateDomain();
		State initialState = new EXGridState(0, 0);
		SimulatedEnvironment env = new SimulatedEnvironment(domain, initialState);

		Visualizer v = gen.getVisualizer();
		VisualExplorer exp = new VisualExplorer(domain, env, v);

		exp.addKeyAction("w", ACTION_NORTH, "");
		exp.addKeyAction("s", ACTION_SOUTH, "");
		exp.addKeyAction("d", ACTION_EAST, "");
		exp.addKeyAction("a", ACTION_WEST, "");

		exp.initGUI();


	}
 
Example #3
Source File: FrostbiteDomain.java    From burlap with Apache License 2.0 6 votes vote down vote up
/**
 * Main function to test the domain.
 * Note: The termination conditions are not checked when testing the domain this way, which means it is
 * impossible to win or die and might trigger bugs. To enable them, uncomment the code in the "update" function.
 *
 * @param args command line args
 */
public static void main(String[] args) {
	FrostbiteDomain fd = new FrostbiteDomain();
	SADomain d = fd.generateDomain();
	State s = new FrostbiteState();

	Visualizer vis = FrostbiteVisualizer.getVisualizer();
	VisualExplorer exp = new VisualExplorer(d, vis, s);

	exp.addKeyAction("a", ACTION_WEST, "");
	exp.addKeyAction("d", ACTION_EAST, "");
	exp.addKeyAction("w", ACTION_NORTH, "");
	exp.addKeyAction("s", ACTION_SOUTH, "");
	exp.addKeyAction("x", ACTION_IDLE, "");

	exp.initGUI();
}
 
Example #4
Source File: IRLExample.java    From burlap_examples with MIT License 5 votes vote down vote up
/**
 * Creates a visual explorer that you can use to to record trajectories. Use the "`" key to reset to a random initial state
 * Use the wasd keys to move north south, east, and west, respectively. To enable recording,
 * first open up the shell and type: "rec -b" (you only need to type this one). Then you can move in the explorer as normal.
 * Each demonstration begins after an environment reset.
 * After each demonstration that you want to keep, go back to the shell and type "rec -r"
 * If you reset the environment before you type that,
 * the episode will be discarded. To temporarily view the episodes you've created, in the shell type "episode -v". To actually record your
 * episodes to file, type "rec -w path/to/save/directory base_file_name" For example "rec -w irl_demos demo"
 * A recommendation for examples is to record two demonstrations that both go to the pink cell while avoiding blue ones
 * and do so from two different start locations on the left (if you keep resetting the environment, it will change where the agent starts).
 */
public void launchExplorer(){
	SimulatedEnvironment env = new SimulatedEnvironment(this.domain, this.sg);
	VisualExplorer exp = new VisualExplorer(this.domain, env, this.v, 800, 800);
	exp.addKeyAction("w", GridWorldDomain.ACTION_NORTH, "");
	exp.addKeyAction("s", GridWorldDomain.ACTION_SOUTH, "");
	exp.addKeyAction("d", GridWorldDomain.ACTION_EAST, "");
	exp.addKeyAction("a", GridWorldDomain.ACTION_WEST, "");

	//exp.enableEpisodeRecording("r", "f", "irlDemo");

	exp.initGUI();
}
 
Example #5
Source File: BlocksWorld.java    From burlap with Apache License 2.0 5 votes vote down vote up
/**
 * Main method for exploring the domain. The initial state will have 3 red blocks starting on the table. By default this method will launch the visual explorer.
 * Pass a "t" argument to use the terminal explorer.
 * @param args process arguments
 */
public static void main(String [] args){
	
	BlocksWorld bw = new BlocksWorld();
	SADomain domain = bw.generateDomain();
	
	State s = getNewState(3);
	
	int expMode = 1;
	if(args.length > 0){
		if(args[0].equals("v")){
			expMode = 1;
		}
		else if(args[0].equals("t")){
			expMode = 0;
		}
	}
	
	
	if(expMode == 0){

		EnvironmentShell shell = new EnvironmentShell(domain, s);
		shell.start();
		
	}
	else if(expMode == 1){
		VisualExplorer exp = new VisualExplorer(domain, BlocksWorldVisualizer.getVisualizer(24), s);
		
		
		exp.initGUI();
	}
	
}
 
Example #6
Source File: GridWorldDQN.java    From burlap_caffe with Apache License 2.0 4 votes vote down vote up
public static void main(String args[]) {

        // Learning constants
        double gamma = 0.99;
        int replayStartSize = 50000;
        int memorySize = 1000000;
        double epsilonStart = 1;
        double epsilonEnd = 0.1;
        double testEpsilon = 0.05;
        int epsilonAnnealDuration = 1000000;
        int staleUpdateFreq = 10000;

        // Caffe solver file
        String solverFile = "example_models/grid_world_dqn_solver.prototxt";

        // Load Caffe
        Loader.load(caffe.Caffe.class);

        // Setup the network
        GridWorldDQN gridWorldDQN = new GridWorldDQN(solverFile, gamma);

        // Create the policies
        SolverDerivedPolicy learningPolicy =
                new AnnealedEpsilonGreedy(epsilonStart, epsilonEnd, epsilonAnnealDuration);
        SolverDerivedPolicy testPolicy = new EpsilonGreedy(testEpsilon);

        // Setup the learner
        DeepQLearner deepQLearner =
                new DeepQLearner(gridWorldDQN.domain, gamma, replayStartSize, learningPolicy, gridWorldDQN.dqn);
        deepQLearner.setExperienceReplay(new FixedSizeMemory(memorySize), gridWorldDQN.dqn.batchSize);
        deepQLearner.useStaleTarget(staleUpdateFreq);

        // Setup the tester
        Tester tester = new SimpleTester(testPolicy);

        // Set the QProvider for the policies
        learningPolicy.setSolver(deepQLearner);
        testPolicy.setSolver(deepQLearner);

        // Setup the visualizer
        VisualExplorer exp = new VisualExplorer(
                gridWorldDQN.domain, gridWorldDQN.env, GridWorldVisualizer.getVisualizer(gridWorldDQN.gwdg.getMap()));
        exp.initGUI();
        exp.startLiveStatePolling(33);

        // Setup helper
        TrainingHelper helper = new TrainingHelper(
                deepQLearner, tester, gridWorldDQN.dqn, actionSet, gridWorldDQN.env);
        helper.setTotalTrainingSteps(50000000);
        helper.setTestInterval(500000);
        helper.setTotalTestSteps(125000);
        helper.setMaxEpisodeSteps(10000);

        // Run helper
        helper.run();
    }
 
Example #7
Source File: ExampleOOGridWorld.java    From burlap_examples with MIT License 4 votes vote down vote up
public static void main(String [] args){

		ExampleOOGridWorld gen = new ExampleOOGridWorld();
		OOSADomain domain = gen.generateDomain();
		State initialState = new GenericOOState(new ExGridAgent(0, 0), new EXGridLocation(10, 10, "loc0"));
		SimulatedEnvironment env = new SimulatedEnvironment(domain, initialState);

		Visualizer v = gen.getVisualizer();
		VisualExplorer exp = new VisualExplorer(domain, env, v);

		exp.addKeyAction("w", ACTION_NORTH, "");
		exp.addKeyAction("s", ACTION_SOUTH, "");
		exp.addKeyAction("d", ACTION_EAST, "");
		exp.addKeyAction("a", ACTION_WEST, "");

		exp.initGUI();


	}
 
Example #8
Source File: BlockDude.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Runs an interactive visual explorer for level one of Block Dude. The keys w,a,d,s,x correspond to actions
 * up, west, east, pick up, put down.
 * @param args can be empty.
 */
public static void main(String[] args) {

	BlockDude bd = new BlockDude();
	SADomain domain = bd.generateDomain();
	State s = BlockDudeLevelConstructor.getLevel2(domain);

	Visualizer v = BlockDudeVisualizer.getVisualizer(bd.maxx, bd.maxy);



	VisualExplorer exp = new VisualExplorer(domain, v, s);

	exp.addKeyAction("w", ACTION_UP, "");
	exp.addKeyAction("d", ACTION_EAST, "");
	exp.addKeyAction("a", ACTION_WEST, "");
	exp.addKeyAction("s", ACTION_PICKUP, "");
	exp.addKeyAction("x", ACTION_PUT_DOWN, "");

	exp.initGUI();



}
 
Example #9
Source File: MountainCar.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Will launch a visual explorer for the mountain car domain that is controlled with the a-s-d keys.
 * @param args empty arguments.
 */
public static void main(String [] args){
	
	MountainCar mcGen = new MountainCar();
	SADomain domain = mcGen.generateDomain();
	State s = mcGen.valleyState();
	

	Visualizer vis = MountainCarVisualizer.getVisualizer(mcGen);
	VisualExplorer exp = new VisualExplorer(domain, vis, s);
	
	exp.addKeyAction("d", ACTION_FORWARD, "");
	exp.addKeyAction("s", ACTION_COAST, "");
	exp.addKeyAction("a", ACTION_BACKWARDS, "");
	
	exp.initGUI();
	
}
 
Example #10
Source File: LunarLanderDomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * This method will launch a visual explorer for the lunar lander domain. It will use the default
 * physics, start the agent on the left side of the world with a landing pad on the right
 * and an obstacle in between. The agent is controlled with the following keys: <p>
 * w: heavy thrust<p>
 * s: weak thrust<p>
 * a: turn/rotate counterclockwise<p>
 * d: turn/rotate clockwise<p>
 * x: idle (drift for one time step)
 * <p>
 * If you pass the main method "t" as an argument, a terminal explorer will be used instead of a visual explorer.
 * @param args optionally pass "t" asn argument to use a terminal explorer instead of a visual explorer.
 */
public static void main(String[] args) {

	LunarLanderDomain lld = new LunarLanderDomain();
	SADomain domain = lld.generateDomain();



	LLState clean = new LLState(
			new LLAgent(5, 0, 0),
			new LLBlock.LLPad(80, 95, 0, 10, "pad"),
			new LLBlock.LLObstacle(60, 70, 0, 13, "obstacle")
	);


	int expMode = 1;

	if(args.length > 0){
		if(args[0].equals("v")){
			expMode = 1;
		}
		else if(args[0].equals("t")){
			expMode = 0;
		}
	}

	if(expMode == 0){

		EnvironmentShell shell = new EnvironmentShell(domain, clean);
		shell.start();

	}
	else if(expMode == 1){

		Visualizer vis = LLVisualizer.getVisualizer(lld);
		VisualExplorer exp = new VisualExplorer(domain, vis, clean);

		exp.addKeyAction("w", ACTION_THRUST, "0.32");
		exp.addKeyAction("s", ACTION_THRUST, String.valueOf(-lld.physParams.gravity));
		exp.addKeyAction("a", ACTION_TURN_LEFT, "");
		exp.addKeyAction("d", ACTION_TURN_RIGHT, "");
		exp.addKeyAction("x", ACTION_IDLE, "");

		exp.initGUI();

	}

}
 
Example #11
Source File: GridWorldDomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a visual explorer or terminal explorer. By default a visual explorer is presented; use the "t" argument
 * to create terminal explorer. Will create a 4 rooms grid world with the agent in lower left corner and a location in
 * the upper right. Use w-a-s-d to move.
 * @param args command line args
 */
public static void main(String[] args) {

	GridWorldDomain gwdg = new GridWorldDomain(11, 11);
	gwdg.setMapToFourRooms();
	//gwdg.setProbSucceedTransitionDynamics(0.75);

	SADomain d = gwdg.generateDomain();


	GridWorldState s = new GridWorldState(new GridAgent(0, 0), new GridLocation(10, 10, "loc0"));

	
	int expMode = 1;
	if(args.length > 0){
		if(args[0].equals("v")){
			expMode = 1;
		}
		else if(args[0].equals("t")){
			expMode = 0;
		}
	}
	
	if(expMode == 0){

		EnvironmentShell shell = new EnvironmentShell(d, s);
		shell.start();
		
	}
	else if(expMode == 1){
		
		Visualizer v = GridWorldVisualizer.getVisualizer(gwdg.getMap());
		VisualExplorer exp = new VisualExplorer(d, v, s);
		
		//use w-s-a-d-x
		exp.addKeyAction("w", ACTION_NORTH, "");
		exp.addKeyAction("s", ACTION_SOUTH, "");
		exp.addKeyAction("a", ACTION_WEST, "");
		exp.addKeyAction("d", ACTION_EAST, "");
		
		exp.initGUI();
	}
	
	
}
 
Example #12
Source File: InvertedPendulum.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * @param args none expected
 */
public static void main(String[] args) {

	InvertedPendulum ivp = new InvertedPendulum();
	SADomain domain = ivp.generateDomain();
	
	State s = new InvertedPendulumState();
	
	Visualizer v = CartPoleVisualizer.getCartPoleVisualizer();
	
	VisualExplorer exp = new VisualExplorer(domain, v, s);
	
	exp.addKeyAction("a", ACTION_LEFT, "");
	exp.addKeyAction("d", ACTION_RIGHT, "");
	exp.addKeyAction("s", ACTION_NO_FORCE, "");
	
	exp.initGUI();

}
 
Example #13
Source File: CartPoleDomain.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Launches an interactive visualize in which key 'a' applies a force in the left direction and key 'd' applies force in the right direction.
 * The corrected physics model is used.
 * @param args ignored.
 */
public static void main(String [] args){
	CartPoleDomain dgen = new CartPoleDomain();

	SADomain domain = dgen.generateDomain();
	
	State s = new CartPoleFullState();
	
	VisualExplorer exp = new VisualExplorer(domain, CartPoleVisualizer.getCartPoleVisualizer(), s);
	exp.addKeyAction("a", ACTION_LEFT, "");
	exp.addKeyAction("d", ACTION_RIGHT, "");
	
	exp.initGUI();
	
}