-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.py
31 lines (24 loc) · 1.07 KB
/
schedule.py
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
28
29
30
31
import numpy as np
from mesa.time import SimultaneousActivation
class MarketActivation(SimultaneousActivation):
def __init__(self, model):
super().__init__(model)
def agent_count(self):
self.num = len(self.agents)
def benefit(self, p_matrix, a_matrix):
for i in range(0, self.num):
self.agents[i].benefit_table(p_matrix[i], a_matrix[i])
def learn_d(self, p_matrix):
price_sum = np.sum(p_matrix)
non_zero = np.nonzero(p_matrix)[0].shape[0] # get the total number of non-zeros
if non_zero != 0:
price_avg = price_sum / non_zero
for i in range(0, self.num):
z = np.array(p_matrix[i])
if np.sum(z) > 0:
self.agents[i].learn() # learn the outflow, water use and outflow to maximize the benefit
else:
self.agents[i].learn_price(price_avg) # only learn the price
else: # No transaction occurs in the market
for i in range(0, self.num):
self.agents[i].learn_by_random()