java.lang.Object
io.openems.edge.controller.ess.timeofusetariff.optimizer.Utils

public final class Utils extends Object
Utils for TimeOfUseTariffController.

All energy values are in [Wh] and positive, unless stated differently.

  • Field Details

    • ESS_MAX_SOC

      public static final float ESS_MAX_SOC
      Keep some buffer to avoid scheduling errors because of bad predictions.
      See Also:
    • ESS_LIMIT_14A_ENWG

      public static final int ESS_LIMIT_14A_ENWG
      Limit Charge Power for §14a EnWG.
      See Also:
    • ESS_CHARGE_C_RATE

      public static final float ESS_CHARGE_C_RATE
      C-Rate (capacity divided by time) during StateMachine.CHARGE_GRID. With a C-Rate of 0.5 the battery gets fully charged within 2 hours.
      See Also:
    • SUM_PRODUCTION

      public static final ChannelAddress SUM_PRODUCTION
    • SUM_CONSUMPTION

      public static final ChannelAddress SUM_CONSUMPTION
    • SUM_GRID

      public static final ChannelAddress SUM_GRID
    • SUM_UNMANAGED_CONSUMPTION

      public static final ChannelAddress SUM_UNMANAGED_CONSUMPTION
    • SUM_ESS_DISCHARGE_POWER

      public static final ChannelAddress SUM_ESS_DISCHARGE_POWER
    • SUM_ESS_SOC

      public static final ChannelAddress 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 Jenetics RandomRegistry for production.
    • initializeRandomRegistryForUnitTest

      public static void initializeRandomRegistryForUnitTest()
      Initializes the Jenetics RandomRegistry for JUnit tests.
    • createSimulatorParams

      public static Params createSimulatorParams(Context context, com.google.common.collect.ImmutableSortedMap<ZonedDateTime,StateMachine> existingSchedule) throws InvalidValueException
      Create Params for Simulator.
      Parameters:
      context - the Context object
      existingSchedule - the existing schedule, i.e. result of previous optimization
      Returns:
      Params
      Throws:
      InvalidValueException - on error
    • generateProductionPrediction

      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.
      Parameters:
      prediction - the production prediction
      minLength - the min length (= consumption prediction length)
      Returns:
      new production prediction
    • joinConsumptionPredictions

      protected static Integer[] joinConsumptionPredictions(int splitAfterIndex, Integer[] totalConsumption, Integer[] unmanagedConsumption)
    • paramsAreValid

      protected static boolean paramsAreValid(Params p)
    • getEssMinSocEnergy

      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.
      Parameters:
      context - the Context
      essCapacity - net SymmetricEss.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 of ControllerEssLimitTotalDischarge
      ctrlEmergencyCapacityReserves - the list of ControllerEssEmergencyCapacityReserve
      Returns:
      the value in [%]
    • interpolateArray

      protected static double[] interpolateArray(Double[] values)
      Interpolate an Array of Doubles.

      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

      protected static int[] interpolateArray(Integer[] values)
      Interpolate an Array of Integers.

      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 the Optimizer provided, then concatenates them to generate a 24-hour GetScheduleResponse.
      Parameters:
      optimizer - the Optimizer
      requestId - the JSON-RPC request-id
      timedata - theTimedata
      componentId - the Component-ID
      now - the current ZonedDateTime (will get rounded down to 15 minutes)
      Returns:
      the GetScheduleResponse
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • calculateExecutionLimitSeconds

      public static long calculateExecutionLimitSeconds(Clock clock)
      Calculates the ExecutionLimitSeconds for the Optimizer.
      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 - the Params
      essInitialEnergy - the initial ESS energy in this period
      state - the initial state
      ef - the EnergyFlow
      Returns:
      the new state
    • postprocessRunState

      public static StateMachine postprocessRunState(int minSoc, Integer soc, int production, StateMachine state)
      Post-Process a state during Controller.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 zero
      soc - the current SymmetricEss.ChannelId.SOC
      production - the current Sum.ChannelId.PRODUCTION_ACTIVE_POWER, or zero
      state - 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 for StateMachine.CHARGE_GRID.
      Parameters:
      params - the Params
      ess - the ManagedSymmetricEss
      sum - the Sum
      maxChargePowerFromGrid - the configured max charge from grid power
      limitChargePowerFor14aEnWG - Limit Charge Power for §14a EnWG
      Returns:
      the set-point or null
    • calculateMaxChargeProductionPower

      public static Integer calculateMaxChargeProductionPower(Sum sum)
      Calculates the Max-ActivePower constraint for
      invalid reference
      StateMachine#CHARGE_PRODUCTION
      .
      Parameters:
      sum - the Sum
      Returns:
      the set-point
    • calculateDelayDischargePower

      public static Integer calculateDelayDischargePower(ManagedSymmetricEss ess)
      Calculates the ActivePower constraint for StateMachine.DELAY_DISCHARGE.
      Parameters:
      ess - the ManagedSymmetricEss
      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

      public static Integer toPower(Integer energy)
      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 - the Params
      periods - the map of Simulator.Periods
    • 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 current ZonedDateTime
      schedule - the active Schedule
      newSchedule - the new Schedule