Beispiel #1
0
stateread.apply_state_str(world, state1_str)

# Creates a PhaseManager object, which wraps a MIDCA object
myMidca = base.PhaseManager(world, display=DISPLAY_FUNC, verbose=2)

# Add phases by name
for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Cleanup", "Intend", "Plan", "Act"]:
    myMidca.append_phase(phase)

# Add the modules which instantiate basic operation
#myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
myMidca.append_module("Simulate", simulator.NBeaconsActionSimulator(wind=WIND_ENABLED,wind_dir=WIND_DIR,wind_strength=WIND_STRENGTH,dim=DIMENSION,wind_schedule=wind_schedule))
myMidca.append_module("Simulate", simulator.ASCIIWorldViewer(DISPLAY_FUNC))
myMidca.append_module("Perceive", perceive.PerfectObserver())

myMidca.append_module("Interpret", note.StateDiscrepancyDetector())
myMidca.append_module("Interpret", assess.SimpleNBeaconsExplain())
myMidca.append_module("Interpret", guide.SimpleNBeaconsGoalManager())
#myMidca.append_module("Interpret", assess.SimpleNBeaconsExplain())
#myMidca.append_module("Interpret", assess.SimpleNBeaconsExplain())

#myMidca.append_module("Interpret", guide.UserGoalInput())
myMidca.append_module("Interpret", guide.NBeaconsGoalGenerator(numbeacons=2,goalList=goal_list))
myMidca.append_module("Eval", evaluate.NBeaconsDataRecorder())
myMidca.append_module("Cleanup", simulator.NBeaconsSimulator(beacon_fail_rate=BEACON_FAIL_RATE))
myMidca.append_module("Intend", intend.SimpleIntend())
myMidca.append_module("Plan", planning.HeuristicSearchPlanner())
#myMidca.append_module("Plan", planning.PyHopPlanner(nbeacons_util.pyhop_state_from_world,
#                                                    nbeacons_util.pyhop_tasks_from_goals,
#                                                    DECLARE_METHODS_FUNC,
#                                                    DECLARE_OPERATORS_FUNC)) # set up planner for sample domain
Beispiel #2
0
    def create_meta_MIDCA(self):

        #STATE_FILE = DOMAIN_ROOT + "states/.sim" # state file is generated dynamically
        DISPLAY_FUNC = nbeacons_util.drawNBeaconsScene
        DECLARE_METHODS_FUNC = methods_nbeacons.declare_methods
        DECLARE_OPERATORS_FUNC = operators_nbeacons.declare_operators
        GOAL_GRAPH_CMP_FUNC = nbeacons_util.preferFree

        WIND_ENABLED = True

        # Load domain
        world = domainread.load_domain(DOMAIN_FILE)

        # Load state
        stateread.apply_state_str(world, self.start_state)

        # Creates a PhaseManager object, which wraps a MIDCA object
        myMidca = base.PhaseManager(world,
                                    display=DISPLAY_FUNC,
                                    verbose=2,
                                    metaEnabled=True)

        # Add phases by name
        for phase in [
                "Simulate", "Perceive", "Interpret1", "Interpret2",
                "Interpret3", "Eval", "Cleanup", "Intend", "Plan", "Act"
        ]:
            myMidca.append_phase(phase)

        # Add the modules which instantiate basic operation
        #myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
        myMidca.append_module(
            "Simulate",
            simulator.NBeaconsActionSimulator(wind=WIND_ENABLED,
                                              wind_dir=self.wind_dir,
                                              wind_strength=self.wind_strength,
                                              dim=DIMENSION,
                                              wind_schedule=WIND_SCHEDULE_1,
                                              logfilenm=DATADIR + "meta" +
                                              NOW_STR + ".log"))

        myMidca.append_module("Simulate",
                              simulator.ASCIIWorldViewer(DISPLAY_FUNC))
        myMidca.append_module("Perceive", perceive.PerfectObserver())

        myMidca.append_module("Interpret1", note.StateDiscrepancyDetector())
        myMidca.append_module("Interpret2", assess.SimpleNBeaconsExplain())
        myMidca.append_module("Interpret3", guide.SimpleNBeaconsGoalManager())
        #myMidca.append_module("Interpret", assess.SimpleNBeaconsExplain())
        #myMidca.append_module("Interpret", assess.SimpleNBeaconsExplain())

        #myMidca.append_module("Interpret", guide.UserGoalInput())
        myMidca.append_module(
            "Interpret3",
            guide.NBeaconsGoalGenerator(numbeacons=2, goalList=self.goal_list))
        myMidca.append_module("Eval", evaluate.NBeaconsDataRecorder())
        myMidca.append_module(
            "Cleanup",
            simulator.NBeaconsSimulator(beacon_fail_rate=BEACON_FAIL_RATE))
        myMidca.append_module("Intend", intend.SimpleIntend())
        myMidca.append_module("Plan", planning.HeuristicSearchPlanner())
        #myMidca.append_module("Plan", planning.PyHopPlanner(nbeacons_util.pyhop_state_from_world,
        #                                                    nbeacons_util.pyhop_tasks_from_goals,
        #                                                    DECLARE_METHODS_FUNC,
        #                                                    DECLARE_OPERATORS_FUNC)) # set up planner for sample domain
        myMidca.append_module("Act", act.NBeaconsSimpleAct())

        for phase in ["Monitor", "Interpret", "Intend", "Plan", "Control"]:
            myMidca.append_meta_phase(phase)

        # add meta layer modules
        myMidca.append_meta_module("Monitor", monitor.MRSimpleMonitor())
        myMidca.append_meta_module("Interpret", interpret.MRSimpleDetect())
        #myMidca.append_meta_module("Interpret", interpret.MRSimpleGoalGenForGoalTrans())
        myMidca.append_meta_module("Intend", metaintend.MRSimpleIntend())
        myMidca.append_meta_module("Plan", plan.MRSimplePlanner())
        myMidca.append_meta_module("Control", control.MRSimpleControl())

        # Set world viewer to output text
        myMidca.set_display_function(nbeacons_util.drawNBeaconsScene)

        # Tells the PhaseManager to copy and store MIDCA states so they can be accessed later.
        # Note: Turning this on drastically increases MIDCA's running time.
        myMidca.storeHistory = False
        myMidca.mem.logEachAccess = False

        # Initialize and start running!

        myMidca.initGoalGraph(cmpFunc=GOAL_GRAPH_CMP_FUNC)
        return myMidca