it is working
This commit is contained in:
@@ -65,3 +65,20 @@ class Coin(Resource):
|
||||
color = np.array([229, 211, 82]) / 255.0
|
||||
collectible = False
|
||||
|
||||
@resource_registry.add
|
||||
class GemRaw(Resource):
|
||||
"""Raw Gem that can be processed further"""
|
||||
|
||||
name = "Gem_Raw"
|
||||
color = np.array([241, 233, 219]) / 255.0
|
||||
collectible = True
|
||||
|
||||
@resource_registry.add
|
||||
class Gem(Resource):
|
||||
"""Proccesed Gem. Craftable."""
|
||||
|
||||
name = "Gem"
|
||||
color = np.array([241, 233, 219]) / 255.0
|
||||
collectible = False
|
||||
craft_recp= {"Gem_Raw": 1}
|
||||
craft_labour_base= 1
|
||||
@@ -238,7 +238,7 @@ class Craft(BaseComponent):
|
||||
|
||||
|
||||
for agent in world.agents:
|
||||
if agent.name not in self.agent_subclasses | agent.is_setup():
|
||||
if agent.name not in self.agent_subclasses | agent.is_setup:
|
||||
continue
|
||||
agent.state["craft_skill"]={}
|
||||
agent.state["craft_labour"]={}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
from . import (
|
||||
simple_market,
|
||||
econ_wrapper
|
||||
econ_wrapper,
|
||||
econ
|
||||
)
|
||||
|
||||
@@ -266,7 +266,7 @@ class Econ(BaseEnvironment):
|
||||
for agent in self.world.agents:
|
||||
if not self._persist_between_resets:
|
||||
agent.set_setup(False) # resets agent states
|
||||
if not agent.is_setup(): # agent has not been setup for scenario
|
||||
if not agent.is_setup: # agent has not been setup for scenario
|
||||
agent.state["inventory"] = {k: 0 for k in agent.inventory.keys()}
|
||||
agent.state["escrow"] = {k: 0 for k in agent.inventory.keys()}
|
||||
agent.state["endogenous"] = {k: 0 for k in agent.endogenous.keys()}
|
||||
|
||||
22
main.py
22
main.py
@@ -7,6 +7,7 @@ from stable_baselines3.common.evaluation import evaluate_policy
|
||||
from sb3_contrib.ppo_mask import MaskablePPO
|
||||
import envs
|
||||
import wrapper
|
||||
import resources
|
||||
from wrapper.base_econ_wrapper import BaseEconWrapper
|
||||
from wrapper.reciever_econ_wrapper import RecieverEconWrapper
|
||||
from wrapper.sb3_econ_converter import SB3EconConverter
|
||||
@@ -26,7 +27,7 @@ env_config = {
|
||||
# ===== SCENARIO CLASS =====
|
||||
# Which Scenario class to use: the class's name in the Scenario Registry (foundation.scenarios).
|
||||
# The environment object will be an instance of the Scenario class.
|
||||
'scenario_name': 'simple_market',
|
||||
'scenario_name': 'econ',
|
||||
|
||||
# ===== COMPONENTS =====
|
||||
# Which components to use (specified as list of ("component_name", {component_kwargs}) tuples).
|
||||
@@ -78,7 +79,7 @@ eval_env_config = {
|
||||
# ===== SCENARIO CLASS =====
|
||||
# Which Scenario class to use: the class's name in the Scenario Registry (foundation.scenarios).
|
||||
# The environment object will be an instance of the Scenario class.
|
||||
'scenario_name': 'simple_market',
|
||||
'scenario_name': 'econ',
|
||||
|
||||
# ===== COMPONENTS =====
|
||||
# Which components to use (specified as list of ("component_name", {component_kwargs}) tuples).
|
||||
@@ -231,23 +232,24 @@ model = MaskablePPO("MlpPolicy",n_steps=int(env_config['episode_length']*2),ent_
|
||||
n_agents=econ.n_agents
|
||||
total_required_for_episode=n_agents*env_config['episode_length']
|
||||
print("this is run {}".format(runname))
|
||||
eval_econ=foundation.make_env_instance(**eval_env_config)
|
||||
eval_base_econ=BaseEconWrapper(eval_econ)
|
||||
eval_base_econ.run()
|
||||
eval_mobileRecieverEconWrapper=RecieverEconWrapper(eval_base_econ,"BasicMobileAgent")
|
||||
time.sleep(0.5)
|
||||
eval_sb3_converter=SB3EconConverter(eval_mobileRecieverEconWrapper,eval_econ,"BasicMobileAgent")
|
||||
while True:
|
||||
# Create Eval ENV
|
||||
|
||||
vec_env_eval=EconVecEnv(env_config=eval_env_config)
|
||||
vec_mon_eval=VecMonitor(venv=vec_env_eval)
|
||||
norm_env_eval=VecNormalize(vec_mon_eval,norm_reward=False,training=False)
|
||||
eval_econ = vec_env_eval.env
|
||||
|
||||
vec_mon_eval=VecMonitor(venv=eval_sb3_converter)
|
||||
#Train
|
||||
model=model.learn(total_timesteps=total_required_for_episode*50,progress_bar=True,reset_num_timesteps=False,tb_log_name=runname,callback=TensorboardCallback(econ=econ))
|
||||
model=model.learn(total_timesteps=total_required_for_episode*20,progress_bar=True,reset_num_timesteps=False,tb_log_name=runname,callback=TensorboardCallback(econ=econ))
|
||||
#normenv.save("temp-normalizer.ai")
|
||||
|
||||
|
||||
|
||||
## Run Eval
|
||||
print("### EVAL ###")
|
||||
norm_env_eval.load("temp-normalizer.ai",vec_mon_eval)
|
||||
|
||||
obs=vec_mon_eval.reset()
|
||||
done=False
|
||||
for i in tqdm(range(eval_env_config['episode_length'])):
|
||||
|
||||
@@ -1,23 +1,4 @@
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
from ai_economist.foundation.entities.resources import Resource, resource_registry
|
||||
|
||||
@resource_registry.add
|
||||
class RawGem(Resource):
|
||||
"""Raw Gem that can be processed further"""
|
||||
|
||||
name = "Raw_Gem"
|
||||
color = np.array([241, 233, 219]) / 255.0
|
||||
collectible = True
|
||||
|
||||
@resource_registry.add
|
||||
class Gem(Resource):
|
||||
"""Proccesed Gem. Craftable."""
|
||||
|
||||
name = "Gem"
|
||||
color = np.array([241, 233, 219]) / 255.0
|
||||
collectible = False
|
||||
craft_recp= {"Raw_Gem": 1}
|
||||
craft_labour_base= 1
|
||||
Reference in New Issue
Block a user