def decide_provider(self, iteration, global_price): # self.reset_adj_matrix() for t in range(Constants.day_hours.size): price = global_price[:, t] changing_customers = [] for i in range(self.blocks.size): # Get list of changing customers of block i changing_customers_list, new_producer = self.blocks[ i].decide_provider(price, t, iteration) # Generate list of same number of tuples as number of changing customers # with first element being the block, second being one customer and third the new provider changing_customers = changing_customers + \ list(zip([i] * len(changing_customers_list), changing_customers_list, [new_producer] * len(changing_customers_list))) # Shuffle them so to get a random order in which they will change np.random.shuffle(changing_customers) for change_tuple in changing_customers: # Account change try: self.blocks[change_tuple[0]].change_provider( change_tuple[1], change_tuple[2], t) except: print(iteration, t) exit(1) # Recompute price possible_providers = self.blocks[ change_tuple[0]].possible_providers total_demand = np.zeros(possible_providers.size) for prod in range(total_demand.size): total_demand[prod] = self.get_demand_by_prod( iteration, possible_providers[prod], [t]) new_price = Cost.energy_price(total_demand, self.num_total_households) # Take new producer and block and update adjacency matrix # self.update_adj_matrix(t, change_tuple[2], change_tuple[0]) # If after change, prices are still different or the cheapest producer is the same, we assume # that customers will continue changing provider. Else, stop process. new_cheap_prod = np.where(new_price == np.min(new_price)) if all(new_price == new_price[0]) or \ np.all(np.where(change_tuple[2] == possible_providers)[0] != new_cheap_prod): break self.update_adj_matrix(t) return
def get_initial_bids(self, iteration, t): demand = self.demand.total_house_demand[iteration, :, t] return Cost.energy_price(demand, self.num_households)