Class Utils
java.lang.Object
io.openems.edge.controller.ess.timeofusetariff.optimizer.Utils
Utils for
TimeOfUseTariffController
.
All energy values are in [Wh] and positive, unless stated differently.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final float
C-Rate (capacity divided by time) duringStateMachine.CHARGE_GRID
.static final int
Limit Charge Power for §14a EnWG.static final float
Keep some buffer to avoid scheduling errors because of bad predictions.protected static final long
protected static final long
static final ChannelAddress
static final ChannelAddress
static final ChannelAddress
static final ChannelAddress
static final ChannelAddress
static final ChannelAddress
-
Method Summary
Modifier and TypeMethodDescriptionstatic Integer
calculateChargeGridPower
(Params params, ManagedSymmetricEss ess, Sum sum, int maxChargePowerFromGrid, boolean limitChargePowerFor14aEnWG) Calculates the Max-ActivePower constraint forStateMachine.CHARGE_GRID
.static Integer
Calculates the ActivePower constraint forStateMachine.DELAY_DISCHARGE
.protected static int
static long
Calculates the ExecutionLimitSeconds for theOptimizer
.static Integer
Calculates the Max-ActivePower constraint forinvalid reference
StateMachine#CHARGE_PRODUCTION
static Params
createSimulatorParams
(Context context, com.google.common.collect.ImmutableSortedMap<ZonedDateTime, StateMachine> existingSchedule) protected static int
findFirstPeakIndex
(int fromIndex, double[] values) protected static int
findFirstValleyIndex
(int fromIndex, double[] values) protected static Integer[]
generateProductionPrediction
(Integer[] prediction, int minLength) Postprocesses production prediction; makes sure length is at least the same as consumption prediction - filling up with zeroes.protected static int
getEssMinSocEnergy
(Context context, int essCapacity) Returns the amount of energy that is not available for scheduling because of a configured minimum SoC.static int
getEssMinSocPercentage
(List<ControllerEssLimitTotalDischarge> ctrlLimitTotalDischarges, List<ControllerEssEmergencyCapacityReserve> ctrlEmergencyCapacityReserves) Returns the configured minimum SoC, or zero.static GetScheduleResponse
handleGetScheduleRequest
(Optimizer optimizer, UUID requestId, Timedata timedata, String componentId, ZonedDateTime now) Utilizes the previous three hours' data and computes the next 21 hours data from theOptimizer
provided, then concatenates them to generate a 24-hourGetScheduleResponse
.static void
Initializes the JeneticsRandomRegistry
for production.static void
Initializes the JeneticsRandomRegistry
for JUnit tests.protected static double[]
interpolateArray
(Double[] values) Interpolate an Array ofDouble
s.protected static int[]
interpolateArray
(Integer[] values) Interpolate an Array ofInteger
s.protected static Integer[]
joinConsumptionPredictions
(int splitAfterIndex, Integer[] totalConsumption, Integer[] unmanagedConsumption) protected static void
logSchedule
(Params params, com.google.common.collect.ImmutableSortedMap<ZonedDateTime, Simulator.Period> periods) Prints the Schedule to System.out.protected static boolean
static StateMachine
postprocessRunState
(int minSoc, Integer soc, int production, StateMachine state) Post-Process a state duringController.run()
, i.e.static StateMachine
postprocessSimulatorState
(Params p, int essInitialEnergy, StateMachine state, EnergyFlow ef) Post-Process a state of a Period during Simulation, i.e.static int
toEnergy
(int power) Converts power [W] to energy [Wh/15 min].static Integer
Converts energy [Wh/15 min] to power [W].static void
updateSchedule
(ZonedDateTime now, TreeMap<ZonedDateTime, Simulator.Period> schedule, com.google.common.collect.ImmutableSortedMap<ZonedDateTime, Simulator.Period> newSchedule) Updates the active Schedule with a new Schedule.
-
Field Details
-
ESS_MAX_SOC
public static final float ESS_MAX_SOCKeep some buffer to avoid scheduling errors because of bad predictions.- See Also:
-
ESS_LIMIT_14A_ENWG
public static final int ESS_LIMIT_14A_ENWGLimit Charge Power for §14a EnWG.- See Also:
-
ESS_CHARGE_C_RATE
public static final float ESS_CHARGE_C_RATEC-Rate (capacity divided by time) duringStateMachine.CHARGE_GRID
. With a C-Rate of 0.5 the battery gets fully charged within 2 hours.- See Also:
-
SUM_PRODUCTION
-
SUM_CONSUMPTION
-
SUM_GRID
-
SUM_UNMANAGED_CONSUMPTION
-
SUM_ESS_DISCHARGE_POWER
-
SUM_ESS_SOC
-
EXECUTION_LIMIT_SECONDS_BUFFER
protected static final long EXECUTION_LIMIT_SECONDS_BUFFER- See Also:
-
EXECUTION_LIMIT_SECONDS_MINIMUM
protected static final long EXECUTION_LIMIT_SECONDS_MINIMUM- See Also:
-
-
Method Details
-
initializeRandomRegistryForProduction
public static void initializeRandomRegistryForProduction()Initializes the JeneticsRandomRegistry
for production. -
initializeRandomRegistryForUnitTest
public static void initializeRandomRegistryForUnitTest()Initializes the JeneticsRandomRegistry
for JUnit tests. -
createSimulatorParams
public static Params createSimulatorParams(Context context, com.google.common.collect.ImmutableSortedMap<ZonedDateTime, StateMachine> existingSchedule) throws InvalidValueException- Parameters:
context
- theContext
objectexistingSchedule
- the existing schedule, i.e. result of previous optimization- Returns:
Params
- Throws:
InvalidValueException
- on error
-
generateProductionPrediction
Postprocesses production prediction; makes sure length is at least the same as consumption prediction - filling up with zeroes.- Parameters:
prediction
- the production predictionminLength
- the min length (= consumption prediction length)- Returns:
- new production prediction
-
joinConsumptionPredictions
-
paramsAreValid
-
getEssMinSocEnergy
Returns the amount of energy that is not available for scheduling because of a configured minimum SoC.- Parameters:
context
- theContext
essCapacity
- netSymmetricEss.ChannelId.CAPACITY
- Returns:
- the value in [Wh]
-
getEssMinSocPercentage
public static int getEssMinSocPercentage(List<ControllerEssLimitTotalDischarge> ctrlLimitTotalDischarges, List<ControllerEssEmergencyCapacityReserve> ctrlEmergencyCapacityReserves) Returns the configured minimum SoC, or zero.- Parameters:
ctrlLimitTotalDischarges
- the list ofControllerEssLimitTotalDischarge
ctrlEmergencyCapacityReserves
- the list ofControllerEssEmergencyCapacityReserve
- Returns:
- the value in [%]
-
interpolateArray
Interpolate an Array ofDouble
s.Replaces nulls with previous value. If first entry is null, it is set to first available value. If all values are null, all are set to 0.
- Parameters:
values
- the values- Returns:
- values without nulls
-
interpolateArray
Interpolate an Array ofInteger
s.Replaces nulls with previous value. If first entry is null, it is set to first available value. If all values are null, all are set to 0.
- Parameters:
values
- the values- Returns:
- values without nulls
-
findFirstPeakIndex
protected static int findFirstPeakIndex(int fromIndex, double[] values) -
findFirstValleyIndex
protected static int findFirstValleyIndex(int fromIndex, double[] values) -
handleGetScheduleRequest
public static GetScheduleResponse handleGetScheduleRequest(Optimizer optimizer, UUID requestId, Timedata timedata, String componentId, ZonedDateTime now) throws OpenemsError.OpenemsNamedException Utilizes the previous three hours' data and computes the next 21 hours data from theOptimizer
provided, then concatenates them to generate a 24-hourGetScheduleResponse
.- Parameters:
optimizer
- theOptimizer
requestId
- the JSON-RPC request-idtimedata
- theTimedata
componentId
- the Component-IDnow
- the currentZonedDateTime
(will get rounded down to 15 minutes)- Returns:
- the
GetScheduleResponse
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
calculateExecutionLimitSeconds
Calculates the ExecutionLimitSeconds for theOptimizer
.- Parameters:
clock
- a clock- Returns:
- execution limit in [s]
-
postprocessSimulatorState
public static StateMachine postprocessSimulatorState(Params p, int essInitialEnergy, StateMachine state, EnergyFlow ef) Post-Process a state of a Period during Simulation, i.e. replace with 'better' state with the same behaviour.NOTE: heavy computation is ok here, because this method is called only at the end with the best Schedule.
- Parameters:
p
- theParams
essInitialEnergy
- the initial ESS energy in this periodstate
- the initial stateef
- theEnergyFlow
- Returns:
- the new state
-
postprocessRunState
public static StateMachine postprocessRunState(int minSoc, Integer soc, int production, StateMachine state) Post-Process a state duringController.run()
, i.e. replace with 'better' state if appropriate.NOTE: this can be useful, if live operation deviates from predicted operation, e.g. because predictions were wrong.
- Parameters:
minSoc
- the configured Minimum-SoC, or zerosoc
- the currentSymmetricEss.ChannelId.SOC
production
- the currentSum.ChannelId.PRODUCTION_ACTIVE_POWER
, or zerostate
- the initial state- Returns:
- the new state
-
calculateEssChargeInChargeGridPowerFromParams
protected static int calculateEssChargeInChargeGridPowerFromParams(Params params, ManagedSymmetricEss ess) -
calculateChargeGridPower
public static Integer calculateChargeGridPower(Params params, ManagedSymmetricEss ess, Sum sum, int maxChargePowerFromGrid, boolean limitChargePowerFor14aEnWG) Calculates the Max-ActivePower constraint forStateMachine.CHARGE_GRID
.- Parameters:
params
- theParams
ess
- theManagedSymmetricEss
sum
- theSum
maxChargePowerFromGrid
- the configured max charge from grid powerlimitChargePowerFor14aEnWG
- Limit Charge Power for §14a EnWG- Returns:
- the set-point or null
-
calculateMaxChargeProductionPower
Calculates the Max-ActivePower constraint forinvalid reference
StateMachine#CHARGE_PRODUCTION
- Parameters:
sum
- theSum
- Returns:
- the set-point
-
calculateDelayDischargePower
Calculates the ActivePower constraint forStateMachine.DELAY_DISCHARGE
.- Parameters:
ess
- theManagedSymmetricEss
- Returns:
- the set-point
-
toEnergy
public static int toEnergy(int power) Converts power [W] to energy [Wh/15 min].- Parameters:
power
- the power value- Returns:
- the energy value
-
toPower
Converts energy [Wh/15 min] to power [W].- Parameters:
energy
- the energy value- Returns:
- the power value
-
logSchedule
protected static void logSchedule(Params params, com.google.common.collect.ImmutableSortedMap<ZonedDateTime, Simulator.Period> periods) Prints the Schedule to System.out.NOTE: The output format is suitable as input for "RunOptimizerFromLogApp". This is useful to re-run a simulation.
- Parameters:
params
- theParams
periods
- the map ofSimulator.Period
s
-
updateSchedule
public static void updateSchedule(ZonedDateTime now, TreeMap<ZonedDateTime, Simulator.Period> schedule, com.google.common.collect.ImmutableSortedMap<ZonedDateTime, Simulator.Period> newSchedule) Updates the active Schedule with a new Schedule.- Period of the currently active Quarter is never changed
- Old Periods are removed from the Schedule
- Remaining Schedules are updated from new Schedule
- Parameters:
now
- the currentZonedDateTime
schedule
- the active SchedulenewSchedule
- the new Schedule
-