本文整理汇总了Python中salma.model.world.World类的典型用法代码示例。如果您正苦于以下问题:Python World类的具体用法?Python World怎么用?Python World使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了World类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testScenario
def testScenario(self):
world = World.instance()
# rob1 = Robot("rob1", 200, 200, 2, math.radians(45))
# rob2 = Robot("rob2", 50, 50, 2, math.radians(270))
# rob3 = Robot("rob3", 400, 50, 2, math.radians(0))
#
# world.addAgent(rob1)
# world.addAgent(rob2)
# world.addAgent(rob3)
self.initBasicScenario(5, randomize=True, lightSources=[(450, 450), (50, 400), (50, 50)])
self.__datalog = []
world.printState()
fileName = "robotic_scenario_positions_{}.csv".format(
datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
self.dataFile = io.FileIO(fileName, mode="w")
self.dataBuffer = io.BufferedWriter(self.dataFile, buffer_size=4 * io.DEFAULT_BUFFER_SIZE)
res = world.runUntilFinished(maxRealTime=datetime.timedelta(minutes=2),
stepListeners=[self.reportPositions])
self.dataFile.flush()
self.dataFile.close()
print(res)
开发者ID:salmatoolkit,项目名称:salma,代码行数:25,代码来源:ASCENS_robotic_scenario1.py
示例17: test_run_right_until_max_X_pos
def test_run_right_until_max_X_pos(self):
world = World.instance()
w = While("robotLeftFrom",
[Entity.SELF, 100, "s0"],
[
Act("move_right", [Entity.SELF]),
Wait("not moving(self)")
])
agent = Agent("rob1", "robot", Procedure(w))
world.addAgent(agent)
world.initialize(False)
self.initialize_robot("rob1", 10, 10, 0, 0)
world.printState()
experiment = Experiment(world)
verdict, info = experiment.run_until_finished()
print("Verdict: {} after {} steps".format(verdict, info['steps']))
print("----")
world.printState()
print("----\n\n")
self.assertEqual(world.get_fluent_value("xpos", ["rob1"]), 100)
self.assertEqual(verdict, constants.OK)
self.assertTrue(450 <= world.getTime() <= 452)
self.assertTrue(world.is_finished())
print(info)
开发者ID:salmatoolkit,项目名称:salma,代码行数:29,代码来源:basic_simulation_test.py
示例18: test_event_instance_scheduled_only_once
def test_event_instance_scheduled_only_once(self):
world = World.instance()
rob1 = self.create_random_walk_robot("rob1")
rob2 = self.create_random_walk_robot("rob2")
world.add(rob1, rob2)
world.initialize(False)
world.deactivate_info_transfer()
world.world_width = 500
world.world_height = 500
world.safety_distance = 10
self.init_robot(rob1, 250, 250, 0, 0)
self.init_robot(rob2, 300, 250, 0, 0)
welcome = world.get_exogenous_action("welcome_message")
welcome.config.occurrence_distribution = GeometricDistribution(0.1)
welcome.config.uniform_param("code", (0, 10))
e1 = Experiment(world)
reclist = []
def recorder(w, **kwargs):
reclist.append(kwargs)
e1.step_listeners.append(recorder)
e1.run(max_world_time=100)
print(reclist)
开发者ID:salmatoolkit,项目名称:salma,代码行数:29,代码来源:event_scheduling_test.py
示例19: test_custom_distrib_lambda
def test_custom_distrib_lambda(self):
world = World.instance()
rob1 = self.create_random_walk_robot("rob1")
rob2 = self.create_random_walk_robot("rob2")
world.add(rob1, rob2)
world.initialize(False)
world.deactivate_info_transfer()
world.world_width = 500
world.world_height = 500
world.safety_distance = 10
self.init_robot(rob1, 250, 250, 1, 2)
self.init_robot(rob2, 255, 250, 3, 4)
collision = world.get_exogenous_action("collide")
collision.config.occurrence_distribution = BernoulliDistribution(1.0)
sev = lambda r1, r2: 1000 * r1.vx + 100 * r1.vy + 10 * r2.vx + r2.vy
collision.config.set_param_distribution("severity", CustomDistribution("integer", sev))
e1 = Experiment(world)
reclist = []
def recorder(w, **kwargs):
reclist.append(kwargs)
e1.step_listeners.append(recorder)
e1.run(max_world_time=0)
print(reclist)
开发者ID:salmatoolkit,项目名称:salma,代码行数:31,代码来源:event_scheduling_test.py
示例20: test_variable_assignment
def test_variable_assignment(self):
world = World.instance()
# run from (x,y) to (y,y)
seq = Sequence([
Assign("myY", "ypos", [Entity.SELF]),
FunctionStatement(print_value, [Variable("myY")])
])
w = While("robotLeftFrom",
[Entity.SELF, Variable("myY"), "s0"],
[
Act("move_right", [Entity.SELF]),
Wait("not moving(self)"),
Assign("myX", "xpos", [Entity.SELF]),
FunctionStatement(print_value, [Variable("myX")])
])
seq.add_child(w)
proc1 = OneShotProcess(Procedure(seq))
rob1 = Agent("rob1", "robot", [proc1])
world.addAgent(rob1)
world.initialize(False)
self.initialize_robot("rob1", 10, 20, 0, 0)
experiment = Experiment(world)
experiment.run_until_finished()
self.assertEqual(proc1.current_evaluation_context.resolve(Variable('myY'))[0], 20)
self.assertEqual(proc1.current_evaluation_context.resolve(Variable('myX'))[0], 20)
开发者ID:salmatoolkit,项目名称:salma,代码行数:28,代码来源:basic_simulation_test.py
注:本文中的salma.model.world.World类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论