-
Notifications
You must be signed in to change notification settings - Fork 106
added capacity tariff feature #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideImplements a configurable capacity tariff feature in the optimization workflow, including runtime parameter handling, objective/constraints integration, and reporting of tariff-related results. Sequence diagram for capacity tariff-aware optimization runsequenceDiagram
actor User
participant ClientAPI
participant RuntimeParamsProcessor
participant Optimization
participant LPModel
User ->> ClientAPI: Submit optimization request with runtimeparams
ClientAPI ->> RuntimeParamsProcessor: treat_runtimeparams(runtimeparams, params, forecast_dates, logger)
RuntimeParamsProcessor ->> RuntimeParamsProcessor: Derive set_capacity_tariff
RuntimeParamsProcessor ->> RuntimeParamsProcessor: Derive capacity_tariff_threshold (scalar or list)
RuntimeParamsProcessor ->> RuntimeParamsProcessor: Derive capacity_tariff_penalty
RuntimeParamsProcessor ->> ClientAPI: Updated params.optim_conf
ClientAPI ->> Optimization: __init__(optim_conf, plant_conf, logger, lp_solver, lp_solver_path, num_threads)
Optimization ->> Optimization: Read set_capacity_tariff
Optimization ->> Optimization: Initialize capacity_threshold, capacity_threshold_is_list, capacity_penalty
ClientAPI ->> Optimization: perform_optimization(data_opt, def_total_timestep, def_total_hours)
Optimization ->> Optimization: Prepare capacity_threshold_array if list
Optimization ->> Optimization: Validate threshold length vs data_opt index
Optimization ->> Optimization: Build objective (base terms)
Optimization ->> Optimization: Create P_excess[i] variables
Optimization ->> Optimization: Add capacity_penalty_term to objective
Optimization ->> LPModel: setObjective(objective)
Optimization ->> LPModel: Add capacity tariff constraints
Optimization ->> LPModel: solve()
LPModel -->> Optimization: Solution with P_excess[i].varValue
Optimization ->> Optimization: Build excess_values and penalty_values
Optimization ->> Optimization: Add capacity_threshold, P_excess, capacity_penalty_cost to opt_tp
Optimization ->> Optimization: Compute cost_fun_profit including penalty_per_timestep
Optimization -->> ClientAPI: Optimization results DataFrame opt_tp
ClientAPI -->> User: Return results with capacity tariff metrics
Class diagram for Optimization and runtime capacity tariff handlingclassDiagram
class Optimization {
<<class>>
+logger
+lp_solver
+lp_solver_path
+num_threads
+optim_conf
+plant_conf
+set_capacity_tariff : bool
+capacity_threshold : float or list~float~
+capacity_threshold_is_list : bool
+capacity_penalty : float
+__init__(optim_conf, plant_conf, logger, lp_solver, lp_solver_path, num_threads)
+perform_optimization(data_opt, def_total_timestep, def_total_hours)
}
class CapacityTariffRuntimeConfig {
<<class>>
+set_capacity_tariff : bool
+capacity_tariff_threshold : float or list~float~
+capacity_tariff_penalty : float
}
class RuntimeParamsProcessor {
<<utility>>
+treat_runtimeparams(runtimeparams, params, forecast_dates, logger)
}
class OptimizationInternals {
<<class>>
+capacity_threshold_array : ndarray
+P_excess : dict~int, LpVariable~
+active_periods : dict~float, list~int~~
+objective
+constraints : dict
+opt_tp : DataFrame
}
class LPModel {
<<external>>
+setObjective(objective)
+solve()
}
RuntimeParamsProcessor --> CapacityTariffRuntimeConfig : populates
CapacityTariffRuntimeConfig --> Optimization : provided via optim_conf
Optimization --> OptimizationInternals : uses
OptimizationInternals --> LPModel : configures objective and constraints
Optimization --> LPModel : owns
OptimizationInternals --> Optimization : results stored in opt_tp and cost_fun_profit
Flow diagram for capacity tariff configuration and usageflowchart TD
A_runtimeparams[Start: runtimeparams input] --> B_check_set[Check set_capacity_tariff in runtimeparams]
B_check_set -->|missing| B1_set_false[set_capacity_tariff = False]
B_check_set -->|present| B2_parse_flag[Parse set_capacity_tariff as bool]
B1_set_false --> C_threshold_default
B2_parse_flag --> C_threshold_source
C_threshold_source{capacity_tariff_threshold provided?} -->|no| C_threshold_default[capacity_tariff_threshold = 5000]
C_threshold_source -->|yes| C_threshold_raw[Read capacity_tariff_threshold]
C_threshold_raw --> C_is_str{Is string?}
C_is_str -->|yes| C_parse_str[ast.literal_eval to list or float]
C_is_str -->|no| C_use_value[Use raw value]
C_parse_str --> C_after_parse
C_use_value --> C_after_parse
C_after_parse --> C_is_list{Is list?}
C_is_list -->|yes| C_validate_len[Validate list length vs forecast_dates]
C_is_list -->|no| C_scalar[Use scalar threshold]
C_validate_len -->|len >= forecast| C_list_ok[Accept time-series threshold]
C_validate_len -->|len < forecast| C_fallback_scalar[Fallback to first nonzero or 5000]
C_list_ok --> D_threshold_to_optim_conf[Store capacity_tariff_threshold in optim_conf]
C_scalar --> D_threshold_to_optim_conf
C_fallback_scalar --> D_threshold_to_optim_conf
C_threshold_default --> D_threshold_to_optim_conf
A_runtimeparams --> E_penalty_source[Read capacity_tariff_penalty]
E_penalty_source --> E_try_parse[Parse to float]
E_try_parse -->|ok| E_penalty_ok[Use parsed penalty]
E_try_parse -->|error| E_penalty_default[capacity_tariff_penalty = 10.0]
E_penalty_ok --> F_penalty_to_optim_conf[Store capacity_tariff_penalty in optim_conf]
E_penalty_default --> F_penalty_to_optim_conf
B1_set_false --> G_flag_to_optim_conf[Store set_capacity_tariff in optim_conf]
B2_parse_flag --> G_flag_to_optim_conf
D_threshold_to_optim_conf --> H_optim_init[Optimization.__init__ reads optim_conf]
F_penalty_to_optim_conf --> H_optim_init
G_flag_to_optim_conf --> H_optim_init
H_optim_init --> H1_check_flag{set_capacity_tariff?}
H1_check_flag -->|no| Z_end[Optimization without capacity tariff]
H1_check_flag -->|yes| H2_init_capacity[Init capacity_threshold, capacity_threshold_is_list, capacity_penalty]
H2_init_capacity --> I_perform_opt[perform_optimization starts]
I_perform_opt --> I1_prepare_array{capacity_threshold_is_list?}
I1_prepare_array -->|yes| I2_build_array[Build capacity_threshold_array from list]
I1_prepare_array -->|no| I4_skip_array[Use scalar threshold only]
I2_build_array --> I3_validate_len[Check length vs data_opt index]
I3_validate_len -->|mismatch| I3_disable[Log error and disable set_capacity_tariff]
I3_validate_len -->|ok| I3_stats[Log active_count and unique thresholds]
I3_stats --> J_objective_start[Build objective function]
I4_skip_array --> J_objective_start
I3_disable --> Z_end
J_objective_start --> J1_build_P_excess[Create P_excess variables per timestep]
J1_build_P_excess --> J2_add_penalty[Add capacity_penalty_term to objective]
J2_add_penalty --> K_constraints_start[Build constraints]
K_constraints_start --> K1_excess_constraints[Add capacity tariff excess constraints]
K1_excess_constraints --> L_solve[Solve LP model]
L_solve --> M_collect_results[Collect optimization results into opt_tp]
M_collect_results --> M1_extract_excess[Extract P_excess.varValue per timestep]
M1_extract_excess --> M2_compute_penalty[Compute capacity_penalty_cost per timestep]
M2_compute_penalty --> M3_add_columns[Add capacity_threshold, P_excess, capacity_penalty_cost columns]
M3_add_columns --> N_costfun_profit{costfun == profit?}
N_costfun_profit -->|yes| N1_add_penalty_profit[Add penalty_per_timestep to cost_fun_profit]
N_costfun_profit -->|no| N2_other_costfun[Other costfun paths]
N1_add_penalty_profit --> Z_end
N2_other_costfun --> Z_end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
Please include the needed unittest to thoroughly test this new feature. |
|
Also please document how to use this 👍 |
|
It would also be relevant to keep track what we mean with "capacity tariff" and how it is calculated towards your monthly electricity bill. There are many totally different implementations of this concept all over the world. imho:
|



Summary by Sourcery
Introduce configurable capacity tariff support to the optimization workflow, including runtime configuration, optimization penalties, constraints, and reporting of tariff-related results.
New Features:
Enhancements: