it is working
This commit is contained in:
@@ -65,3 +65,20 @@ class Coin(Resource):
|
|||||||
color = np.array([229, 211, 82]) / 255.0
|
color = np.array([229, 211, 82]) / 255.0
|
||||||
collectible = False
|
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:
|
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
|
continue
|
||||||
agent.state["craft_skill"]={}
|
agent.state["craft_skill"]={}
|
||||||
agent.state["craft_labour"]={}
|
agent.state["craft_labour"]={}
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
simple_market,
|
simple_market,
|
||||||
econ_wrapper
|
econ_wrapper,
|
||||||
|
econ
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -266,7 +266,7 @@ class Econ(BaseEnvironment):
|
|||||||
for agent in self.world.agents:
|
for agent in self.world.agents:
|
||||||
if not self._persist_between_resets:
|
if not self._persist_between_resets:
|
||||||
agent.set_setup(False) # resets agent states
|
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["inventory"] = {k: 0 for k in agent.inventory.keys()}
|
||||||
agent.state["escrow"] = {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()}
|
agent.state["endogenous"] = {k: 0 for k in agent.endogenous.keys()}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from stable_baselines3.common.evaluation import evaluate_policy
|
|||||||
from sb3_contrib.ppo_mask import MaskablePPO
|
from sb3_contrib.ppo_mask import MaskablePPO
|
||||||
import envs
|
import envs
|
||||||
import wrapper
|
import wrapper
|
||||||
|
import resources
|
||||||
from wrapper.base_econ_wrapper import BaseEconWrapper
|
from wrapper.base_econ_wrapper import BaseEconWrapper
|
||||||
from wrapper.reciever_econ_wrapper import RecieverEconWrapper
|
from wrapper.reciever_econ_wrapper import RecieverEconWrapper
|
||||||
from wrapper.sb3_econ_converter import SB3EconConverter
|
from wrapper.sb3_econ_converter import SB3EconConverter
|
||||||
@@ -26,7 +27,7 @@ env_config = {
|
|||||||
# ===== SCENARIO CLASS =====
|
# ===== SCENARIO CLASS =====
|
||||||
# Which Scenario class to use: the class's name in the Scenario Registry (foundation.scenarios).
|
# 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.
|
# The environment object will be an instance of the Scenario class.
|
||||||
'scenario_name': 'simple_market',
|
'scenario_name': 'econ',
|
||||||
|
|
||||||
# ===== COMPONENTS =====
|
# ===== COMPONENTS =====
|
||||||
# Which components to use (specified as list of ("component_name", {component_kwargs}) tuples).
|
# Which components to use (specified as list of ("component_name", {component_kwargs}) tuples).
|
||||||
@@ -78,7 +79,7 @@ eval_env_config = {
|
|||||||
# ===== SCENARIO CLASS =====
|
# ===== SCENARIO CLASS =====
|
||||||
# Which Scenario class to use: the class's name in the Scenario Registry (foundation.scenarios).
|
# 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.
|
# The environment object will be an instance of the Scenario class.
|
||||||
'scenario_name': 'simple_market',
|
'scenario_name': 'econ',
|
||||||
|
|
||||||
# ===== COMPONENTS =====
|
# ===== COMPONENTS =====
|
||||||
# Which components to use (specified as list of ("component_name", {component_kwargs}) tuples).
|
# 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
|
n_agents=econ.n_agents
|
||||||
total_required_for_episode=n_agents*env_config['episode_length']
|
total_required_for_episode=n_agents*env_config['episode_length']
|
||||||
print("this is run {}".format(runname))
|
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:
|
while True:
|
||||||
# Create Eval ENV
|
# Create Eval ENV
|
||||||
|
vec_mon_eval=VecMonitor(venv=eval_sb3_converter)
|
||||||
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
|
|
||||||
|
|
||||||
#Train
|
#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")
|
#normenv.save("temp-normalizer.ai")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Run Eval
|
## Run Eval
|
||||||
print("### EVAL ###")
|
print("### EVAL ###")
|
||||||
norm_env_eval.load("temp-normalizer.ai",vec_mon_eval)
|
|
||||||
obs=vec_mon_eval.reset()
|
obs=vec_mon_eval.reset()
|
||||||
done=False
|
done=False
|
||||||
for i in tqdm(range(eval_env_config['episode_length'])):
|
for i in tqdm(range(eval_env_config['episode_length'])):
|
||||||
|
|||||||
@@ -1,23 +1,4 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
from ai_economist.foundation.entities.resources import Resource, resource_registry
|
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