something something i broke it meh
This commit is contained in:
@@ -2,29 +2,29 @@ kind: production
|
|||||||
spec:
|
spec:
|
||||||
|
|
||||||
- name: Grain
|
- 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
|
amount: 10
|
||||||
prod:
|
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
|
- name: Food
|
||||||
amount: 5
|
amount: 1
|
||||||
prod:
|
prod:
|
||||||
Fuel: 1
|
# Fuel: 1
|
||||||
Fruit: 1
|
# Fruit: 1
|
||||||
Grain: 2
|
Grain: 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -89,6 +89,14 @@ class Price_Believe_Aquire_Agent(Base_Aquire_Agent):
|
|||||||
else:
|
else:
|
||||||
# timeout
|
# timeout
|
||||||
self.update_trades()
|
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"])
|
cx.cancel_order(i["id"])
|
||||||
self.collect_balance_from_cxs()
|
self.collect_balance_from_cxs()
|
||||||
self.collect_resource_from_cxs(self.resource)
|
self.collect_resource_from_cxs(self.resource)
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
|||||||
# aquire based on current price belive
|
# aquire based on current price belive
|
||||||
cx_id = self.select_best_cx()
|
cx_id = self.select_best_cx()
|
||||||
|
|
||||||
price=round(self.price_believe[cx_id])
|
price = round(self.price_believe[cx_id])
|
||||||
if price<self.min_price:
|
if price < self.min_price:
|
||||||
price=self.min_price
|
price = self.min_price
|
||||||
order = self.distribute_resource(
|
order = self.distribute_resource(
|
||||||
price, order_error, cx_id)
|
price, order_error, cx_id)
|
||||||
self.register_order(cx_id, order)
|
self.register_order(cx_id, order)
|
||||||
@@ -53,7 +53,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
|||||||
'lifetime': self.max_price_adj_rate,
|
'lifetime': self.max_price_adj_rate,
|
||||||
'leaves': order.leaves_qty
|
'leaves': order.leaves_qty
|
||||||
})
|
})
|
||||||
if order.leaves_qty!=order.qty:
|
if order.leaves_qty != order.qty:
|
||||||
self.update_trades()
|
self.update_trades()
|
||||||
|
|
||||||
def tick_open_orders(self) -> int:
|
def tick_open_orders(self) -> int:
|
||||||
@@ -68,22 +68,32 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
|||||||
for i in cx_orders:
|
for i in cx_orders:
|
||||||
# Check for each order if it is fullfiled or if it is timed
|
# Check for each order if it is fullfiled or if it is timed
|
||||||
o = self.orders[cx_id][i["id"]]
|
o = self.orders[cx_id][i["id"]]
|
||||||
leaves=o.leaves_qty
|
leaves = o.leaves_qty
|
||||||
if o.leaves_qty == 0:
|
if o.leaves_qty == 0:
|
||||||
# order is done
|
# order is done
|
||||||
self.open_orders[cx_id].remove(i) # remove order from open
|
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_balance_from_cxs()
|
||||||
self.collect_resource_from_cxs(self.resource)
|
self.collect_resource_from_cxs(self.resource)
|
||||||
self.update_trades()
|
self.update_trades()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not (i["leaves"]==leaves):
|
if not (i["leaves"] == leaves):
|
||||||
#update in order
|
# update in order
|
||||||
i["leaves"]=leaves
|
i["leaves"] = leaves
|
||||||
self.update_trades()
|
self.update_trades()
|
||||||
#reset lifetime
|
# reset lifetime
|
||||||
i["lifetime"]=self.max_price_adj_rate
|
#i["lifetime"] = self.max_price_adj_rate
|
||||||
|
|
||||||
if i["lifetime"] > 0:
|
if i["lifetime"] > 0:
|
||||||
self.open_qty += o.leaves_qty
|
self.open_qty += o.leaves_qty
|
||||||
@@ -91,10 +101,19 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
|||||||
else:
|
else:
|
||||||
# timeout
|
# timeout
|
||||||
self.update_trades()
|
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"])
|
cx.cancel_order(i["id"])
|
||||||
self.collect_balance_from_cxs()
|
self.collect_balance_from_cxs()
|
||||||
self.collect_resource_from_cxs(self.resource)
|
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)
|
self.open_orders[cx_id].remove(i)
|
||||||
|
|
||||||
def update_believe(self, cx_id, modifier):
|
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
|
If negative will sub lr to believe
|
||||||
"""
|
"""
|
||||||
self.price_believe[cx_id] += modifier*self.lr
|
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:
|
if self.price_believe[cx_id] < 1:
|
||||||
self.price_believe[cx_id] = 1
|
self.price_believe[cx_id] = 1
|
||||||
|
|
||||||
|
|||||||
@@ -2,29 +2,32 @@ from .base_business import Business
|
|||||||
from ..agents.price_believe_aquire import Price_Believe_Aquire_Agent
|
from ..agents.price_believe_aquire import Price_Believe_Aquire_Agent
|
||||||
from ..agents.price_believe_distribute import Price_Believe_Distribiute_Agent
|
from ..agents.price_believe_distribute import Price_Believe_Distribiute_Agent
|
||||||
from ..agents.autoproduction import AutoProductionAgent
|
from ..agents.autoproduction import AutoProductionAgent
|
||||||
|
import log
|
||||||
|
|
||||||
|
|
||||||
class Price_Believe_Business(Business):
|
class Price_Believe_Business(Business):
|
||||||
def __init__(self, id, production, balance, exchange, simulation, location) -> None:
|
def __init__(self, id, production, balance, exchange, simulation, location) -> None:
|
||||||
super().__init__(id, production, balance, location)
|
super().__init__(id, production, balance, location)
|
||||||
|
|
||||||
|
self.max_storage = 10
|
||||||
self.expense_per_unit = -1
|
self.expense_per_unit = -1
|
||||||
self.income_per_unit = -1
|
self.income_per_unit = -1
|
||||||
self.distribute = Price_Believe_Distribiute_Agent(
|
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.craft = AutoProductionAgent(simulation, self)
|
||||||
self.aquire = {}
|
self.aquire = {}
|
||||||
|
|
||||||
for k, v in production["prod"].items():
|
for k, v in production["prod"].items():
|
||||||
a = Price_Believe_Aquire_Agent(
|
a = Price_Believe_Aquire_Agent(
|
||||||
simulation, self, k, exchange, 0.2, 10)
|
simulation, self, k, exchange, 0.2, 10)
|
||||||
a.set_target(v*2)
|
a.set_target(v*2)
|
||||||
a.set_price_max(10)
|
a.set_price_max(10)
|
||||||
self.aquire[k] = a
|
self.aquire[k] = a
|
||||||
self.distribute.set_price_min(10)
|
self.distribute.set_price_min(0)
|
||||||
self.distribute.set_target(0)
|
self.distribute.set_target(0)
|
||||||
|
|
||||||
def tick_business_decisions(self, step):
|
def tick_business_decisions(self, step):
|
||||||
|
amount= self.production["amount"]
|
||||||
if step == 0:
|
if step == 0:
|
||||||
|
|
||||||
max_amount = self.production["amount"]*5
|
max_amount = self.production["amount"]*5
|
||||||
@@ -33,30 +36,39 @@ class Price_Believe_Business(Business):
|
|||||||
self.update_ex_per_unit()
|
self.update_ex_per_unit()
|
||||||
self.update_income_per_unit(step)
|
self.update_income_per_unit(step)
|
||||||
|
|
||||||
# set target for aquire
|
# calc descision
|
||||||
orderForNewProds = 1
|
orderForNewProds = 1
|
||||||
prod = self.production["prod"]
|
if self.income_per_unit<=0 or self.expense_per_unit<=0:
|
||||||
|
# dont have data
|
||||||
for k, v in prod.items():
|
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)
|
self.aquire[k].set_target(v*orderForNewProds)
|
||||||
|
|
||||||
# update production
|
# update production
|
||||||
targetUnit = self.production["amount"]*10
|
targetUnit = self.production["amount"]*self.max_storage
|
||||||
self.craft.set_target(targetUnit)
|
self.craft.set_target(targetUnit)
|
||||||
|
|
||||||
# set min distribute
|
# set min distribute
|
||||||
self.distribute.set_price_min(self.expense_per_unit)
|
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):
|
def tick_business_episode(self, episode_count):
|
||||||
start_balance = self.balance_history[-1]
|
start_balance = self.balance_history[-1]
|
||||||
diff = self.balance-start_balance
|
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):
|
def resource_in_possesion(self):
|
||||||
return self.distribute.open_qty+self.inventory[self.production["name"]]
|
return self.distribute.open_qty+self.inventory[self.production["name"]]
|
||||||
@@ -70,7 +82,7 @@ class Price_Believe_Business(Business):
|
|||||||
agent.update_trades()
|
agent.update_trades()
|
||||||
if agent.qty == 0:
|
if agent.qty == 0:
|
||||||
return
|
return
|
||||||
if agent.qty<0:
|
if agent.qty < 0:
|
||||||
print("pla")
|
print("pla")
|
||||||
req = prod[key]
|
req = prod[key]
|
||||||
|
|
||||||
@@ -89,7 +101,7 @@ class Price_Believe_Business(Business):
|
|||||||
for key, agent in self.aquire.items():
|
for key, agent in self.aquire.items():
|
||||||
qtyToConfirm = prod[key]*qtyNewProds
|
qtyToConfirm = prod[key]*qtyNewProds
|
||||||
agent.confirm_purchase(qtyToConfirm)
|
agent.confirm_purchase(qtyToConfirm)
|
||||||
a=1+2
|
a = 1+2
|
||||||
|
|
||||||
qtyNewUnits = qtyNewProds*amount
|
qtyNewUnits = qtyNewProds*amount
|
||||||
|
|
||||||
@@ -105,16 +117,31 @@ class Price_Believe_Business(Business):
|
|||||||
new_ex = ex_total/estimatedQTYUnits
|
new_ex = ex_total/estimatedQTYUnits
|
||||||
self.expense_per_unit = new_ex
|
self.expense_per_unit = new_ex
|
||||||
|
|
||||||
def update_income_per_unit(self,step):
|
def update_income_per_unit(self, step):
|
||||||
qty_sold = self.distribute.qty
|
qty_sold = self.distribute.qty
|
||||||
income = self.distribute.income
|
income = self.distribute.income
|
||||||
if income==0:
|
if income == 0:
|
||||||
return
|
return
|
||||||
self.income_per_unit = qty_sold/income
|
self.income_per_unit = qty_sold/income
|
||||||
self.distribute.confirm_distribution(qty_sold,step)
|
self.distribute.confirm_distribution(qty_sold, step)
|
||||||
|
|
||||||
def close_business(self):
|
def close_business(self):
|
||||||
for k, a in self.aquire.items():
|
for k, a in self.aquire.items():
|
||||||
a.unregister()
|
a.unregister()
|
||||||
self.distribute.unregister()
|
self.distribute.unregister()
|
||||||
self.craft.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):
|
def close_business(self):
|
||||||
assert "close_business has not been provided"
|
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:
|
while len(sim.get_underutelized_prods(1))>0:
|
||||||
sim.create_bussiness(1)
|
sim.create_bussiness(1)
|
||||||
#sim.reset()
|
#sim.reset()
|
||||||
for a in tqdm(range(200)):
|
for a in tqdm(range(50)):
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
sim.tick(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']}")
|
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