fuck man major readjustment but it is running again...

This commit is contained in:
2023-06-28 19:40:42 +02:00
parent b7dc7b99d1
commit 509c59bb88
25 changed files with 353 additions and 147 deletions

View File

@@ -34,6 +34,7 @@ class Simulation():
def set_cells(self,cells):
for c in cells:
self.cells[c.name]=c
self.populated_cells[c.name]=0
def set_businesses(self,bus):
self.businesses=bus
@@ -93,7 +94,7 @@ class Simulation():
self.timings["dss"]+=setup-start
self.timings["dsa"]+=agentstep-setup
self.timings["dsap"]=self.timings["dsa"]/(len(self.tick_funcs)+1)
self.timings["dab"]+=busstep-agentstep
self.timings["dab"]+=(busstep-agentstep)/(len(self.businesses)+1)
self.timings["dbl"]+=logstep-busstep
self.timings["dt"]+=logstep-start
@@ -157,10 +158,10 @@ class Simulation():
cell_id=random.choice(cells)
cell=self.cells[cell_id]
cxs=[cell.exchange,self.cx]
self.populated_cells[cell_id]=True
business=Price_Believe_Business.Price_Believe_Business(uuid.uuid4(),prod,1000,cxs,self)
business=Price_Believe_Business.Price_Believe_Business(uuid.UUID(int=random.getrandbits(128)),prod,1000,cxs,self,cell_id)
self.businesses.append(business)
self.production_util[selected_prod]+=1
self.populated_cells[cell_id]+=1
return business
def remove_business(self,id):
@@ -173,6 +174,7 @@ class Simulation():
bus.close_business()
self.businesses.remove(bus)
self.production_util[bus.production["id"]]-=1
self.populated_cells[bus.location]-=1
def get_max_profit_prod(self):
@@ -183,7 +185,7 @@ class Simulation():
for b in self.businesses:
id=b.production["id"]
diff=b.balance-b.balance_history[-1]
diff=b.balance-b.balance_history[-2]
if id not in profit:
profit[id]=0
profit[id]+=diff
@@ -208,16 +210,15 @@ class Simulation():
cx=cell.exchange
# Best prod resource availability
# Using the exchange in that cell, lookup supply or demand of resources. Supply +1 / Demand -1
for prod_item in prod["prod"]:
key=list(prod_item.keys())[0]
val=prod_item[key]
for key,val in prod["prod"].items():
a=cx.get_total_supply(key)
cell_score[cell.name]+=(cx.get_total_supply(key)/val)
cell_score[cell.name]-=(cx.get_total_demand(key)/val)
# If demand for prod item in cell then score +1/ score -1 if supply is already there
a=cx.get_total_demand(prod["name"])
cell_score[cell.name]+=cx.get_total_demand(prod["name"])
cell_score[cell.name]-=cx.get_total_supply(prod["name"])
b=cx.get_total_supply(prod["name"])
cell_score[cell.name]+=a
cell_score[cell.name]-=b
max_keys = [key for key, value in cell_score.items() if value == max(cell_score.values())]
return max_keys
@@ -246,11 +247,12 @@ class Simulation():
return cx.log_step(name,epi,epilen,tick,False)
def log_cxs_episode(self):
for id,_ in self.populated_cells.items():
cell=self.cells[id]
lcx=cell.exchange
name="lcx_{}".format(id)
lcx.log_episode(name,self.episode_count)
for id,v in self.populated_cells.items():
if v>0:
cell=self.cells[id]
lcx=cell.exchange
name="lcx_{}".format(id)
lcx.log_episode(name,self.episode_count)
self.cx.log_episode("cx",self.episode_count)
def log_business_tick(self,episode_length):