예제 #1
0
파일: model.py 프로젝트: montefesp/resite
def build_model_gurobipy(resite, params: Dict):
    """Model build-up. with gurobipy"""

    from gurobipy import Model
    from resite.models.gurobipy_utils import minimize_cost, capacity_bigger_than_existing, \
        generation_bigger_than_load_proportion_with_slack, create_generation_y_dict

    data = resite.data_dict
    load = data["load"].values
    regions = resite.regions
    technologies = resite.technologies
    tech_points_tuples = list(resite.tech_points_tuples)
    time_slices = define_time_slices(params["time_resolution"],
                                     resite.timestamps)

    cost_dict = get_cost_dict(technologies, resite.timestamps)

    model = Model()

    # - Parameters - #
    load_perc_per_region = dict(zip(regions, params["perc_per_region"]))

    # - Variables - #
    ens_tuples = []
    for r in regions:
        for t in np.arange(len(resite.timestamps)):
            ens_tuples.append((r, t))
    ens = model.addVars(ens_tuples,
                        lb=0.,
                        name=lambda k: 'ens_%s_%s' % (k[0], k[1]))

    # Portion of capacity at each location for each technology
    y = model.addVars(tech_points_tuples,
                      lb=0.,
                      ub=1.,
                      name=lambda k: 'y_%s_%s_%s' % (k[0], k[1], k[2]))
    # Create generation dictionary for building speed up
    generation_potential_df = data["cap_factor_df"] * data["cap_potential_ds"]
    region_generation_y_dict = \
        create_generation_y_dict(y, regions, resite.tech_points_regions_ds, generation_potential_df)

    # - Constraints - #
    # Impose a certain percentage of the load to be covered over each time slice
    generation_bigger_than_load_proportion_with_slack(
        model, region_generation_y_dict, ens, load, regions, time_slices,
        load_perc_per_region)
    # Percentage of capacity installed must be bigger than existing percentage
    existing_cap_percentage_ds = data["existing_cap_ds"].divide(
        data["cap_potential_ds"])
    capacity_bigger_than_existing(model, y, existing_cap_percentage_ds,
                                  tech_points_tuples)

    # - Objective - #
    # Minimize the capacity that is deployed
    obj = minimize_cost(model, y, ens, data["cap_potential_ds"], regions,
                        np.arange(len(resite.timestamps)), cost_dict)

    resite.instance = model
    resite.y = y
    resite.obj = obj
예제 #2
0
def build_model_docplex(resite, cap_per_tech: List[float]):
    """Build model using pyomo"""

    from docplex.mp.model import Model
    from resite.models.docplex_utils import maximize_load_proportion, tech_cap_bigger_than_limit, \
        capacity_bigger_than_existing, generation_bigger_than_load_x, create_generation_y_dict

    data = resite.data_dict
    load = data["load"].values
    tech_points_tuples = list(resite.tech_points_tuples)
    regions = resite.regions
    technologies = resite.technologies
    timestamps_idxs = np.arange(len(resite.timestamps))

    model = Model()

    # - Parameters - #
    required_cap_per_tech = dict(zip(technologies, cap_per_tech))

    # - Variables - #
    # Portion of demand that is met at each time-stamp for each region
    model.x = model.continuous_var_dict(keys=list(
        product(regions, timestamps_idxs)),
                                        lb=0.,
                                        ub=1.,
                                        name=lambda k: 'x_%s_%s' %
                                        (k[0], k[1]))
    # Portion of capacity at each location for each technology
    model.y = model.continuous_var_dict(keys=tech_points_tuples,
                                        lb=0.,
                                        ub=1.,
                                        name=lambda k: 'y_%s_%s_%s' %
                                        (k[0], k[1], k[2]))
    # Create generation dictionary for building speed up
    generation_potential_df = data["cap_factor_df"] * data["cap_potential_ds"]
    region_generation_y_dict = \
        create_generation_y_dict(model, regions, resite.tech_points_regions_ds, generation_potential_df)

    # - Constraints - #
    # Generation must be greater than x percent of the load in each region for each time step
    generation_bigger_than_load_x(model, region_generation_y_dict, load,
                                  regions, timestamps_idxs)
    # Percentage of capacity installed must be bigger than existing percentage
    existing_cap_percentage_ds = data["existing_cap_ds"].divide(
        data["cap_potential_ds"])
    capacity_bigger_than_existing(model, existing_cap_percentage_ds,
                                  tech_points_tuples)
    # Impose a certain installed capacity per technology
    tech_cap_bigger_than_limit(model, data["cap_potential_ds"],
                               resite.tech_points_dict, technologies,
                               required_cap_per_tech)

    # - Objective - #
    # Maximize the proportion of load that is satisfied
    maximize_load_proportion(model, regions, timestamps_idxs)

    resite.instance = model
예제 #3
0
파일: model.py 프로젝트: montefesp/resite
def build_model_pyomo(resite, params: Dict):
    """Model build-up using pyomo"""

    from pyomo.environ import ConcreteModel, NonNegativeReals, Var
    from resite.models.pyomo_utils import capacity_bigger_than_existing, minimize_cost, \
        generation_bigger_than_load_proportion_with_slack, create_generation_y_dict

    data = resite.data_dict
    load = data["load"].values
    regions = resite.regions
    technologies = resite.technologies
    tech_points_tuples = list(resite.tech_points_tuples)
    time_slices = define_time_slices(params["time_resolution"],
                                     resite.timestamps)

    cost_dict = get_cost_dict(technologies, resite.timestamps)

    model = ConcreteModel()

    # - Parameters - #
    covered_load_perc_per_region = dict(zip(regions,
                                            params["perc_per_region"]))

    # - Variables - #
    model.ens = Var(list(regions),
                    list(np.arange(len(resite.timestamps))),
                    within=NonNegativeReals)

    # Portion of capacity at each location for each technology
    model.y = Var(tech_points_tuples, within=NonNegativeReals, bounds=(0, 1))
    # Create generation dictionary for building speed up
    generation_potential_df = data["cap_factor_df"] * data["cap_potential_ds"]
    region_generation_y_dict = \
        create_generation_y_dict(model, regions, resite.tech_points_regions_ds, generation_potential_df)

    # - Constraints - #
    # Impose a certain percentage of the load to be covered over each time slice
    model.generation_check =\
        generation_bigger_than_load_proportion_with_slack(model, region_generation_y_dict, load, regions,
                                                          time_slices, covered_load_perc_per_region)
    # Percentage of capacity installed must be bigger than existing percentage
    existing_cap_percentage_ds = data["existing_cap_ds"].divide(
        data["cap_potential_ds"])
    model.potential_constraint = capacity_bigger_than_existing(
        model, existing_cap_percentage_ds, tech_points_tuples)

    # - Objective - #
    # Minimize the capacity that is deployed
    model.objective = minimize_cost(model, data["cap_potential_ds"], regions,
                                    np.arange(len(resite.timestamps)),
                                    cost_dict)

    resite.instance = model
예제 #4
0
def build_model_pyomo(resite, cap_per_tech: List[float]):
    """Build model using pyomo"""

    from pyomo.environ import ConcreteModel, Var, NonNegativeReals
    from resite.models.pyomo_utils import tech_cap_bigger_than_limit, maximize_load_proportion, \
        generation_bigger_than_load_x, capacity_bigger_than_existing, create_generation_y_dict

    data = resite.data_dict
    load = data["load"].values
    tech_points_tuples = list(resite.tech_points_tuples)
    regions = resite.regions
    technologies = resite.technologies
    timestamps_idxs = np.arange(len(resite.timestamps))

    model = ConcreteModel()

    # - Parameters - #
    required_cap_per_tech = dict(zip(technologies, cap_per_tech))

    # - Variables - #
    # Portion of demand that is met at each time-stamp for each region
    model.x = Var(regions,
                  timestamps_idxs,
                  within=NonNegativeReals,
                  bounds=(0, 1))
    # Portion of capacity at each location for each technology
    model.y = Var(tech_points_tuples, within=NonNegativeReals, bounds=(0, 1))
    # Create generation dictionary for building speed up
    generation_potential_df = data["cap_factor_df"] * data["cap_potential_ds"]
    region_generation_y_dict = \
        create_generation_y_dict(model, regions, resite.tech_points_regions_ds, generation_potential_df)

    # - Constraints - #
    # Generation must be greater than x percent of the load in each region for each time step
    model.generation_check = generation_bigger_than_load_x(
        model, region_generation_y_dict, load, regions, timestamps_idxs)
    # Percentage of capacity installed must be bigger than existing percentage
    existing_cap_percentage_ds = data["existing_cap_ds"].divide(
        data["cap_potential_ds"])
    model.potential_constraint = capacity_bigger_than_existing(
        model, existing_cap_percentage_ds, tech_points_tuples)
    # The capacity installed for each technology must be superior to a certain limit
    model.capacity_target = tech_cap_bigger_than_limit(
        model, data["cap_potential_ds"], resite.tech_points_dict, technologies,
        required_cap_per_tech)

    # - Objective - #
    # Maximize the proportion of load that is satisfied
    model.objective = maximize_load_proportion(model, regions, timestamps_idxs)

    resite.instance = model
예제 #5
0
def build_model_docplex(resite, params: Dict):
    """Model build-up with docplex"""

    from docplex.mp.model import Model
    from resite.models.docplex_utils import minimize_deployed_capacity, capacity_bigger_than_existing, \
        generation_bigger_than_load_proportion, create_generation_y_dict

    data = resite.data_dict
    load = data["load"].values
    regions = resite.regions
    tech_points_tuples = list(resite.tech_points_tuples)
    time_slices = define_time_slices(params["time_resolution"],
                                     resite.timestamps)

    model = Model()

    # - Parameters - #
    load_perc_per_region = dict(zip(regions, params["perc_per_region"]))

    # - Variables - #
    # Portion of capacity at each location for each technology
    model.y = model.continuous_var_dict(keys=tech_points_tuples,
                                        lb=0.,
                                        ub=1.,
                                        name=lambda k: 'y_%s_%s_%s' %
                                        (k[0], k[1], k[2]))
    # Create generation dictionary for building speed up
    generation_potential_df = data["cap_factor_df"] * data["cap_potential_ds"]
    region_generation_y_dict = \
        create_generation_y_dict(model, regions, resite.tech_points_regions_ds, generation_potential_df)

    # - Constraints - #
    # Impose a certain percentage of the load to be covered over each time slice
    generation_bigger_than_load_proportion(model, region_generation_y_dict,
                                           load, regions, time_slices,
                                           load_perc_per_region)
    # Percentage of capacity installed must be bigger than existing percentage
    existing_cap_percentage_ds = data["existing_cap_ds"].divide(
        data["cap_potential_ds"])
    capacity_bigger_than_existing(model, existing_cap_percentage_ds,
                                  tech_points_tuples)

    # - Objective - #
    # Minimize the capacity that is deployed
    minimize_deployed_capacity(model, data["cap_potential_ds"])

    resite.instance = model