-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetexport.py
More file actions
29 lines (22 loc) · 883 Bytes
/
netexport.py
File metadata and controls
29 lines (22 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import abce
from abce import NotEnoughGoods
class NetExport(abce.Agent):
def init(self, _, __):
self.create('money', 0)
def invest(self):
offers_grouped = self.get_offers_all().values()
offers = []
for os in offers_grouped:
offers.extend(os)
demand = sum([offer.quantity * offer.price for offer in offers if offer.sell])
if demand < self.possession('money'):
self.rationing = rationing = 1
else:
self.rationing = rationing = self.possession('money') / demand
for offer in offers:
if not offer.sell:
self.create(offer.good, offer.quantity)
self.accept(offer)
else:
self.accept(offer, offer.quantity * rationing)
self.give(('household', 0), quantity=self.possession('money'), good='money')