コード例 #1
0
def UserGoalsMidca(domainFile, stateFile, goalsFile = None, extinguish = False):
    world = domainread.load_domain(domainFile)
    stateread.apply_state_file(world, stateFile)
    myMidca = base.PhaseManager(world, verbose=1, display = asqiiDisplay, metaEnabled=True)

    # add cognitive layer phases
    for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
        myMidca.append_phase(phase)

    # add cognitive layer modules
    myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
    myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
    myMidca.append_module("Perceive", perceive.PerfectObserver())
    myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
    myMidca.append_module("Interpret", guide.UserGoalInput())
    myMidca.append_module("Eval", evaluate.SimpleEval())
    myMidca.append_module("Intend", intend.SimpleIntend())
    myMidca.append_module("Plan", planningbroken.PyHopPlannerBroken(extinguish))
    myMidca.append_module("Act", act.SimpleAct())

    # add meta layer phases
    #for phase in ["Monitor", "Interpret", "Eval", "Intend", "Plan", "Control"]:
    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.MRSimpleGoalGen())
    myMidca.append_meta_module("Intend", metaintend.MRSimpleIntend())
    myMidca.append_meta_module("Plan", plan.MRSimplePlanner())
    myMidca.append_meta_module("Control", control.MRSimpleControl())

    return myMidca
コード例 #2
0
ファイル: predicateworld.py プロジェクト: whitten/MIDCA
def UserGoalsMidca(domainFile,
                   stateFile,
                   display=print,
                   goalsFile=None,
                   argsPyHopPlanner=[]):
    world = domainread.load_domain(domainFile)
    stateread.apply_state_file(world, stateFile)
    #creates a PhaseManager object, which wraps a MIDCA object
    myMidca = base.PhaseManager(world, display=display, verbose=4)
    #add phases by name
    for phase in [
            "Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan",
            "Act"
    ]:
        myMidca.append_phase(phase)

        #add the modules which instantiate basic blocksworld operation
    myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
    myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
    myMidca.append_module("Perceive", perceive.PerfectObserver())
    myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
    #myMidca.append_module("Interpret", guide.UserGoalInput())
    myMidca.append_module("Eval", evaluate.SimpleEval())
    myMidca.append_module("Intend", intend.SimpleIntend())
    myMidca.append_module("Plan", planning.PyHopPlanner(*argsPyHopPlanner))
    myMidca.append_module("Act", act.SimpleAct())
    return myMidca
コード例 #3
0
def UserGoalsMidca(domainFile, stateFile, goalsFile=None, extinguish=False):
    world = domainread.load_domain(domainFile)
    stateread.apply_state_file(world, stateFile)
    myMidca = base.PhaseManager(world, verbose=1, display=asqiiDisplay, metaEnabled=True)

    # add cognitive layer phases
    for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
        myMidca.append_phase(phase)

    # add cognitive layer modules
    myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
    myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
    myMidca.append_module("Perceive", perceive.PerfectObserver())
    myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
    myMidca.append_module("Interpret", guide.UserGoalInput())
    myMidca.append_module("Eval", evaluate.SimpleEval())
    myMidca.append_module("Intend", intend.SimpleIntend())
    myMidca.append_module("Plan", planningbroken.PyHopPlannerBroken(extinguish))
    myMidca.append_module("Act", act.SimpleAct())

    # add meta layer phases
    # for phase in ["Monitor", "Interpret", "Eval", "Intend", "Plan", "Control"]:
    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.MRSimpleGoalGen())
    myMidca.append_meta_module("Intend", metaintend.MRSimpleIntend())
    myMidca.append_meta_module("Plan", plan.MRSimplePlanner())
    myMidca.append_meta_module("Control", control.MRSimpleControl())

    return myMidca
コード例 #4
0
ファイル: mortar_experiment_1.py プロジェクト: whitten/MIDCA
    def createMIDCAObj(self):
        extinguish = False
        mortar = True

        thisDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))

        MIDCA_ROOT = thisDir + "/../"

        domainFile = MIDCA_ROOT + "worldsim/domains/arsonist_mortar.sim"
        stateFile = MIDCA_ROOT + "worldsim/states/defstate_mortar.sim"

        # load domain file like normal
        self.world = domainread.load_domain(domainFile)
        
        # for state file, need to add number of mortar blocks to begin with
        state_str = open(stateFile).read() # first read file
        # now add new mortar blocks
        for i in range(self.currMortarCount):
            state_str+="MORTARBLOCK(M"+str(i)+")\n"
            state_str+="available(M"+str(i)+")\n"
        # now load the state    
        stateread.apply_state_str(self.world, state_str)
        # creates a PhaseManager object, which wraps a MIDCA object
        myMidca = base.PhaseManager(self.world, display=asqiiDisplay,verbose=0)
        #asqiiDisplay(world)
        # add phases by name
        for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
            myMidca.append_phase(phase)

        # add the modules which instantiate basic blocksworld operation
        myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
        myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
        myMidca.append_module("Perceive", perceive.PerfectObserver())
        myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
        # need to make sure to disable all user input modules #myMidca.append_module("Interpret", guide.UserGoalInput())
        myMidca.append_module("Eval", evaluate.SimpleEval())
        myMidca.append_module("Intend", intend.SimpleIntend())
        myMidca.append_module("Plan", planning.PyHopPlanner(extinguish, mortar))
        myMidca.append_module("Act", act.SimpleAct())

        #myMidca.insert_module('Simulate', simulator.ArsonSimulator(arsonChance=self.arsonChanceArg, arsonStart=10), 1)
        #myMidca.insert_module('Simulate', simulator.FireReset(), 0)
        myMidca.insert_module('Interpret', guide.TFStack(), 1)

        myMidca.insert_module('Eval', evaluate.MortarScorer(), 1)  # this needs to be a 1 so that Scorer happens AFTER SimpleEval
        # tells the PhaseManager to copy and store MIDCA states so they can be accessed later.
        myMidca.storeHistory = False
        myMidca.initGoalGraph()
        ## note: myMidca.init() is NOT called here, instead in singlerun()

        self.myMidca = myMidca
        self.initialized = True
コード例 #5
0
ファイル: predicateworld_test.py プロジェクト: dtdannen/MIDCA
def guiMidca(domainFile, stateFile, goalsFile = None):
	world = domainread.load_domain(domainFile)
	stateread.apply_state_file(world, stateFile)
	myMidca = base.PhaseManager(world, display = asqiiDisplay)
	for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
		myMidca.append_phase(phase)

	myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
	myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
	myMidca.append_module("Perceive", perceive.PerfectObserver())
	myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
	myMidca.append_module("Eval", evaluate.SimpleEval())
	myMidca.append_module("Intend", intend.SimpleIntend())
	myMidca.append_module("Plan", planning.PyHopPlanner())
	myMidca.append_module("Act", act.SimpleAct())
	return myMidca
コード例 #6
0
def guiMidca(domainFile, stateFile, goalsFile = None):
    world = domainread.load_domain(domainFile)
    stateread.apply_state_file(world, stateFile)
    myMidca = base.PhaseManager(world, display = asqiiDisplay)
    for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
        myMidca.append_phase(phase)

    myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
    myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
    myMidca.append_module("Perceive", perceive.PerfectObserver())
    myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
    myMidca.append_module("Eval", evaluate.SimpleEval())
    myMidca.append_module("Intend", intend.SimpleIntend())
    myMidca.append_module("Plan", planning.PyHopPlanner())
    myMidca.append_module("Act", act.SimpleAct())
    return myMidca
コード例 #7
0
ファイル: predicateworld.py プロジェクト: dtdannen/MIDCA
def UserGoalsMidca(domainFile, stateFile, goalsFile = None, extinguish = False):
    world = domainread.load_domain(domainFile)
    stateread.apply_state_file(world, stateFile)
        #creates a PhaseManager object, which wraps a MIDCA object
    myMidca = base.PhaseManager(world, display = asqiiDisplay)
        #add phases by name
    for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
        myMidca.append_phase(phase)

        #add the modules which instantiate basic blocksworld operation
    myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
    myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
    myMidca.append_module("Perceive", perceive.PerfectObserver())
    myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
    myMidca.append_module("Interpret", guide.UserGoalInput())
    myMidca.append_module("Eval", evaluate.SimpleEval())
    myMidca.append_module("Intend", intend.SimpleIntend())
    myMidca.append_module("Plan", planning.PyHopPlanner(extinguish))
    myMidca.append_module("Act", act.SimpleAct())
    return myMidca
コード例 #8
0
DOMAIN_FILE = DOMAIN_ROOT + "domains/nbeacons.sim"
#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 = None

DIMENSION = 16  # width and height of grid
BEACON_FAIL_RATE = 20  # percent chance each beacon will fail each tick
WIND_ENABLED = True
WIND_DIR = 'east'  # direction to push the agent if it moves in this direction
WIND_STRENGTH = 0  # number of extra tiles for the agent to move
NUM_QUICKSAND = 10

# Load domain
world = domainread.load_domain(DOMAIN_FILE)

# Create Starting state
state1 = nbeacons_util.NBeaconGrid()
state1.generate(width=DIMENSION,
                height=DIMENSION,
                num_beacons=10,
                num_quicksand_spots=NUM_QUICKSAND)
state1_str = state1.get_STRIPS_str()

# Load state
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)
コード例 #9
0
    def createMIDCAObj(self):
        # in this demo, always keep extinguish to false
            extinguish = False

            thisDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))

            MIDCA_ROOT = thisDir + "/../"

            domainFile = MIDCA_ROOT + "worldsim/domains/arsonist.sim"
            stateFile = MIDCA_ROOT + "worldsim/states/defstate.sim"

            self.world = domainread.load_domain(domainFile)
            stateread.apply_state_file(self.world, stateFile)
            # creates a PhaseManager object, which wraps a MIDCA object
            myMidca = base.PhaseManager(self.world, display=asqiiDisplay,verbose=4)
            #asqiiDisplay(world)
            # add phases by name
            for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
                myMidca.append_phase(phase)

            # add the modules which instantiate basic blocksworld operation
            myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
            myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
            myMidca.append_module("Perceive", perceive.PerfectObserver())
            myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
            # need to make sure to disable all user input modules #myMidca.append_module("Interpret", guide.UserGoalInput())
            myMidca.append_module("Eval", evaluate.SimpleEval())
            myMidca.append_module("Intend", intend.SimpleIntend())
            myMidca.append_module("Plan", planning.PyHopPlanner(extinguish))
            myMidca.append_module("Act", act.SimpleAct())

            myMidca.insert_module('Simulate', simulator.ArsonSimulator(arsonChance=self.arsonChanceArg, arsonStart=10), 1)
            myMidca.insert_module('Simulate', simulator.FireReset(), 0)
            myMidca.insert_module('Interpret', guide.TFStack(), 1)

            if self.usingTFTreeFire:
                myMidca.insert_module('Interpret', guide.TFFire(), 2)

            if self.usingSimulatedMA:
                myMidca.insert_module('Interpret', guide.ReactiveApprehend(), 3)

            myMidca.insert_module('Eval', evaluate.Scorer(), 1)  # this needs to be a 1 so that Scorer happens AFTER SimpleEval

            def preferApprehend(goal1, goal2):
                if 'predicate' not in goal1 or 'predicate' not in goal2:
                    return 0
                elif goal1['predicate'] == 'free' and goal2['predicate'] != 'free':
                    return -1
                elif goal1['predicate'] != 'free' and goal2['predicate'] == 'free':
                    return 1
                elif goal1['predicate'] == 'onfire' and goal2['predicate'] != 'onfire':
                    return -1
                elif goal1['predicate'] != 'onfire' and goal2['predicate'] == 'onfire':
                    return 1
                return 0

            # tells the PhaseManager to copy and store MIDCA states so they can be accessed later.
            myMidca.storeHistory = False
            myMidca.initGoalGraph(cmpFunc=preferApprehend)
            ## DO NOT DO THIS: experiment.py will do this automatically: myMidca.init()

            print "Created MIDCA "+str(id(myMidca))+" w/ arsonchance="+str(self.arsonChanceArg)+", usingTFTreeFire="+str(self.usingTFTreeFire)+",usingSimMA="+str(self.usingSimulatedMA)

            self.myMidca = myMidca
            self.initialized = True
コード例 #10
0
ファイル: nbeacons_util.py プロジェクト: mclumd/MIDCA
        return -1
    elif goal1['predicate'] != 'free' and goal2['predicate'] == 'free':
        return 1

    return 0

    
if __name__ == "__main__":
    import os, inspect
    from MIDCA.worldsim import domainread, stateread 
    thisDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    MIDCA_ROOT = thisDir + "/../"
    #DOMAIN_ROOT = MIDCA_ROOT + "domains/nbeacons/"
    DOMAIN_ROOT = "domains/nbeacons/"
    DOMAIN_FILE = DOMAIN_ROOT + "domains/nbeacons.sim"
    
    # generate an NBeacons Scenario
    env1 = NBeaconGrid()
    env1.generate_good_test()
    
    state1_str = env1.get_STRIPS_str()
    
    world = domainread.load_domain(DOMAIN_FILE)
    
    # Load state
    stateread.apply_state_str(world, state1_str)
    
    drawNBeaconsScene(world)
    
    print(env1.get_STRIPS_str())
コード例 #11
0
ファイル: run_extinguish.py プロジェクト: whitten/MIDCA
thisDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))

MIDCA_ROOT = thisDir + "/../"

domainFile = MIDCA_ROOT + "domains/blocksworld/domains/arsonist_extinguish.sim"
stateFile = MIDCA_ROOT + "domains/blocksworld/states/extinguisher_state.sim"
extinguish = True

argsPyHopPlanner = [util.pyhop_state_from_world,
					util.pyhop_tasks_from_goals,
					DECLARE_METHODS_FUNC,
					DECLARE_OPERATORS_FUNC,
					extinguish]

world = domainread.load_domain(domainFile)
stateread.apply_state_file(world, stateFile)
#creates a PhaseManager object, which wraps a MIDCA object
myMidca = base.PhaseManager(world, display = util.asqiiDisplay, verbose=4)
#add phases by name
for phase in ["Simulate", "Perceive", "Interpret", "Eval", "Intend", "Plan", "Act"]:
	myMidca.append_phase(phase)

#add the modules which instantiate basic blocksworld operation
myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
myMidca.append_module("Simulate", simulator.ASCIIWorldViewer())
myMidca.append_module("Perceive", perceive.PerfectObserver())
myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())
#myMidca.append_module("Interpret", guide.UserGoalInput())
myMidca.append_module("Eval", evaluate.SimpleEval())
myMidca.append_module("Intend", intend.SimpleIntend())
コード例 #12
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