当前位置: 首页>>代码示例>>Python>>正文


Python world.World类代码示例

本文整理汇总了Python中salma.model.world.World的典型用法代码示例。如果您正苦于以下问题:Python World类的具体用法?Python World怎么用?Python World使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了World类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     print("setup")
     World.create_new_world()
     world = World.instance()
     world.add_additional_expression_context_global("random", random)
     world.load_declarations()
     world.deactivate_all_events()
开发者ID:salmatoolkit,项目名称:salma,代码行数:7,代码来源:event_scheduling_test.py

示例2: setUp

 def setUp(self):
     print("setup")
     World.create_new_world(erase_properties=True)
     world = World.instance()
     world.load_declarations()
     world.set_constant_value("gravity", [], 9.81)
     world.register_clp_function("robotLeftFrom")
     self.configure_events_default()
开发者ID:salmatoolkit,项目名称:salma,代码行数:8,代码来源:world_test_base.py

示例3: steplogger

def steplogger(world: World, **kwargs):
    print("Step: {} - T = {} - pos: ({}, {}) - v: ({}, {})".format(
        kwargs["step"],
        world.getTime(),
        world.get_fluent_value("xpos", ["rob1"]),
        world.get_fluent_value("ypos", ["rob1"]),
        world.get_fluent_value("vx", ["rob1"]),
        world.get_fluent_value("vy", ["rob1"])))
    return True, None
开发者ID:salmatoolkit,项目名称:salma,代码行数:9,代码来源:event_scheduling_test.py

示例4: setUpClass

 def setUpClass(cls):
     try:
         World.set_logic_engine(EclipseCLPEngine("../test/ASCENS_robotic_scenario/ASCENS_robotic_domain.ecl",
                                               "../test/ASCENS_robotic_scenario/ASCENS_robotic_scenario_01.ecl"))
     except SALMAException as e:
         print(e)
         raise
     RoboticScenario.logger = logging.getLogger('salma')
     RoboticScenario.logger.setLevel(logging.INFO)
     ch = logging.StreamHandler()
     RoboticScenario.logger.addHandler(ch)
开发者ID:salmatoolkit,项目名称:salma,代码行数:11,代码来源:ASCENS_robotic_scenario1.py

示例5: initialize

    def initialize(self):
        if self.world is None:
            World.create_new_world(erase_properties=False)
            self.__world = World.instance()
            self.world.load_declarations()
            self.augment_world_context()

        self.create_entities()
        self.world.initialize()
        self.setup_distributions()
        self.create_initial_situation()
开发者ID:salmatoolkit,项目名称:salma,代码行数:11,代码来源:experiment.py

示例6: setUpClass

    def setUpClass(cls):

        try:
            World.set_logic_engine(EclipseCLPEngine("ecl-test/robot-simple/robot.simple-domaindesc.ecl"))
        except SALMAException as e:
            print(e)
            raise
        logger = logging.getLogger('salmalab')
        logger.setLevel(logging.DEBUG)
        ch = logging.StreamHandler()
        logger.addHandler(ch)
开发者ID:salmatoolkit,项目名称:salma,代码行数:11,代码来源:robot-simple-test.py

示例7: setUpClass

    def setUpClass(cls):

        try:
            World.set_logic_engine(
                EclipseCLPEngine("ecl-test/info-transfer-test/domaindesc_info_transfer_test.ecl"))
        except SALMAException as e:
            print(e)
            raise
        logger = logging.getLogger('salmalab')
        logger.setLevel(logging.DEBUG)
        ch = logging.StreamHandler()
        logger.addHandler(ch)
开发者ID:salmatoolkit,项目名称:salma,代码行数:12,代码来源:info_transfer_test.py

示例8: setUpClass

 def setUpClass(cls):
     try:
         World.set_logic_engine(
             EclipseCLPEngine("ecl-test/event_scheduling/domaindesc_event_scheduling.ecl"))
     except SALMAException as e:
         print(e)
         raise
     logger = logging.getLogger('salmalab')
     logger.setLevel(logging.DEBUG)
     ch = logging.StreamHandler()
     logger.addHandler(ch)
     logger2 = logging.getLogger('salma.model')
     logger2.setLevel(logging.DEBUG)
     logger2.addHandler(ch)
开发者ID:salmatoolkit,项目名称:salma,代码行数:14,代码来源:event_scheduling_test.py

示例9: testTwoAgentsRunUntilMaxXPos

    def testTwoAgentsRunUntilMaxXPos(self):
        world = World.instance()

        w = While(EvaluationContext.TRANSIENT_FLUENT, "robotLeftFrom", [Entity.SELF, 120],
                  Act("move_right", [Entity.SELF]))

        proc = Procedure("main", [], w)

        agent1 = Agent("rob1", "robot", proc)

        agent2 = Agent("rob2", "robot", proc)

        world.addAgent(agent1)
        world.addAgent(agent2)
        world.initialize(False)

        world.set_fluent_value("xpos", ["rob1"], 10)
        world.set_fluent_value("ypos", ["rob1"], 10)

        world.set_fluent_value("xpos", ["rob2"], 20)
        world.set_fluent_value("ypos", ["rob2"], 20)

        self.setNoOneCarriesAnything()
        verdict, info = world.runUntilFinished()
        print("Verdict: {}  after {} steps".format(verdict, info['steps']))
        print("----")
        world.printState()
        print("----\n\n")

        self.assertEqual(verdict, constants.OK)
        # there should be 110 steps to take rob1 to 120 and 2 extra steps
        self.assertEqual(info['steps'], 112)
        self.assertEqual(world.get_fluent_value("xpos", ["rob1"]), 120)
        self.assertEqual(world.get_fluent_value("xpos", ["rob2"]), 120)
开发者ID:salmatoolkit,项目名称:salma,代码行数:34,代码来源:worldtest.py

示例10: testCreatePLan_OK_Unique

    def testCreatePLan_OK_Unique(self):
        world = World.instance()
        world.addEntity(Entity("item1", "item"))
        world.addEntity(Entity("item2", "item"))

        controlProc = Procedure("main", [],
                                Sequence([
                                    Plan("transportToX",
                                         [("r", "robot"),
                                          ("i", "item"),
                                          17],
                                         "plan1")
                                ]))

        agent = Agent("rob1", "robot", controlProc)
        world.addAgent(agent)

        world.initialize(False)

        self.place_agents_in_column(10)

        world.runUntilFinished()
        world.printState()

        resolvedValues = agent.evaluation_context.resolve(
            Variable("r"),
            Variable("i"),
            Variable("plan"))
        print("resolvedValues:", resolvedValues)
开发者ID:salmatoolkit,项目名称:salma,代码行数:29,代码来源:worldtest.py

示例11: test_procedure_call

    def test_procedure_call(self):

        world = World.instance()
        transportToX = Procedure("transportToX",
                                 [("r1", "robot"), ("i", "item"), ("targetX", "integer")],
                                 Sequence(
                                     [
                                         Act("grab", [Variable("r1"), Variable("i")]),
                                         While(EvaluationContext.TRANSIENT_FLUENT, "robotLeftFrom",
                                               [Variable("r1"), Variable("targetX")],
                                               Act("move_right", [Variable("r1")])),
                                         Act("drop", [Variable("r1"), Variable("i")])
                                     ]
                                 ))
        registry = ProcedureRegistry()
        registry.register_procedure(transportToX)

        controlProc = Procedure("main", [],
                                Sequence([
                                    ProcedureCall("transportToX", ["rob1", "coffee", 17])
                                ]))

        agent = Agent("rob1", "robot", controlProc, registry)
        world.addAgent(agent)
        world.addEntity(Entity("coffee", "item"))
        world.initialize(False)
        self.place_agents_in_column(10)
        self.setNoOneCarriesAnything()
        world.runUntilFinished()
        world.printState()
        self.assertEqual(world.get_fluent_value('xpos', ['rob1']), 17)
开发者ID:salmatoolkit,项目名称:salma,代码行数:31,代码来源:worldtest.py

示例12: testSelectFirstWorld

    def testSelectFirstWorld(self):
        world = World.instance()

        for i in range(5):
            item = Entity("item{}".format(i), "item")
            world.addEntity(item)

        seq1 = Sequence([
            Select(EvaluationContext.TRANSIENT_FLUENT, "canPaint",
                   [Entity.SELF, ("i", "item")]),
            Act("paint", [Entity.SELF, Variable("i")])
        ])
        agent = Agent("rob1", "robot", Procedure("main", [], seq1))
        world.addAgent(agent)

        world.initialize(False)
        self.setNoOneCarriesAnything()
        items = world.getDomain('item')
        for item in items:
            world.set_fluent_value("painted", [item.id], False)

        world.runUntilFinished()
        world.printState()
        paintedItems = []
        for item in items:
            if world.get_fluent_value("painted", [item.id]):
                paintedItems.append(item)

        self.assertEqual(len(paintedItems), 1)
        self.assertEqual(paintedItems[0],
                         agent.evaluation_context.getEntity(
                             agent.evaluation_context.resolve(Variable("i", "item"))[0]
                         )
        )
开发者ID:salmatoolkit,项目名称:salma,代码行数:34,代码来源:worldtest.py

示例13: testIterate_python

    def testIterate_python(self):
        world = World.instance()
        items = []
        for i in range(5):
            item = Entity("item{}".format(i), "item")
            world.addEntity(item)
            items.append(item)

        seq1 = Sequence([
            Iterate(EvaluationContext.ITERATOR, items,
                    [("i", "item")],
                    Sequence([
                        Act("paint", [Entity.SELF, Variable("i")])
                    ])

            )
        ])

        agent = Agent("rob1", "robot", Procedure("main", [], seq1))
        world.addAgent(agent)

        world.initialize(False)
        self.setNoOneCarriesAnything()
        for item in items:
            world.set_fluent_value("painted", [item.id], False)

        world.runUntilFinished()
        world.printState()
        for item in items:
            self.assertTrue(world.get_fluent_value("painted", [item.id]))
开发者ID:salmatoolkit,项目名称:salma,代码行数:30,代码来源:worldtest.py

示例14: testSelectFirst

    def testSelectFirst(self):
        world = World.instance()
        agent1, agent2, grabMap = self.setupSelectionContext()
        res1 = agent1.evaluation_context.selectFirst(EvaluationContext.FLUENT, "carrying",
                                                     ('r', 'robot'), ('i', 'item'))
        self.assertIsNone(res1)
        world.runUntilFinished()

        res2 = agent1.evaluation_context.selectFirst(EvaluationContext.FLUENT, "carrying",
                                                     ('r', 'robot'), ('i', 'item'))

        self.assertIsInstance(res2, dict)

        handledAgents = set()

        self.assertIsInstance(
            res2['r'], Agent)
        if res2['r'].id == "rob1":
            self.assertEqual(res2['r'], agent1)
        elif res2['r'].id == "rob2":
            self.assertEqual(res2['r'], agent2)
        else:
            self.fail("Wrong agent id.")

        self.assertEqual(res2['i'], grabMap[res2['r'].id])
        handledAgents.add(res2['r'].id)

        print(res2)
开发者ID:salmatoolkit,项目名称:salma,代码行数:28,代码来源:worldtest.py

示例15: testUniformStochasticAction

    def testUniformStochasticAction(self):
        world = World.instance()

        seq = Sequence([
            Act("move_right", [Entity.SELF]),
            Assign("i", 0),
            While("i < 100", [
                Act("jump", [Entity.SELF, 42]),
                Assign("i", "i + 1")
            ])
        ])

        agent = Agent("rob1", "robot", Procedure(seq))
        world.addAgent(agent)
        world.initialize(False)

        jump_action = world.get_stochastic_action("jump")
        self.generate_outcomes(jump_action)
        jump_action.selection_strategy = NonDeterministic()

        self.initialize_robot("rob1", 10, 20, 0, 0)

        world.printState()
        self.__crash_count = 0
        self.__land_on_count = 0
        experiment = Experiment(world)
        experiment.step_listeners.append(self.record_outcomes)
        experiment.run_until_finished()
        world.printState()
        print("crash: {} - land on: {}".format(self.__crash_count, self.__land_on_count))
        self.assertTrue(self.__crash_count > 40)
        self.assertTrue(self.__land_on_count > 40)
        self.assertEqual(self.__crash_count + self.__land_on_count, 100)
开发者ID:salmatoolkit,项目名称:salma,代码行数:33,代码来源:basic_simulation_test.py


注:本文中的salma.model.world.World类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。