its not braking anymore
This commit is contained in:
@@ -50,6 +50,7 @@ class Craft(BaseComponent):
|
||||
assert len(commodities)>0
|
||||
#setup commodities
|
||||
self.recip_map={}
|
||||
self.commodities=[]
|
||||
for v in commodities:
|
||||
res_class=resource_registry.get(v)
|
||||
res=res_class()
|
||||
@@ -80,11 +81,14 @@ class Craft(BaseComponent):
|
||||
def agent_can_build(self, agent, res):
|
||||
"""Return True if agent can actually build in its current location."""
|
||||
# See if the agent has the resources necessary to complete the action
|
||||
recipe= self.recip_map[res]
|
||||
for resource, cost in recipe.items():
|
||||
if agent.state["inventory"][resource] < cost:
|
||||
return False
|
||||
return True
|
||||
if res in self.recip_map:
|
||||
recipe= self.recip_map[res]
|
||||
for resource, cost in recipe.items():
|
||||
if agent.state["inventory"][resource] < cost:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
# Required methods for implementing components
|
||||
# --------------------------------------------
|
||||
@@ -136,9 +140,10 @@ class Craft(BaseComponent):
|
||||
|
||||
# Build! (If you can.)
|
||||
else:
|
||||
action-=1
|
||||
comm=self.commodities[action]
|
||||
|
||||
if self.agent_can_build(agent,comm.craft_recp):
|
||||
if self.agent_can_build(agent,comm.name):
|
||||
# Remove the resources
|
||||
for resource, cost in comm.craft_recp.items():
|
||||
agent.state["inventory"][resource] -= cost
|
||||
@@ -211,7 +216,7 @@ class Craft(BaseComponent):
|
||||
where metric_value is a scalar.
|
||||
"""
|
||||
world = self.world
|
||||
|
||||
"""
|
||||
build_stats = {a.idx: {"n_builds": 0} for a in world.agents}
|
||||
for builds in self.builds:
|
||||
for build in builds:
|
||||
@@ -225,8 +230,8 @@ class Craft(BaseComponent):
|
||||
|
||||
num_houses = np.sum(world.maps.get("House") > 0)
|
||||
out_dict["total_builds"] = num_houses
|
||||
|
||||
return out_dict
|
||||
"""
|
||||
return {}
|
||||
|
||||
def additional_reset_steps(self):
|
||||
"""
|
||||
@@ -257,7 +262,8 @@ class Craft(BaseComponent):
|
||||
elif self.skill_dist == "pareto":
|
||||
labour = 1
|
||||
sampled_skill = np.random.pareto(2)
|
||||
amount = np.minimum(MSAB, MSAB * sampled_skill)
|
||||
|
||||
amount = 1+np.minimum(MSAB,(MSAB-1) * (sampled_skill) )
|
||||
labour_modifier = 1 - np.minimum(1 - MSLB, (1 - MSLB) * sampled_skill)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -107,8 +107,8 @@ class ExternalMarket(BaseComponent):
|
||||
|
||||
# NO-OP!
|
||||
if action == 0:
|
||||
pass
|
||||
action-=1
|
||||
continue
|
||||
|
||||
res_name=self.action_res_map[action]
|
||||
# Build! (If you can.)
|
||||
|
||||
@@ -163,10 +163,11 @@ class ExternalMarket(BaseComponent):
|
||||
# Mobile agents' build action is masked if they cannot build with their
|
||||
# current location and/or endowment
|
||||
for agent in self.world.agents:
|
||||
mask=[]
|
||||
for res in self.market_demand:
|
||||
mask.append(self.agent_can_sell(agent,res))
|
||||
masks[agent.idx] = mask
|
||||
if agent.name in self.agent_subclasses:
|
||||
mask=[]
|
||||
for res in self.market_demand:
|
||||
mask.append(self.agent_can_sell(agent,res))
|
||||
masks[agent.idx] = mask
|
||||
|
||||
return masks
|
||||
|
||||
@@ -182,7 +183,7 @@ class ExternalMarket(BaseComponent):
|
||||
where metric_value is a scalar.
|
||||
"""
|
||||
world = self.world
|
||||
|
||||
"""
|
||||
build_stats = {a.idx: {"n_builds": 0} for a in world.agents}
|
||||
for builds in self.builds:
|
||||
for build in builds:
|
||||
@@ -196,8 +197,8 @@ class ExternalMarket(BaseComponent):
|
||||
|
||||
num_houses = np.sum(world.maps.get("House") > 0)
|
||||
out_dict["total_builds"] = num_houses
|
||||
|
||||
return out_dict
|
||||
"""
|
||||
return {}
|
||||
|
||||
def additional_reset_steps(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user