Coverage for agentlib_flexquant/data_structures/globals.py: 100%
30 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-10-20 14:09 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2025-10-20 14:09 +0000
1"""Script containing global variables"""
3from typing import Literal
5# fixed string definitions
6PREP_TIME = "prep_time"
7MARKET_TIME = "market_time"
8FLEX_EVENT_DURATION = "flex_event_duration"
9PROFILE_DEVIATION_WEIGHT = "profile_deviation_weight"
10PROFILE_COMFORT_WEIGHT = "profile_comfort_weight"
11TIME_STEP = "time_step"
12PREDICTION_HORIZON = "prediction_horizon"
13FLEXIBILITY_OFFER = "FlexibilityOffer"
14LINEAR = 'linear'
15CONSTANT = 'constant'
16COLLOCATION = 'collocation'
17INTEGRATION_METHOD = Literal[LINEAR, CONSTANT]
18FlexibilityDirections = Literal["positive", "negative"]
19POWER_ALIAS_BASE = "_P_el_base"
20POWER_ALIAS_NEG = "_P_el_neg"
21POWER_ALIAS_POS = "_P_el_pos"
22STORED_ENERGY_ALIAS_BASE = "_E_stored_base"
23STORED_ENERGY_ALIAS_NEG = "_E_stored_neg"
24STORED_ENERGY_ALIAS_POS = "_E_stored_pos"
25full_trajectory_suffix: str = "_full"
26full_trajectory_prefix: str = "_"
27shadow_suffix: str = "_shadow"
28COLLOCATION_TIME_GRID = 'collocation_time_grid'
30# cost function in the shadow mpc. obj_std and obj_flex are to be evaluated according
31# to user definition
32SHADOW_MPC_COST_FUNCTION = (
33 "return ca.if_else(self.time < self.prep_time.sym + "
34 "self.market_time.sym, obj_std, ca.if_else(self.time < "
35 "(self.prep_time.sym + self.flex_event_duration.sym + "
36 "self.market_time.sym), obj_flex, obj_std))"
37)
40def return_baseline_cost_function(power_variable: str, comfort_variable: str) -> str:
41 """Return baseline cost function
43 Args:
44 power_variable: name of the power variable
45 comfort_variable: name of the comfort variable
47 Returns:
48 Cost function in the baseline mpc, obj_std is to be evaluated according to
49 user definition
51 """
52 if comfort_variable:
53 cost_func = (
54 "return ca.if_else(self.in_provision.sym, "
55 "ca.if_else(self.time < self.rel_start.sym, obj_std, "
56 "ca.if_else(self.time >= self.rel_end.sym, obj_std, "
57 f"sum([self.profile_deviation_weight*(self.{power_variable} - "
58 f"self._P_external)**2, "
59 f"self.{comfort_variable}**2 * self.profile_comfort_weight]))),obj_std)"
60 )
61 else:
62 cost_func = (
63 "return ca.if_else(self.in_provision.sym, "
64 "ca.if_else(self.time < self.rel_start.sym, obj_std, "
65 "ca.if_else(self.time >= self.rel_end.sym, obj_std, "
66 f"sum([self.profile_deviation_weight*(self.{power_variable} - "
67 f"self._P_external)**2]))),obj_std)"
68 )
69 return cost_func