Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constraint_sets['techs_energy_capacity_systemwide_constraint'] = [
i for i in sets.techs
if model_run.get_key('techs.{}.constraints.energy_cap_max_systemwide'.format(i), None)
or model_run.get_key('techs.{}.constraints.energy_cap_equals_systemwide'.format(i), None)
]
# dispatch.py
constraint_sets['loc_tech_carriers_carrier_production_max_constraint'] = [
i for i in sets.loc_tech_carriers_prod
if i not in sets.loc_tech_carriers_conversion_plus
and i.rsplit('::', 1)[0] not in sets.loc_techs_milp
]
constraint_sets['loc_tech_carriers_carrier_production_min_constraint'] = [
i for i in sets.loc_tech_carriers_prod
if i not in sets.loc_tech_carriers_conversion_plus
and constraint_exists(model_run, i.rsplit('::', 1)[0], 'constraints.energy_cap_min_use')
and i.rsplit('::', 1)[0] not in sets.loc_techs_milp
]
constraint_sets['loc_tech_carriers_carrier_consumption_max_constraint'] = [
i for i in sets.loc_tech_carriers_con
if i.rsplit('::', 1)[0] in sets.loc_techs_demand +
sets.loc_techs_storage + sets.loc_techs_transmission
and i.rsplit('::', 1)[0] not in sets.loc_techs_milp
]
constraint_sets['loc_techs_resource_max_constraint'] = sets.loc_techs_supply_plus
constraint_sets['loc_tech_carriers_ramping_constraint'] = [
i for i in sets.loc_tech_carriers_prod
if i.rsplit('::', 1)[0] in sets.loc_techs_ramping
]
# clustering-specific dispatch constraints
if (model_run.model.get_key('time.function', None) == 'apply_clustering' and
model_run.model.get_key('time.function_options.storage_inter_cluster', True)):
if i.rsplit('::', 1)[0] in sets.loc_techs_demand +
sets.loc_techs_storage + sets.loc_techs_transmission
and i.rsplit('::', 1)[0] in sets.loc_techs_milp
]
constraint_sets['loc_techs_energy_capacity_units_milp_constraint'] = [
i for i in sets.loc_techs_milp
if constraint_exists(model_run, i, 'constraints.energy_cap_per_unit')
is not None
]
constraint_sets['loc_techs_storage_capacity_units_milp_constraint'] = [
i for i in sets.loc_techs_milp if i in sets.loc_techs_store
]
constraint_sets['loc_techs_energy_capacity_max_purchase_milp_constraint'] = [
i for i in sets.loc_techs_purchase
if (constraint_exists(model_run, i, 'constraints.energy_cap_equals') is not None
or (constraint_exists(model_run, i, 'constraints.energy_cap_max') is not None
and constraint_exists(model_run, i, 'constraints.energy_cap_max') != np.inf))
]
constraint_sets['loc_techs_energy_capacity_min_purchase_milp_constraint'] = [
i for i in sets.loc_techs_purchase
if (not constraint_exists(model_run, i, 'constraints.energy_cap_equals')
and constraint_exists(model_run, i, 'constraints.energy_cap_min'))
]
constraint_sets['loc_techs_storage_capacity_max_purchase_milp_constraint'] = [
i for i in set(sets.loc_techs_purchase).intersection(sets.loc_techs_store)
if (constraint_exists(model_run, i, 'constraints.storage_cap_equals') is not None
or (constraint_exists(model_run, i, 'constraints.storage_cap_max') is not None
and constraint_exists(model_run, i, 'constraints.storage_cap_max') != np.inf))
]
constraint_sets['loc_techs_storage_capacity_min_purchase_milp_constraint'] = [
i for i in set(sets.loc_techs_purchase).intersection(sets.loc_techs_store)
if (not constraint_exists(model_run, i, 'constraints.storage_cap_equals')
and i.rsplit('::', 1)[0] in sets.loc_techs_milp
]
constraint_sets['loc_techs_carrier_production_min_conversion_plus_milp_constraint'] = [
i for i in sets.loc_techs_conversion_plus
if constraint_exists(model_run, i, 'constraints.energy_cap_min_use')
and i in sets.loc_techs_milp
]
constraint_sets['loc_tech_carriers_carrier_consumption_max_milp_constraint'] = [
i for i in sets.loc_tech_carriers_con
if i.rsplit('::', 1)[0] in sets.loc_techs_demand +
sets.loc_techs_storage + sets.loc_techs_transmission
and i.rsplit('::', 1)[0] in sets.loc_techs_milp
]
constraint_sets['loc_techs_energy_capacity_units_milp_constraint'] = [
i for i in sets.loc_techs_milp
if constraint_exists(model_run, i, 'constraints.energy_cap_per_unit')
is not None
]
constraint_sets['loc_techs_storage_capacity_units_milp_constraint'] = [
i for i in sets.loc_techs_milp if i in sets.loc_techs_store
]
constraint_sets['loc_techs_energy_capacity_max_purchase_milp_constraint'] = [
i for i in sets.loc_techs_purchase
if (constraint_exists(model_run, i, 'constraints.energy_cap_equals') is not None
or (constraint_exists(model_run, i, 'constraints.energy_cap_max') is not None
and constraint_exists(model_run, i, 'constraints.energy_cap_max') != np.inf))
]
constraint_sets['loc_techs_energy_capacity_min_purchase_milp_constraint'] = [
i for i in sets.loc_techs_purchase
if (not constraint_exists(model_run, i, 'constraints.energy_cap_equals')
and constraint_exists(model_run, i, 'constraints.energy_cap_min'))
]
i for i in sets.loc_techs_milp
if constraint_exists(model_run, i, 'constraints.energy_cap_per_unit')
is not None
]
constraint_sets['loc_techs_storage_capacity_units_milp_constraint'] = [
i for i in sets.loc_techs_milp if i in sets.loc_techs_store
]
constraint_sets['loc_techs_energy_capacity_max_purchase_milp_constraint'] = [
i for i in sets.loc_techs_purchase
if (constraint_exists(model_run, i, 'constraints.energy_cap_equals') is not None
or (constraint_exists(model_run, i, 'constraints.energy_cap_max') is not None
and constraint_exists(model_run, i, 'constraints.energy_cap_max') != np.inf))
]
constraint_sets['loc_techs_energy_capacity_min_purchase_milp_constraint'] = [
i for i in sets.loc_techs_purchase
if (not constraint_exists(model_run, i, 'constraints.energy_cap_equals')
and constraint_exists(model_run, i, 'constraints.energy_cap_min'))
]
constraint_sets['loc_techs_storage_capacity_max_purchase_milp_constraint'] = [
i for i in set(sets.loc_techs_purchase).intersection(sets.loc_techs_store)
if (constraint_exists(model_run, i, 'constraints.storage_cap_equals') is not None
or (constraint_exists(model_run, i, 'constraints.storage_cap_max') is not None
and constraint_exists(model_run, i, 'constraints.storage_cap_max') != np.inf))
]
constraint_sets['loc_techs_storage_capacity_min_purchase_milp_constraint'] = [
i for i in set(sets.loc_techs_purchase).intersection(sets.loc_techs_store)
if (not constraint_exists(model_run, i, 'constraints.storage_cap_equals')
and constraint_exists(model_run, i, 'constraints.storage_cap_min'))
]
constraint_sets['loc_techs_update_costs_investment_units_milp_constraint'] = [
i for i in sets.loc_techs_milp
if i in sets.loc_techs_investment_cost and
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_min_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_min')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_max_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_max')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_resource_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if any([
constraint_exists(model_run, i, 'constraints.resource_cap_equals'),
constraint_exists(model_run, i, 'constraints.resource_cap_max'),
constraint_exists(model_run, i, 'constraints.resource_cap_min')
])
]
constraint_sets['loc_techs_resource_capacity_equals_energy_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if constraint_exists(model_run, i, 'constraints.resource_cap_equals_energy_cap')
]
constraint_sets['loc_techs_resource_area_constraint'] = sets.loc_techs_area
constraint_sets['loc_techs_resource_area_per_energy_capacity_constraint'] = [
i for i in sets.loc_techs_area
if constraint_exists(model_run, i, 'constraints.resource_area_per_energy_cap')
is not None
]
constraint_sets['locs_resource_area_capacity_per_loc_constraint'] = [
i for i in sets.locs
]
constraint_sets['loc_techs_energy_capacity_storage_min_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_min')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_max_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_max')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_resource_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if any([
constraint_exists(model_run, i, 'constraints.resource_cap_equals'),
constraint_exists(model_run, i, 'constraints.resource_cap_max'),
constraint_exists(model_run, i, 'constraints.resource_cap_min')
])
]
constraint_sets['loc_techs_resource_capacity_equals_energy_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if constraint_exists(model_run, i, 'constraints.resource_cap_equals_energy_cap')
]
constraint_sets['loc_techs_resource_area_constraint'] = sets.loc_techs_area
constraint_sets['loc_techs_resource_area_per_energy_capacity_constraint'] = [
i for i in sets.loc_techs_area
if constraint_exists(model_run, i, 'constraints.resource_area_per_energy_cap')
is not None
]
constraint_sets['locs_resource_area_capacity_per_loc_constraint'] = [
i for i in sets.locs
if model_run.locations[i].get_key('available_area', None) is not None
# capacity.py
constraint_sets['loc_techs_storage_capacity_constraint'] = [
i for i in sets.loc_techs_store if i not in sets.loc_techs_milp
]
constraint_sets['loc_techs_energy_capacity_storage_constraint_old'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.charge_rate')
]
constraint_sets['loc_techs_energy_capacity_storage_equals_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_min_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_min')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_max_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_max')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_resource_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if any([
constraint_exists(model_run, i, 'constraints.resource_cap_equals'),
constraint_exists(model_run, i, 'constraints.resource_cap_max'),
constraint_exists(model_run, i, 'constraints.resource_cap_min')
])
]
constraint_sets['loc_techs_resource_capacity_equals_energy_capacity_constraint'] = [
sets = model_run.sets
## From here on, everything is a `key=value` pair within a dictionary
constraint_sets = dict()
# energy_balance.py
constraint_sets['loc_carriers_system_balance_constraint'] = sets.loc_carriers
constraint_sets['loc_techs_balance_supply_constraint'] = sets.loc_techs_finite_resource_supply
constraint_sets['loc_techs_balance_demand_constraint'] = sets.loc_techs_finite_resource_demand
constraint_sets['loc_techs_resource_availability_supply_plus_constraint'] = sets.loc_techs_finite_resource_supply_plus
constraint_sets['loc_techs_balance_transmission_constraint'] = sets.loc_techs_transmission
constraint_sets['loc_techs_balance_supply_plus_constraint'] = sets.loc_techs_supply_plus
constraint_sets['loc_techs_balance_storage_constraint'] = sets.loc_techs_storage
if model_run.run.cyclic_storage is True:
constraint_sets['loc_techs_storage_initial_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.storage_initial') is not None
]
constraint_sets['loc_techs_storage_discharge_depth'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.storage_discharge_depth')
]
constraint_sets['carriers_reserve_margin_constraint'] = [
i for i in sets.carriers
if i in model_run.model.get_key('reserve_margin', {}).keys()
]
# clustering-specific balance constraints
if (model_run.model.get_key('time.function', None) == 'apply_clustering' and
model_run.model.get_key('time.function_options.storage_inter_cluster', True)):
set_name = 'loc_techs_balance_storage_inter_cluster_constraint'
constraint_sets[set_name] = sets.loc_techs_store
# costs.py
constraint_sets['loc_techs_energy_capacity_storage_max_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_max')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_resource_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if any([
constraint_exists(model_run, i, 'constraints.resource_cap_equals'),
constraint_exists(model_run, i, 'constraints.resource_cap_max'),
constraint_exists(model_run, i, 'constraints.resource_cap_min')
])
]
constraint_sets['loc_techs_resource_capacity_equals_energy_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if constraint_exists(model_run, i, 'constraints.resource_cap_equals_energy_cap')
]
constraint_sets['loc_techs_resource_area_constraint'] = sets.loc_techs_area
constraint_sets['loc_techs_resource_area_per_energy_capacity_constraint'] = [
i for i in sets.loc_techs_area
if constraint_exists(model_run, i, 'constraints.resource_area_per_energy_cap')
is not None
]
constraint_sets['locs_resource_area_capacity_per_loc_constraint'] = [
i for i in sets.locs
if model_run.locations[i].get_key('available_area', None) is not None
and sets.loc_techs_area
]
constraint_sets['loc_techs_energy_capacity_constraint'] = [
i for i in sets.loc_techs
if i not in sets.loc_techs_milp + sets.loc_techs_purchase
]
constraint_sets['loc_techs_energy_capacity_storage_constraint_old'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.charge_rate')
]
constraint_sets['loc_techs_energy_capacity_storage_equals_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_min_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_min')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_energy_capacity_storage_max_constraint'] = [
i for i in sets.loc_techs_store
if constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_max')
and not constraint_exists(model_run, i, 'constraints.energy_cap_per_storage_cap_equals')
]
constraint_sets['loc_techs_resource_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if any([
constraint_exists(model_run, i, 'constraints.resource_cap_equals'),
constraint_exists(model_run, i, 'constraints.resource_cap_max'),
constraint_exists(model_run, i, 'constraints.resource_cap_min')
])
]
constraint_sets['loc_techs_resource_capacity_equals_energy_capacity_constraint'] = [
i for i in sets.loc_techs_finite_resource_supply_plus
if constraint_exists(model_run, i, 'constraints.resource_cap_equals_energy_cap')
]
constraint_sets['loc_techs_resource_area_constraint'] = sets.loc_techs_area
constraint_sets['loc_techs_resource_area_per_energy_capacity_constraint'] = [