Exemple #1
0
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
Exemple #2
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
Exemple #3
0
#creates a PhaseManager object, which wraps a MIDCA object
myMidca = base.PhaseManager(world, display = DISPLAY_FUNC, 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(display=DISPLAY_FUNC))
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(util.pyhop_state_from_world,
                                                    util.pyhop_tasks_from_goals,
                                                    DECLARE_METHODS_FUNC,
                                                    DECLARE_OPERATORS_FUNC))
myMidca.append_module("Act", act.SimpleAct())

myMidca.insert_module('Simulate', simulator.ArsonSimulator(arsonChance = 0.9, arsonStart = 10), 1)
myMidca.insert_module('Simulate', simulator.FireReset(), 0)
myMidca.insert_module('Interpret', guide.TFStack(), 1)
myMidca.insert_module('Interpret', guide.TFFire(), 2)
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


#tells the PhaseManager to copy and store MIDCA states so they can be accessed later.
myMidca.storeHistory = True
myMidca.initGoalGraph(cmpFunc = GOAL_GRAPH_CMP_FUNC)
myMidca.init()
Exemple #4
0
]:
    myMidca.append_phase(phase)

    #add the modules which instantiate basic blocksworld operation
myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
myMidca.append_module("Simulate",
                      simulator.ASCIIWorldViewer(display=DISPLAY_FUNC))
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(util.mortar_pyhop_state_from_world,
                          util.mortar_pyhop_tasks_from_goals,
                          DECLARE_METHODS_FUNC, DECLARE_OPERATORS_FUNC,
                          extinguish, mortar))
myMidca.append_module("Act", act.SimpleAct())
#myMidca.insert_module('Simulate', simulator.ArsonSimulator(arsonChance = 0.0, arsonStart = 10), 1)
#myMidca.insert_module('Simulate', simulator.FireReset(), 0)
myMidca.insert_module('Interpret', guide.SimpleMortarGoalGen(), 1)
#myMidca.insert_module('Interpret', guide.TFFire(), 2)
myMidca.insert_module('Interpret', guide.ReactiveApprehend(), 3)
myMidca.insert_module(
    'Eval', evaluate.MortarScorer(),
    1)  # this needs to be a 1 so that Scorer happens AFTER SimpleEval

# 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)
world = domainread.load_domain(DOMAIN_FILE)
stateread.apply_state_file(world, STATE_FILE)
#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", "Intend", "Plan", "Act"
]:
    myMidca.append_phase(phase)

myMidca.append_module("Simulate", simulator.MidcaActionSimulator())
myMidca.append_module("Simulate",
                      simulator.ASCIIWorldViewer(display=DISPLAY_FUNC))
myMidca.append_module("Perceive", perceive.PerfectObserver())  ## add in SRL
myMidca.append_module("Interpret", note.ADistanceAnomalyNoter())

#UserGoalInput getUserInstruction  world, mem, verbose
myMidca.append_module("Interpret", guide.GoalInference(world))
# 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.GoalInferenceAct(world))

print(myMidca.get_phases())
#tells the PhaseManager to copy and store MIDCA states so they can be accessed later.
myMidca.storeHistory = True
myMidca.init()
myMidca.run()
        "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(util.pyhop_state_from_world,
                          util.pyhop_tasks_from_goals, DECLARE_METHODS_FUNC,
                          DECLARE_OPERATORS_FUNC))

myMidca.append_module("Act", act.SimpleAct())

myMidca.insert_module('Simulate',
                      simulator.ArsonSimulator(arsonChance=0.3, arsonStart=2),
                      1)
myMidca.insert_module('Interpret', guide.TFStack(), 1)
myMidca.insert_module('Interpret', guide.TFFire(), 2)

#tells the PhaseManager to copy and store MIDCA states so they can be accessed later. Note: this drastically increases MIDCA's running time.
myMidca.storeHistory = True
myMidca.initGoalGraph(cmpFunc=GOAL_GRAPH_CMP_FUNC)
myMidca.init()
myMidca.run()
Exemple #7
0
    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
Exemple #8
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