class Firm(abce.Agent, abce.Firm): def init(self, simulation_parameters, agent_parameters): self.price_controller = PiController(0.001, 0.015, positive=True) self.production_controller = PiController(0.001, 0.015, positive=True) self.price = self.price_1 = 100 self.total_orders = 0 self.dX = np.ones((20, 4)) self.dy = np.ones(20) self.X = np.ones((20, 2)) self.y = np.ones(20) self.L = 4 self.L_1 = 0 def my_production(self): """ produce missing cookies """ self.create('cookies', self.L) self.cookies_before = self.possession('cookies') self.log('cookies', {'created': self.L, 'inventory': self.possession('cookies')}) self.y[self.round % 20] = (self.price) self.dy[self.round % 20] = (self.price - self.price_1) def selling(self): self.offer = self.sell(('market', 0), 'cookies', self.possession('cookies'), self.price) def adjust_price(self): self.total_orders = self.get_messages('demand')[0].content self.dX[self.round % 20] = [1, self.L, self.price_1, self.L_1] self.X[self.round % 20] = [1, self.L] self.price_1 = self.price error = self.total_orders - self.cookies_before self.price = self.price_controller.update(error) self.log('price', {'price': self.price, 'error_cum': self.price_controller.error_cum, 'error': error, 'total_orders': self.total_orders}) def adjust_quantity(self): # uw ought to be 1 * L for monopolist, 0 for competitive # up ought to be -1 * L for monopolist, 0 for competitive if self.round % 20 == 19: # monopolist uw = 1 * self.L up = -1 * self.L w = 14 + self.L p = self.price error = p + up - w - uw self.L = self.production_controller.update(error) self.log('production', {'error_cum': self.production_controller.error_cum, 'error': error})
def init(self, simulation_parameters, agent_parameters): self.price = self.price_1 = 100 self.cookies_before = self.production_target = self.production_target_1 = 100 self.wage = self.wage_1 = 1 self.price_controller = PiController(0.01, 0.015, output0=self.price, positive=True) self.production_controller = PiController(0.01, 0.015, output0=self.production_target, positive=True) self.wage_controller = PiController(0.01, 0.015, output0=self.wage, positive=True) self.up_regression = UPRegression(memory=500) self.uw_regression = UPRegression(memory=500) self.set_leontief('cookies', {'labor': 1})
class Firm(abce.Agent, abce.Firm): def init(self, simulation_parameters, agent_parameters): self.price_controller = PiController(0.001, 0.015, positive=True) self.production_controller = PiController(0.001, 0.015, positive=True) self.price = self.price_1 = 100 self.total_orders = 0 self.dX = np.ones((20, 4)) self.dy = np.ones(20) self.X = np.ones((20, 2)) self.y = np.ones(20) self.L = 4 self.L_1 = 0 def my_production(self): """ produce missing cookies """ self.create('cookies', self.L) self.cookies_before = self.possession('cookies') self.log('cookies', {'created': self.L, 'inventory': self.possession('cookies')}) self.y[self.round % 20] = (self.price) self.dy[self.round % 20] = (self.price - self.price_1) def selling(self): self.offer = self.sell('market', 0, 'cookies', self.possession('cookies'), self.price) def adjust_price(self): self.total_orders = self.get_messages('demand')[0].content self.dX[self.round % 20] = [1, self.L, self.price_1, self.L_1] self.X[self.round % 20] = [1, self.L] self.price_1 = self.price error = self.total_orders - self.cookies_before self.price = self.price_controller.update(error) self.log('price', {'price': self.price, 'error_cum': self.price_controller.error_cum, 'error': error, 'total_orders': self.total_orders}) def adjust_quantity(self): #uw ought to be 1 * L for monopolist, 0 for competitive #up ought to be -1 * L for monopolist, 0 for competitive if self.round % 20 == 19: # monopolist uw = 1 * self.L up = -1 * self.L w = 14 + self.L p = self.price error = p + up - w - uw self.L = self.production_controller.update(error) self.log('production', {'error_cum': self.production_controller.error_cum, 'error': error})
def init(self, simulation_parameters, agent_parameters): self.price_controller = PiController(0.001, 0.015, positive=True) self.production_controller = PiController(0.001, 0.015, positive=True) self.price = self.price_1 = 100 self.total_orders = 0 self.dX = np.ones((20, 4)) self.dy = np.ones(20) self.X = np.ones((20, 2)) self.y = np.ones(20) self.L = 4 self.L_1 = 0
def main(argv): # Initialize WiringPi PiController().setup() # Run diagnostics if RUN_DIAGNOSTICS: init() diag() else: # Play game init() play()
def init(self, simulation_parameters, agent_parameters): self.price = self.price_1 = 100 self.cookies_before = self.production_target = self.production_target_1 = 100 self.wage = self.wage_1 = 1 self.price_controller = PiController( 0.01, 0.015, output0=self.price, positive=True) self.production_controller = PiController( 0.01, 0.015, output0=self.production_target, positive=True) self.wage_controller = PiController( 0.01, 0.015, output0=self.wage, positive=True) self.up_regression = UPRegression(memory=500) self.uw_regression = UPRegression(memory=500) self.set_leontief('cookies', {'labor': 1})
class Firm(abce.Agent, abce.Firm, abce.Quote): def init(self, simulation_parameters, agent_parameters): self.price = self.price_1 = 100 self.cookies_before = self.production_target = self.production_target_1 = 100 self.wage = self.wage_1 = 1 self.price_controller = PiController(0.01, 0.015, output0=self.price, positive=True) self.production_controller = PiController(0.01, 0.015, output0=self.production_target, positive=True) self.wage_controller = PiController(0.01, 0.015, output0=self.wage, positive=True) self.up_regression = UPRegression(memory=500) self.uw_regression = UPRegression(memory=500) self.set_leontief('cookies', {'labor': 1}) def quote_hire(self): """ sends a note to the labor market, that it is willing to pay wage """ self.create('money', self.wage * self.production_target) self.quote_buy('labormarket', 0, 'labor', self.possession('money') / self.wage, self.wage) def hire(self): """ hires enough people to meet production_target*. Lets the pi- controller adjust the wage according to the shortag / excess of labor. *but not more than is offered and he can afford """ offer = self.get_offers('labor')[0] self.accept(offer, min(offer.quantity, self.possession('money') / self.wage, self.production_target)) self.wage_1 = self.wage error = self.production_target - offer.quantity self.wage = self.wage_controller.update(error) self.log('wage', {'wage': self.wage, 'error_cum': self.wage_controller.error_cum, 'error': error}) def my_production(self): """ produce using all workers cookies """ self.log('production', self.produce_use_everything()) self.log('cookies', {'inventory': self.possession('cookies')}) def selling(self): """ offers to sell all cookies """ self.offer = self.sell('market', 0, 'cookies', self.possession('cookies'), self.price) def adjust_price(self): """ The prices are adjusted according to the change in inventory. up and uw estimates are updated """ self.total_orders = self.get_messages('demand')[0].content self.log('total', {'orders': self.total_orders}) self.up_regression.fit(self.price, self.price_1, self.production_target, self.production_target_1) self.uw_regression.fit(self.wage, self.wage_1, self.production_target, self.production_target_1) self.price_1 = self.price error = -(self.possession('cookies') - self.cookies_before) self.cookies_before = self.possession('cookies') self.price = self.price_controller.update(error) self.log('price', {'price': self.price, 'error_cum': self.price_controller.error_cum, 'error': error, 'total_orders': self.total_orders}) def adjust_quantity(self): if self.round % 20 == 19 and self.round > 50: w = self.wage p = self.price up = self.up_regression.predict() uw = self.uw_regression.predict() self.production_target_1 = self.production_target error = p + up - (w + uw) #error = p + up * self.production_target - (w + uw * self.production_target) self.production_target = self.production_controller.update(error) self.log('production', {'production': self.production_target, 'error_cum': self.production_controller.error_cum, 'error': error}) self.log('up', {'chosen': up, 'complex_estimation': self.up_regression.up_delta_price, 'simple_estimation': self.up_regression.up_price}) self.log('uw', {'chosen': uw, 'complex_estimation': self.uw_regression.up_delta_price, 'simple_estimation': self.uw_regression.up_price})
class Firm(abce.Agent, abce.Firm): def init(self, simulation_parameters, agent_parameters): self.price = self.price_1 = 100 self.cookies_before = self.production_target = self.production_target_1 = 100 self.wage = self.wage_1 = 1 self.price_controller = PiController(0.01, 0.015, output0=self.price, positive=True) self.production_controller = PiController( 0.01, 0.015, output0=self.production_target, positive=True) self.wage_controller = PiController(0.01, 0.015, output0=self.wage, positive=True) self.up_regression = UPRegression(memory=500) self.uw_regression = UPRegression(memory=500) self.set_leontief('cookies', {'labor': 1}) def quote_hire(self): """ sends a note to the labor market, that it is willing to pay wage """ self.create('money', self.wage * self.production_target) self.quote_buy('labormarket', 0, 'labor', self.possession('money') / self.wage, self.wage) def hire(self): """ hires enough people to meet production_target*. Lets the pi- controller adjust the wage according to the shortag / excess of labor. *but not more than is offered and he can afford """ offer = self.get_offers('labor')[0] self.accept_partial( offer, min(offer['quantity'], self.possession('money') / self.wage, self.production_target)) self.wage_1 = self.wage error = self.production_target - offer['quantity'] self.wage = self.wage_controller.update(error) self.log( 'wage', { 'wage': self.wage, 'error_cum': self.wage_controller.error_cum, 'error': error }) def my_production(self): """ produce using all workers cookies """ self.log('production', self.produce_use_everything()) self.log('cookies', {'inventory': self.possession('cookies')}) def selling(self): """ offers to sell all cookies """ self.offer = self.sell('market', 0, 'cookies', self.possession('cookies'), self.price) def adjust_price(self): """ The prices are adjusted according to the change in inventory. up and uw estimates are updated """ self.total_orders = self.get_messages('demand')[0]['content'] self.log('total', {'orders': self.total_orders}) self.up_regression.fit(self.price, self.price_1, self.production_target, self.production_target_1) self.uw_regression.fit(self.wage, self.wage_1, self.production_target, self.production_target_1) self.price_1 = self.price error = -(self.possession('cookies') - self.cookies_before) self.cookies_before = self.possession('cookies') self.price = self.price_controller.update(error) self.log( 'price', { 'price': self.price, 'error_cum': self.price_controller.error_cum, 'error': error, 'total_orders': self.total_orders }) def adjust_quantity(self): if self.round % 20 == 19 and self.round > 50: w = self.wage p = self.price up = self.up_regression.predict() uw = self.uw_regression.predict() self.production_target_1 = self.production_target error = p + up - (w + uw) #error = p + up * self.production_target - (w + uw * self.production_target) self.production_target = self.production_controller.update(error) self.log( 'production', { 'production': self.production_target, 'error_cum': self.production_controller.error_cum, 'error': error }) self.log( 'up', { 'chosen': up, 'complex_estimation': self.up_regression.up_delta_price, 'simple_estimation': self.up_regression.up_price }) self.log( 'uw', { 'chosen': uw, 'complex_estimation': self.uw_regression.up_delta_price, 'simple_estimation': self.uw_regression.up_price })
def __init__(self, bus_address, pin): self.bus_address = bus_address self.pin = pin + (bus_address - self.BUS_ADDR_0) * 16 self.picontroller = PiController()
class Gpio(object): """ The address of a GPIO pin. @param bus_address: A GPIO bus address. @param pin: A GPIO pin. """ # Bus addresses BUS_ADDR_0 = 0x20 BUS_ADDR_1 = 0x21 BUS_ADDR_2 = 0x22 # Pins GPA0 = 65 GPA1 = 66 GPA2 = 67 GPA3 = 68 GPA4 = 69 GPA5 = 70 GPA6 = 71 GPA7 = 72 GPB0 = 73 GPB1 = 74 GPB2 = 75 GPB3 = 76 GPB4 = 77 GPB5 = 78 GPB6 = 79 GPB7 = 80 def __init__(self, bus_address, pin): self.bus_address = bus_address self.pin = pin + (bus_address - self.BUS_ADDR_0) * 16 self.picontroller = PiController() def high(self): self.picontroller.pin_mode(self.pin, 1) self.picontroller.digital_write(self.pin, 1) def low(self): self.picontroller.pin_mode(self.pin, 1) self.picontroller.digital_write(self.pin, 0) def is_high(self): self.picontroller.pin_mode(self.pin, 0) self.picontroller.pull_up_dn_control(self.pin, 1) return self.picontroller.digital_read(self.pin) == 1 def is_low(self): self.picontroller.pin_mode(self.pin, 0) self.picontroller.pull_up_dn_control(self.pin, 2) return self.picontroller.digital_read(self.pin) == 0
class Firm(abce.Agent, abce.Firm): def init(self, simulation_parameters, agent_parameters): self.price_controller = PiController(0.001, 0.015, positive=True) self.production_controller = PiController(0.001, 0.015, positive=True) self.price = self.price_1 = 100 self.total_orders = 0 self.dX = np.ones((20, 4)) self.dy = np.ones(20) self.X = np.ones((20, 2)) self.y = np.ones(20) self.L = 4 self.L_1 = 0 self.production = 0 def my_production(self): """ produce missing cookies """ self.create("cookies", self.L) self.cookies_before = self.possession("cookies") self.log("cookies", {"created": self.L, "inventory": self.possession("cookies")}) self.y[self.round % 20] = self.price self.dy[self.round % 20] = self.price - self.price_1 def selling(self): self.offer = self.sell("market", 0, "cookies", self.possession("cookies"), self.price) def adjust_price(self): self.total_orders = self.get_messages("demand")[0]["content"] self.log("total", {"orders": self.total_orders}) self.dX[self.round % 20] = [1, self.L, self.price_1, self.L_1] self.X[self.round % 20] = [1, self.L] self.price_1 = self.price error = self.total_orders - self.cookies_before self.price = self.price_controller.update(error) self.log( "price", { "price": self.price, "error_cum": self.price_controller.error_cum, "error": error, "total_orders": self.total_orders, }, ) def adjust_quantity(self): # uw ought to be 1 * L for monopolist, 0 for competitive # up ought to be -1 * L for monopolist, 0 for competitive if self.round % 20 == 19: # monopolist uw = 1 * self.L up = -1 * self.L w = 14 + self.L p = self.price error = p + up - w - uw self.L = self.production_controller.update(error) self.log( "production", {"production": self.production, "error_cum": self.production_controller.error_cum, "error": error}, )