fuck man major readjustment but it is running again...
This commit is contained in:
@@ -3,35 +3,118 @@ 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
|
||||
|
||||
class Price_Believe_Business(Business):
|
||||
def __init__(self, id, production, balance,exchange,simulation) -> None:
|
||||
super().__init__(id, production, balance)
|
||||
|
||||
self.distribute=Price_Believe_Distribiute_Agent(simulation,self,production["name"],exchange,0.5,10)
|
||||
self.craft=AutoProductionAgent(simulation,self)
|
||||
self.aquire={}
|
||||
for l in production["prod"]:
|
||||
for k,v in l.items():
|
||||
a=Price_Believe_Aquire_Agent(simulation,self,k,exchange,1,10)
|
||||
a.set_target(v*2)
|
||||
a.set_price_max(10)
|
||||
self.aquire[k]=a
|
||||
self.distribute.set_price_min(10)
|
||||
self.distribute.set_target(0)
|
||||
|
||||
def tick_business_decisions(self,step):
|
||||
for comp in self.production["prod"]:
|
||||
for k,v in comp.items():
|
||||
modifier=1
|
||||
self.aquire[k].set_target(v*modifier)
|
||||
max_amount=self.production["amount"]*5
|
||||
self.craft.set_target(max_amount)
|
||||
class Price_Believe_Business(Business):
|
||||
def __init__(self, id, production, balance, exchange, simulation, location) -> None:
|
||||
super().__init__(id, production, balance, location)
|
||||
|
||||
self.expense_per_unit = -1
|
||||
self.income_per_unit = -1
|
||||
self.distribute = Price_Believe_Distribiute_Agent(
|
||||
simulation, self, production["name"], exchange, 0.2, 10)
|
||||
self.craft = AutoProductionAgent(simulation, self)
|
||||
self.aquire = {}
|
||||
|
||||
for k, v in production["prod"].items():
|
||||
a = Price_Believe_Aquire_Agent(
|
||||
simulation, self, k, exchange, 0.2, 10)
|
||||
a.set_target(v*2)
|
||||
a.set_price_max(10)
|
||||
self.aquire[k] = a
|
||||
self.distribute.set_price_min(10)
|
||||
self.distribute.set_target(0)
|
||||
|
||||
def tick_business_decisions(self, step):
|
||||
if step == 0:
|
||||
|
||||
max_amount = self.production["amount"]*5
|
||||
self.craft.set_target(max_amount)
|
||||
# Update bookkeeping
|
||||
self.update_ex_per_unit()
|
||||
self.update_income_per_unit(step)
|
||||
|
||||
# set target for aquire
|
||||
orderForNewProds = 1
|
||||
prod = self.production["prod"]
|
||||
|
||||
for k, v in prod.items():
|
||||
|
||||
self.aquire[k].set_target(v*orderForNewProds)
|
||||
|
||||
# update production
|
||||
targetUnit = self.production["amount"]*10
|
||||
self.craft.set_target(targetUnit)
|
||||
|
||||
# set min distribute
|
||||
self.distribute.set_price_min(self.expense_per_unit)
|
||||
self.distribute.set_target(0)
|
||||
|
||||
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"]]
|
||||
return self.distribute.open_qty+self.inventory[self.production["name"]]
|
||||
|
||||
def update_ex_per_unit(self):
|
||||
experunit = 0
|
||||
prod = self.production["prod"]
|
||||
amount = self.production["amount"]
|
||||
qtyNewProds = -1
|
||||
for key, agent in self.aquire.items():
|
||||
agent.update_trades()
|
||||
if agent.qty == 0:
|
||||
return
|
||||
if agent.qty<0:
|
||||
print("pla")
|
||||
req = prod[key]
|
||||
|
||||
covers = agent.qty/req
|
||||
|
||||
if qtyNewProds == -1:
|
||||
qtyNewProds = covers
|
||||
if qtyNewProds > covers:
|
||||
qtyNewProds = covers
|
||||
|
||||
ExPerProd = agent.expense/covers
|
||||
experunit += ExPerProd/amount
|
||||
|
||||
if qtyNewProds > 0:
|
||||
# confirm new units
|
||||
for key, agent in self.aquire.items():
|
||||
qtyToConfirm = prod[key]*qtyNewProds
|
||||
agent.confirm_purchase(qtyToConfirm)
|
||||
a=1+2
|
||||
|
||||
qtyNewUnits = qtyNewProds*amount
|
||||
|
||||
# if we havent set the expense_per_unit
|
||||
if self.expense_per_unit == -1:
|
||||
self.expense_per_unit = experunit
|
||||
return
|
||||
# update expense per unit
|
||||
prev_ex_total = self.expense_per_unit*self.resource_in_possesion()
|
||||
new_ex_total = qtyNewUnits*experunit
|
||||
ex_total = prev_ex_total+new_ex_total
|
||||
estimatedQTYUnits = qtyNewUnits+self.resource_in_possesion()
|
||||
new_ex = ex_total/estimatedQTYUnits
|
||||
self.expense_per_unit = new_ex
|
||||
|
||||
def update_income_per_unit(self,step):
|
||||
qty_sold = self.distribute.qty
|
||||
income = self.distribute.income
|
||||
if income==0:
|
||||
return
|
||||
self.income_per_unit = qty_sold/income
|
||||
self.distribute.confirm_distribution(qty_sold,step)
|
||||
|
||||
def close_business(self):
|
||||
for k,a in self.aquire.items():
|
||||
a.unregister()
|
||||
self.distribute.unregister()
|
||||
self.craft.unregister()
|
||||
for k, a in self.aquire.items():
|
||||
a.unregister()
|
||||
self.distribute.unregister()
|
||||
self.craft.unregister()
|
||||
|
||||
Reference in New Issue
Block a user