def record(self, time, power, begin_comp, end_comp): # records hash of [f33_file, begincomphash, time, power, endcomphas] l = [self.f33_file, str(time), str(power)] # boc: """ boc = l + ['boc'] print(boc) for iso, frac in begin_comp.items(): row = boc + [str(iso), str(frac)] lib.record_time_series('depletion_history', self, ','.join(row)) eoc = l + ['eoc'] print(eoc) for iso, frac in end_comp.items(): row = eoc + [str(iso), str(frac)] lib.record_time_series('depletion_history', self, ','.join(row)) """ s = ','.join(l) + ',' for iso, frac in begin_comp.items(): s += str(iso) + ':' + str(frac) + ';' s = s[:-1] + ',' for iso, frac in end_comp.items(): s += str(iso) + ':' + str(frac) + ';' s = s[:-1] print(s) lib.record_time_series('depletion_history', self, s) print('done')
def decision(self): """ This is the tock method for decision the institution. Here the institution determines the difference in supply and demand and makes the the decision to deploy facilities or not. """ time = self.context.time for commod, proto_dict in self.commodity_dict.items(): diff, supply, demand = self.calc_diff(commod, time) lib.record_time_series('calc_supply' + commod, self, supply) lib.record_time_series('calc_demand' + commod, self, demand) if diff < 0: deploy_dict = solver.deploy_solver(self.commodity_supply, self.commodity_dict, commod, diff, time) for proto, num in deploy_dict.items(): for i in range(num): self.context.schedule_build(self, proto) if self.record: out_text = "Time " + str(time) + \ " Deployed " + str(len(self.children)) out_text += " supply " + \ str(self.commodity_supply[commod][time]) out_text += " demand " + \ str(self.commodity_demand[commod][time]) + "\n" with open(commod + ".txt", 'a') as f: f.write(out_text)
def decision(self): """ This is the tock method for decision the institution. Here the institution determines the difference in supply and capacity and makes the the decision to deploy facilities or not. """ time = self.context.time for commod, proto_dict in self.commodity_dict.items(): diff, capacity, supply = self.calc_diff(commod, time) lib.record_time_series('calc_supply' + commod, self, supply) lib.record_time_series('calc_capacity' + commod, self, capacity) if diff < 0: if self.installed_cap: deploy_dict, self.commodity_dict = solver.deploy_solver( self.installed_capacity, self.commodity_dict, commod, diff, time) else: deploy_dict, self.commodity_dict = solver.deploy_solver( self.commodity_supply, self.commodity_dict, commod, diff, time) for proto, num in deploy_dict.items(): for i in range(num): self.context.schedule_build(self, proto) # update installed capacity dict self.installed_capacity[commod][time + 1] = \ self.installed_capacity[commod][time] for proto, num in deploy_dict.items(): self.installed_capacity[commod][time + 1] += \ self.commodity_dict[commod][proto]['cap'] * num else: self.installed_capacity[commod][ time + 1] = self.installed_capacity[commod][time] os_limit = self.commod_mins[commod] * self.os_int if diff > os_limit: self.commod_os[commod] += 1 else: self.commod_os[commod] = 0 if diff > os_limit and self.commod_os[commod] > self.os_time: solver.decommission_oldest(self, self.commodity_dict[commod], diff, commod, time) if self.record: out_text = "Time " + str(time) + \ " Deployed " + str(len(self.children)) out_text += " capacity " + \ str(self.commodity_capacity[commod][time]) out_text += " supply " + \ str(self.commodity_supply[commod][time]) + "\n" with open(commod + ".txt", 'a') as f: f.write(out_text) for child in self.children: if child.exit_time == time: itscommod = self.fac_commod[child.prototype] self.installed_capacity[itscommod][ time + 1] -= self.commodity_dict[itscommod][ child.prototype]['cap']
def tick(self): """ This method defines the tick behavior for this archetype. The demand and supply rates are calculated, and those are recorded in time series. """ self.demand_t += 1 self.supply_t += 1 supply_rate = random.uniform(self.supply_rate_min, self.supply_rate_max) demand_rate = random.uniform(self.demand_rate_min, self.demand_rate_max) if self.supply_t == -1 or self.supply_t is self.supply_ts: lib.record_time_series(self.supply_commod, self, supply_rate) self.supply_t = 0 else: lib.record_time_series(self.supply_commod, self, 0.) if self.demand_t == -1 or self.demand_t is self.demand_ts: lib.record_time_series(self.demand_commod, self, demand_rate) self.demand_t = 0 else: lib.record_time_series(self.demand_commod, self, 0.)
def tick(self): lib.record_time_series(lib.POWER, self, 10.) print("TICK")
def produce_power(self, produce=True): if produce: lib.record_time_series(lib.POWER, self, float(self.power_cap)) else: lib.record_time_series(lib.POWER, self, 0)
def tick(self): rate = random.uniform(self.production_rate_min, self.production_rate_max) print("Agent {0} {1} {2}".format(self.id, self.production_rate_min, rate)) lib.record_time_series(self.commodity, self, rate)