コード例 #1
0
    def run(self):

        sim = Simulator(self.location, self.year_choice, Windturbine(5), terrain_factor = self.terrain_factor )
        sim.latitude = self.latitude
        sim.longitude = self.longitude

        if self.store_wt_out:
            P_wt,_ = sim.calc_wind(self.windfeatures)
        else:
            P_wt = 0
        if self.store_sp_out:
            P_sp,_ = sim.calc_solar(Az=self.solarfeatures[2::3], Inc=self.solarfeatures[1::3],sp_area=self.solarfeatures[0::3], sp_eff=self.sp_eff)
        else:
            P_sp = 0
        if self.store_total_out:
            P_tot,_ = sim.calc_total_power(self.solarfeatures, self.windfeatures, self.sp_eff)
        else:
            P_tot = 0

        data = {'Pwt':P_wt,'Psp': P_sp,'Ptot': P_tot}

        self.write_data(data, self.filename)

        evt = SimDoneEvent(myEVT_SIMDONE, -1, filename=self.filename)
        wx.PostEvent(self.parent, evt)
コード例 #2
0
            wm_price = 5350000
        elif (wm_type == 1):
            wm_price = 535000
        elif (wm_type == 4):
            wm_price = 3210000
        else:
            wm_price = 0
    return wm_price


# code example to test if storage and deficit calculations are working
if __name__ == '__main__':
    from Simulator import Simulator
    from generators import Windturbine

    turbine = Windturbine(4)
    sim = Simulator('formatted_data.xls', '1%overschrijding-B.2', turbine)

    sp_price_1 = 450
    storage_price_1 = 1

    print('Training: 1')
    cost_calculator = CostCalculator(sp_price_1, storage_price_1, 6000, 1000000, 1000)
    n_turb = 10
    solar_feat = list([107806, 0, 0, 24175, 0, 0, 19751, 0, 0, 10000, 0, 0, ])
    wind_feat = list([n_turb, 0.12])
    output = sim.calc_total_power(solar_feat, wind_feat)
    stats = cost_calculator.get_stats(output, np.sum(solar_feat[0::3]), 4, n_turb)
    print('Stats: ')
    print(stats)
コード例 #3
0
def train(n_generations,
          group_size,
          surface_min,
          surface_max,
          angle_min,
          angle_max,
          orientation_min,
          orientation_max,
          model_name=None,
          load=False,
          counter=None,
          directory=None,
          mutationPercentage=50,
          target_kw=6000,
          cost_calculator=None,
          simulator=None,
          windturbineType=4,
          N_WIND_MAX=100,
          tr_rating=0.12,
          sp_efficiency=16,
          toScreen=False):
    """train genetic algorithm"""
    genetic_algorithm = GeneticAlgorith(mutationPercentage, 150, 6, 2, 2, True)

    # parameter 2 kosten voor accu per kWh
    if cost_calculator is None:
        cost_calculator = CostCalculator(190, 400, target_kw, 1000000, 1000,
                                         3210000)

    turbine = Windturbine(windturbineType)

    if simulator is None:
        location = Location("NEN")
        simulator = Simulator(location, '2018', turbine)

    saver = PopulationSaver(model_name, load)

    if load:
        group_values = saver.load()
    else:
        # generate random values in valid range
        solar_values = np.random.rand(group_size, N_SOLAR_FEATURES)
        solar_values[:, 0::3] *= (surface_max - surface_min)
        solar_values[:, 0::3] += surface_min
        solar_values[:, 1::3] *= (angle_max - angle_min)
        solar_values[:, 1::3] += angle_min
        solar_values[:, 2::3] *= (orientation_max - orientation_min)
        solar_values[:, 2::3] += orientation_min
        wind_values = np.random.rand(group_size, N_WIND_FEATURES)
        wind_values[0] *= N_WIND_MAX
        wind_values[1] *= (WIND_HEIGHT_MAX - WIND_HEIGHT_MIN)
        wind_values[1] += WIND_HEIGHT_MIN
        group_values = np.concatenate((solar_values, wind_values),
                                      axis=1)  # concatenate on features

    # prepare min and max arrays to truncate values later
    highest_allowed = np.zeros_like(group_values)
    lowest_allowed = np.zeros_like(group_values)
    highest_allowed[:, 0:N_SOLAR_FEATURES:3] = surface_max
    lowest_allowed[:, 0:N_SOLAR_FEATURES:3] = surface_min
    highest_allowed[:, 1:N_SOLAR_FEATURES:3] = angle_max
    lowest_allowed[:, 1:N_SOLAR_FEATURES:3] = angle_min
    highest_allowed[:, 2:N_SOLAR_FEATURES:3] = orientation_max
    lowest_allowed[:, 2:N_SOLAR_FEATURES:3] = orientation_min
    highest_allowed[:, -2] = N_WIND_MAX
    lowest_allowed[:, -2] = 0
    highest_allowed[:, -1] = WIND_HEIGHT_MAX
    lowest_allowed[:, -1] = WIND_HEIGHT_MIN

    last_generation = n_generations - 1
    best_gen = 0
    cost_temp = 1e20

    for generation in range(saver.generation, n_generations):

        if generation == n_generations - 20:
            genetic_algorithm.set_mutation(mutationPercentage / 2)
        elif generation == n_generations - 10:
            genetic_algorithm.set_mutation(mutationPercentage / 4)

        cost_array = np.zeros(group_size)

        if toScreen:
            print('finished simulation 0 of {}'.format(group_size), end='\r')

        for i in range(group_size):
            current_row = group_values[i]
            # selecting windturbine type

            wm_type = 4
            n_Turbines = int(current_row[-2])
            turbine_height = int(current_row[-1])
            # run simulink
            energy_production, energy_split = simulator.calc_total_power(
                current_row[:N_SOLAR_FEATURES],
                list([n_Turbines, turbine_height]), sp_efficiency)
            # energy_production = simulator.calc_total_power(current_row[:N_SOLAR_FEATURES], list([n_Turbines, turbine_height]), sp_efficiency)
            # run cost calculator
            sp_sm = np.sum(current_row[0:N_SOLAR_FEATURES:3])
            cost_array[i] = cost_calculator.calculate_cost(
                energy_production, sp_sm, wm_type,
                n_Turbines)  # add turbine later
            # print progress
            if toScreen:
                print('finished simulation {} of {}'.format(i + 1, group_size),
                      end='\r')
        # log and print progress
        best = genetic_algorithm.get_best(group_values, cost_array)
        saver.log('generation:',
                  saver.generation,
                  'mean_cost:',
                  np.mean(cost_array),
                  'min_cost:',
                  np.min(cost_array),
                  to_screen=toScreen)
        # store intermediate result

        if np.min(cost_array) < cost_temp:
            cost_temp = np.min(cost_array)
            best_gen = best

        saver.save_best(best)

        if directory is not None:
            directory.value = saver.path
        if counter is not None:
            counter.value = counter.value + 1

        # quit when done
        if generation == last_generation:
            return best_gen
        # run genetic algorithm
        group_values = genetic_algorithm.generate_new_population(
            group_values, cost_array)
        # remove illegal values
        group_values = np.minimum(group_values, highest_allowed)
        group_values = np.maximum(group_values, lowest_allowed)
        # store intermediate population
        saver.save(group_values)
コード例 #4
0
                           -45,
                           45,
                           mutationPercentage=mutationrate,
                           target_kw=energy_demand,
                           cost_calculator=cost_calc,
                           simulator=sim,
                           windturbineType=TURBINETYPE,
                           N_WIND_MAX=7,
                           tr_rating=loc_data.terrain,
                           sp_efficiency=16)

        best_pick = best_array[0]
        best_solar = best_pick[:12]
        best_wind = best_pick[-2:]

        best_pick_power, _ = sim.calc_total_power(best_solar, best_wind, 16)
        total_solar_sm = np.sum(best_solar[0::3])
        costings = cost_calc.calculate_cost(best_pick_power, total_solar_sm,
                                            TURBINETYPE, int(best_wind[0]))
        stats = cost_calc.get_stats(best_pick_power, total_solar_sm,
                                    TURBINETYPE, int(best_wind[0]))

        sol_power, _ = sim.calc_solar(Az=best_solar[2::3],
                                      Inc=best_solar[1::3],
                                      sp_area=best_solar[0::3])
        win_power, _ = sim.calc_wind(best_wind)
        win_power_total = np.sum(win_power)
        sol_power_total = np.sum(sol_power)

        inputs = {
            'Name': loc_data.name,