something something i broke it meh
This commit is contained in:
@@ -2,29 +2,29 @@ kind: production
|
||||
spec:
|
||||
|
||||
- name: Grain
|
||||
amount: 1000
|
||||
prod:
|
||||
Raw_Agriculture_Plot: 1
|
||||
- name: Fruit
|
||||
amount: 1000
|
||||
prod:
|
||||
Raw_Agriculture_Plot: 1
|
||||
- name: Wood
|
||||
amount: 1000
|
||||
prod:
|
||||
Raw_Forrest: 1
|
||||
|
||||
- name: Fuel
|
||||
amount: 10
|
||||
prod:
|
||||
Wood: 1
|
||||
Raw_Agriculture_Plot: 1
|
||||
# - name: Fruit
|
||||
# amount: 1000
|
||||
# prod:
|
||||
# Raw_Agriculture_Plot: 1
|
||||
# - name: Wood
|
||||
# amount: 1000
|
||||
# prod:
|
||||
# Raw_Forrest: 1
|
||||
|
||||
# - name: Fuel
|
||||
# amount: 10
|
||||
# prod:
|
||||
# Wood: 1
|
||||
|
||||
- name: Food
|
||||
amount: 5
|
||||
amount: 1
|
||||
prod:
|
||||
Fuel: 1
|
||||
Fruit: 1
|
||||
Grain: 2
|
||||
# Fuel: 1
|
||||
# Fruit: 1
|
||||
Grain: 5
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -89,6 +89,14 @@ class Price_Believe_Aquire_Agent(Base_Aquire_Agent):
|
||||
else:
|
||||
# timeout
|
||||
self.update_trades()
|
||||
buy = o.qty-o.leaves_qty
|
||||
buyp=buy/o.qty
|
||||
sup = cx.total_supply[self.resource]+buy
|
||||
if sup == 0:
|
||||
sup = 1
|
||||
coverage = buy/sup
|
||||
# 50 % coverage limit
|
||||
modifier = (max([coverage,buyp])*2)-1
|
||||
cx.cancel_order(i["id"])
|
||||
self.collect_balance_from_cxs()
|
||||
self.collect_resource_from_cxs(self.resource)
|
||||
|
||||
@@ -72,7 +72,17 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
if o.leaves_qty == 0:
|
||||
# order is done
|
||||
self.open_orders[cx_id].remove(i) # remove order from open
|
||||
self.update_believe(cx_id, 1) # update price believe
|
||||
sold = o.qty-o.leaves_qty
|
||||
if o.qty==0:
|
||||
o.qty=1
|
||||
soldperc=sold/o.qty
|
||||
dem = cx.total_demand[self.resource]+sold
|
||||
if dem == 0:
|
||||
dem = 1
|
||||
coverage = sold/dem
|
||||
# 50 % coverage limit
|
||||
modifier = (max([coverage,soldperc])*2)-1
|
||||
self.update_believe(cx_id, modifier) # update price believe
|
||||
self.collect_balance_from_cxs()
|
||||
self.collect_resource_from_cxs(self.resource)
|
||||
self.update_trades()
|
||||
@@ -83,7 +93,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
i["leaves"] = leaves
|
||||
self.update_trades()
|
||||
# reset lifetime
|
||||
i["lifetime"]=self.max_price_adj_rate
|
||||
#i["lifetime"] = self.max_price_adj_rate
|
||||
|
||||
if i["lifetime"] > 0:
|
||||
self.open_qty += o.leaves_qty
|
||||
@@ -91,10 +101,19 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
else:
|
||||
# timeout
|
||||
self.update_trades()
|
||||
|
||||
sold = o.qty-o.leaves_qty
|
||||
soldperc=sold/o.qty
|
||||
dem = cx.total_demand[self.resource]+sold
|
||||
if dem == 0:
|
||||
dem = 1
|
||||
coverage = sold/dem
|
||||
# 50 % coverage limit
|
||||
modifier = (max([coverage,soldperc])*2)-1
|
||||
cx.cancel_order(i["id"])
|
||||
self.collect_balance_from_cxs()
|
||||
self.collect_resource_from_cxs(self.resource)
|
||||
self.update_believe(cx_id, -1)
|
||||
self.update_believe(cx_id, modifier)
|
||||
self.open_orders[cx_id].remove(i)
|
||||
|
||||
def update_believe(self, cx_id, modifier):
|
||||
@@ -104,6 +123,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
||||
If negative will sub lr to believe
|
||||
"""
|
||||
self.price_believe[cx_id] += modifier*self.lr
|
||||
self.price_believe[cx_id] = round(self.price_believe[cx_id], 2)
|
||||
if self.price_believe[cx_id] < 1:
|
||||
self.price_believe[cx_id] = 1
|
||||
|
||||
|
||||
@@ -2,16 +2,18 @@ from .base_business import Business
|
||||
from ..agents.price_believe_aquire import Price_Believe_Aquire_Agent
|
||||
from ..agents.price_believe_distribute import Price_Believe_Distribiute_Agent
|
||||
from ..agents.autoproduction import AutoProductionAgent
|
||||
import log
|
||||
|
||||
|
||||
class Price_Believe_Business(Business):
|
||||
def __init__(self, id, production, balance, exchange, simulation, location) -> None:
|
||||
super().__init__(id, production, balance, location)
|
||||
|
||||
self.max_storage = 10
|
||||
self.expense_per_unit = -1
|
||||
self.income_per_unit = -1
|
||||
self.distribute = Price_Believe_Distribiute_Agent(
|
||||
simulation, self, production["name"], exchange, 0.2, 10)
|
||||
simulation, self, production["name"], exchange, 0.2, 20)
|
||||
self.craft = AutoProductionAgent(simulation, self)
|
||||
self.aquire = {}
|
||||
|
||||
@@ -21,10 +23,11 @@ class Price_Believe_Business(Business):
|
||||
a.set_target(v*2)
|
||||
a.set_price_max(10)
|
||||
self.aquire[k] = a
|
||||
self.distribute.set_price_min(10)
|
||||
self.distribute.set_price_min(0)
|
||||
self.distribute.set_target(0)
|
||||
|
||||
def tick_business_decisions(self, step):
|
||||
amount= self.production["amount"]
|
||||
if step == 0:
|
||||
|
||||
max_amount = self.production["amount"]*5
|
||||
@@ -33,30 +36,39 @@ class Price_Believe_Business(Business):
|
||||
self.update_ex_per_unit()
|
||||
self.update_income_per_unit(step)
|
||||
|
||||
# set target for aquire
|
||||
# calc descision
|
||||
orderForNewProds = 1
|
||||
if self.income_per_unit<=0 or self.expense_per_unit<=0:
|
||||
# dont have data
|
||||
retain=0
|
||||
else:
|
||||
ie = (self.income_per_unit/self.expense_per_unit)-1
|
||||
if ie < 0:
|
||||
ie = 0
|
||||
if ie > 1:
|
||||
ie = 1
|
||||
#retain=(self.max_storage-ie*self.max_storage)*amount
|
||||
retain=0
|
||||
|
||||
|
||||
# set target for aquire
|
||||
|
||||
prod = self.production["prod"]
|
||||
|
||||
for k, v in prod.items():
|
||||
|
||||
self.aquire[k].set_target(v*orderForNewProds)
|
||||
|
||||
# update production
|
||||
targetUnit = self.production["amount"]*10
|
||||
targetUnit = self.production["amount"]*self.max_storage
|
||||
self.craft.set_target(targetUnit)
|
||||
|
||||
# set min distribute
|
||||
self.distribute.set_price_min(self.expense_per_unit)
|
||||
self.distribute.set_target(0)
|
||||
self.distribute.set_target(retain)
|
||||
|
||||
def tick_business_episode(self, episode_count):
|
||||
start_balance = self.balance_history[-1]
|
||||
diff = self.balance-start_balance
|
||||
if diff > 0:
|
||||
# we have some profit -> increase production staff
|
||||
self.craft.set_worker(self.craft.worker+1)
|
||||
else:
|
||||
self.craft.set_worker(self.craft.worker-1)
|
||||
|
||||
def resource_in_possesion(self):
|
||||
return self.distribute.open_qty+self.inventory[self.production["name"]]
|
||||
@@ -118,3 +130,18 @@ class Price_Believe_Business(Business):
|
||||
a.unregister()
|
||||
self.distribute.unregister()
|
||||
self.craft.unregister()
|
||||
|
||||
def log(self, episode, episode_length, step):
|
||||
data = {}
|
||||
data["id"] = self.id
|
||||
data["episode"] = episode
|
||||
data["step"] = step
|
||||
data["tstep"] = step+episode*episode_length
|
||||
data["production"] = self.production["name"]
|
||||
data["expense"] = self.expense_per_unit
|
||||
data["income"] = self.income_per_unit
|
||||
data["inventory"] = self.inventory[self.production["name"]]
|
||||
data["retain"] = self.distribute.target
|
||||
data["balance"] = self.balance
|
||||
data["location"] = self.location
|
||||
log.BUSINESSData.append(data)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -52,15 +52,3 @@ class Business(ABC):
|
||||
def close_business(self):
|
||||
assert "close_business has not been provided"
|
||||
|
||||
def log(self,episode,episode_length,step):
|
||||
data={}
|
||||
data["id"]=self.id
|
||||
data["episode"]=episode
|
||||
data["step"]=step
|
||||
data["tstep"]=step+episode*episode_length
|
||||
data["production"]=self.production["name"]
|
||||
data["prod_inventory"]=self.inventory[self.production["name"]]
|
||||
data["raw_inventory"]=self.inventory[self.production["name"]]
|
||||
data["balance"]=self.balance
|
||||
data["location"]=self.location
|
||||
log.BUSINESSData.append(data)
|
||||
2
main.py
2
main.py
@@ -41,7 +41,7 @@ sim.reset()
|
||||
while len(sim.get_underutelized_prods(1))>0:
|
||||
sim.create_bussiness(1)
|
||||
#sim.reset()
|
||||
for a in tqdm(range(200)):
|
||||
for a in tqdm(range(50)):
|
||||
for i in range(100):
|
||||
sim.tick(100)
|
||||
print(f"|Stats| Num of Businesses: {len(sim.businesses)} Num Tickfunk: {len(sim.tick_funcs)} Time Agent Tick: {sim.timings['dsa']} Time Logging {sim.timings['dbl']}")
|
||||
|
||||
Reference in New Issue
Block a user