本文整理汇总了Python中multiagent.scenarios.load方法的典型用法代码示例。如果您正苦于以下问题:Python scenarios.load方法的具体用法?Python scenarios.load怎么用?Python scenarios.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiagent.scenarios
的用法示例。
在下文中一共展示了scenarios.load方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_particle_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_particle_env(game_name, benchmark=False):
import multiagent.scenarios as scenarios
scenario = scenarios.load(game_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = ParticleEnv(
world,
scenario.reset_world,
scenario.reward,
scenario.observation,
scenario.benchmark_data,
)
else:
env = ParticleEnv(
world, scenario.reset_world, scenario.reward, scenario.observation
)
return env
# environment for all agents in the multiagent world
# currently code assumes that no agents will be created/destroyed at runtime!
示例2: make_particle_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_particle_env(game_name, benchmark=False):
import multiagent.scenarios as scenarios
scenario = scenarios.load(game_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = ParticleEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data)
else:
env = ParticleEnv(world, scenario.reset_world, scenario.reward, scenario.observation)
return env
# environment for all agents in the multiagent world
# currently code assumes that no agents will be created/destroyed at runtime!
示例3: parse_args
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def parse_args():
parser = argparse.ArgumentParser("Reinforcement Learning experiments for multiagent environments")
# Environment
parser.add_argument("--scenario", type=str, default="simple", help="name of the scenario script")
parser.add_argument("--max-episode-len", type=int, default=25, help="maximum episode length")
parser.add_argument("--num-episodes", type=int, default=60000, help="number of episodes")
parser.add_argument("--num-adversaries", type=int, default=0, help="number of adversaries")
parser.add_argument("--good-policy", type=str, default="maddpg", help="policy for good agents")
parser.add_argument("--bad-policy", type=str, default="maddpg", help="policy of adversaries")
# Core training parameters
parser.add_argument("--lr", type=float, default=1e-2, help="learning rate for Adam optimizer")
parser.add_argument("--gamma", type=float, default=0.95, help="discount factor")
parser.add_argument("--batch-size", type=int, default=1024, help="number of episodes to optimize at the same time")
parser.add_argument("--num-units", type=int, default=64, help="number of units in the mlp")
parser.add_argument("--adv-eps", type=float, default=1e-3, help="adversarial training rate")
parser.add_argument("--adv-eps-s", type=float, default=1e-5, help="small adversarial training rate")
# Checkpointing
parser.add_argument("--exp-name", type=str, default=None, help="name of the experiment")
parser.add_argument("--save-dir", type=str, default="/tmp/policy/", help="directory in which training state and model should be saved")
parser.add_argument("--save-rate", type=int, default=1000, help="save model once every time this many episodes are completed")
parser.add_argument("--load-name", type=str, default="", help="name of which training state and model are loaded, leave blank to load seperately")
parser.add_argument("--load-good", type=str, default="", help="which good policy to load")
parser.add_argument("--load-bad", type=str, default="", help="which bad policy to load")
# Evaluation
parser.add_argument("--test", action="store_true", default=False)
parser.add_argument("--restore", action="store_true", default=False)
parser.add_argument("--display", action="store_true", default=False)
parser.add_argument("--benchmark", action="store_true", default=False)
parser.add_argument("--benchmark-iters", type=int, default=100000, help="number of iterations run for benchmarking")
parser.add_argument("--benchmark-dir", type=str, default="./benchmark_files/", help="directory where benchmark data is saved")
parser.add_argument("--plots-dir", type=str, default="./learning_curves/", help="directory where plot data is saved")
return parser.parse_args()
示例4: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, arglist, benchmark=False):
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as scenarios
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation)
return env
示例5: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, benchmark=False):
'''
Creates a MultiAgentEnv object as env. This can be used similar to a gym
environment by calling env.reset() and env.step().
Use env.render() to view the environment on the screen.
Input:
scenario_name : name of the scenario from ./scenarios/ to be Returns
(without the .py extension)
benchmark : whether you want to produce benchmarking data
(usually only done during evaluation)
Some useful env properties (see environment.py):
.observation_space : Returns the observation space for each agent
.action_space : Returns the action space for each agent
.n : Returns the number of Agents
'''
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as scenarios
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation)
return env
示例6: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, benchmark=False):
'''
Creates a MultiAgentEnv object as env. This can be used similar to a gym
environment by calling env.reset() and env.step().
Use env.render() to view the environment on the screen.
Input:
scenario_name : name of the scenario from ./scenarios/ to be Returns
(without the .py extension)
benchmark : whether you want to produce benchmarking data
(usually only done during evaluation)
Some useful env properties (see environment.py):
.observation_space : Returns the observation space for each agent
.action_space : Returns the action space for each agent
.n : Returns the number of Agents
'''
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as scenarios
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation,
done_callback=scenario.done)
return env
示例7: parse_args
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def parse_args():
parser = argparse.ArgumentParser("Reinforcement Learning experiments for multiagent environments")
# Environment
parser.add_argument("--scenario", type=str, default="simple", help="name of the scenario script")
parser.add_argument("--max-episode-len", type=int, default=25, help="maximum episode length")
parser.add_argument("--num-episodes", type=int, default=60000, help="number of episodes")
parser.add_argument("--num-adversaries", type=int, default=0, help="number of adversaries")
parser.add_argument("--good-policy", type=str, default="maddpg", help="policy for good agents")
parser.add_argument("--adv-policy", type=str, default="maddpg", help="policy of adversaries")
# Core training parameters
parser.add_argument("--lr", type=float, default=1e-2, help="learning rate for Adam optimizer")
parser.add_argument("--gamma", type=float, default=0.95, help="discount factor")
parser.add_argument("--batch-size", type=int, default=1024, help="number of episodes to optimize at the same time")
parser.add_argument("--num-units", type=int, default=64, help="number of units in the mlp")
# Checkpointing
parser.add_argument("--exp-name", type=str, default=None, help="name of the experiment")
parser.add_argument("--save-dir", type=str, default="/tmp/policy/", help="directory in which training state and model should be saved")
parser.add_argument("--save-rate", type=int, default=1000, help="save model once every time this many episodes are completed")
parser.add_argument("--load-dir", type=str, default="", help="directory in which training state and model are loaded")
# Evaluation
parser.add_argument("--restore", action="store_true", default=False)
parser.add_argument("--display", action="store_true", default=False)
parser.add_argument("--benchmark", action="store_true", default=False)
parser.add_argument("--benchmark-iters", type=int, default=100000, help="number of iterations run for benchmarking")
parser.add_argument("--benchmark-dir", type=str, default="./benchmark_files/", help="directory where benchmark data is saved")
parser.add_argument("--plots-dir", type=str, default="./learning_curves/", help="directory where plot data is saved")
return parser.parse_args()
示例8: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, benchmark=False):
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation)
return env
示例9: make_multiagent_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_multiagent_env(env_id, num_agents, dist_threshold, arena_size, identity_size):
scenario = scenarios.load(env_id+".py").Scenario(num_agents=num_agents, dist_threshold=dist_threshold,
arena_size=arena_size, identity_size=identity_size)
world = scenario.make_world()
env = MultiAgentEnv(world=world,
reset_callback=scenario.reset_world,
reward_callback=scenario.reward,
observation_callback=scenario.observation,
info_callback=scenario.info if hasattr(scenario, 'info') else None,
discrete_action=True,
done_callback=scenario.done,
cam_range=arena_size
)
return env
示例10: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, benchmark=False):
'''
Creates a MultiAgentEnv object as env. This can be used similar to a gym
environment by calling env.reset() and env.step().
Use env.render() to view the environment on the screen.
Input:
scenario_name : name of the scenario from ./scenarios/ to be Returns
(without the .py extension)
benchmark : whether you want to produce benchmarking data
(usually only done during evaluation)
Some useful env properties (see environment.py):
.observation_space : Returns the observation space for each agent
.action_space : Returns the action space for each agent
.n : Returns the number of Agents
'''
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as scenarios
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, scenario.benchmark_data, done_callback = scenario.done)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward, scenario.observation, done_callback = scenario.done)
return env
示例11: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, benchmark=False, discrete_action=False):
'''
Creates a MultiAgentEnv object as env. This can be used similar to a gym
environment by calling env.reset() and env.step().
Use env.render() to view the environment on the screen.
Input:
scenario_name : name of the scenario from ./scenarios/ to be Returns
(without the .py extension)
benchmark : whether you want to produce benchmarking data
(usually only done during evaluation)
Some useful env properties (see environment.py):
.observation_space : Returns the observation space for each agent
.action_space : Returns the action space for each agent
.n : Returns the number of Agents
'''
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as scenarios
# load scenario from script
scenario = scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if benchmark:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward,
scenario.observation, scenario.benchmark_data,
discrete_action=discrete_action)
else:
env = MultiAgentEnv(world, scenario.reset_world, scenario.reward,
scenario.observation,
discrete_action=discrete_action)
return env
示例12: make_env
# 需要导入模块: from multiagent import scenarios [as 别名]
# 或者: from multiagent.scenarios import load [as 别名]
def make_env(scenario_name, benchmark=False, discrete_action=False):
'''
Creates a MultiAgentEnv object as env. This can be used similar to a gym
environment by calling env.reset() and env.step().
Use env.render() to view the environment on the screen.
Input:
scenario_name : name of the scenario from ./scenarios/ to be Returns
(without the .py extension)
benchmark : whether you want to produce benchmarking data
(usually only done during evaluation)
Some useful env properties (see environment.py):
.observation_space : Returns the observation space for each agent
.action_space : Returns the action space for each agent
.n : Returns the number of Agents
'''
from multiagent.environment import MultiAgentEnv
import multiagent.scenarios as old_scenarios
import envs.mpe_scenarios as new_scenarios
# load scenario from script
try:
scenario = old_scenarios.load(scenario_name + ".py").Scenario()
except:
scenario = new_scenarios.load(scenario_name + ".py").Scenario()
# create world
world = scenario.make_world()
# create multiagent environment
if hasattr(scenario, 'post_step'):
post_step = scenario.post_step
else:
post_step = None
if benchmark:
env = MultiAgentEnv(world, reset_callback=scenario.reset_world,
reward_callback=scenario.reward,
observation_callback=scenario.observation,
post_step_callback=post_step,
info_callback=scenario.benchmark_data,
discrete_action=discrete_action)
else:
env = MultiAgentEnv(world, reset_callback=scenario.reset_world,
reward_callback=scenario.reward,
observation_callback=scenario.observation,
post_step_callback=post_step,
discrete_action=discrete_action)
return env