Clarification about Genetic Algorithm and Time-of-Use Controller

Hello. Could someone please explain how is the provided genetic algorithm supposed to be used? I had a look at the code but couldn’t understand how to activate it (unlike the other algorithms, there is no controller for it) and what fitness or cost functions there are. Is it the same algorithm talked about at the OpenEMS Conference in November 2024, which this blog post mentions? Is it a real-time algorithm, such the Symmetric Ess Balancing controller?

Could you also explain how to use the Time-of-Use Controller? As far as I’ve understood, it is the only controller capable to leverage one of the available predictors. Is it correct? What I would like to achieve is using future predictions of consumption and productions from non-programmable DERs (such as PV panel and wind turbine) to determine the best values of the programmable DERs’ set-points (such as the ESS or the grid meter) in the present, or beforehand anyway. How can this be done?

Is there a relationship between the genetic algorithm and the Time-of-Use Controller? According to this post it seems there is, but it is not clear to me.

I don’t want to bother anyone with too many questions, but I could’t find the information I’m looking for anywhere and I’m highly interested in the topic.

Thanks in advance,
Fabio

1 Like

I am posting here so that I can follow this thread. I have recently posted a very similar question about using predictors (e.g LSTM) and how to use within a controller:

1 Like

Hi @fabio,

if you can access the App Center, the easiest way to install everything is via the “ENTSO-E”-App (openems/io.openems.edge.core/src/io/openems/edge/app/timeofusetariff/EntsoE.java at develop · OpenEMS/openems · GitHub)

To configure manually, you’ll need:

  • Controller.Ess.Time-Of-Use-Tariff
  • TimeOfUseTariff.ENTSO-E or any other TimeOfUseTariff provider
  • Controller.Symmetric.Balancing, configured in Scheduler after time-of-use controller
  • Predictor.PersistenceModel for _sum/ProductionActivePower, _sum/ConsumptionActivePower and _sum/UnmanagedConsumptionActivePower

I’d recommend starting this way (i.e. “v1”), as it works very well in production. For more advanced and generic combination of different Controllers, you will then have to use “Energy Scheduler v2” which is currently in development and what I have been talking about in the Conference.

This is the latest backport PR: Energy Scheduler v2 / Time-of-Use-Tariff optimization (ALPHA) by sfeilmeier · Pull Request #3029 · OpenEMS/openems · GitHub

Back to “v1”. The essentials for the Genetic Algorithm are here: openems/io.openems.edge.energy/src/io/openems/edge/energy/v1/optimizer/SimulatorV1.java at develop · OpenEMS/openems · GitHub. You can find the cost calculations in the simulatePeriod() method.

Regards,
Stefan

Thank you @stefan.feilmeier for your kind answer. So, for what I understand, the Controller.Ess.Time-Of-Use-Tariff alone is responsible for the instantiation and operation of the Genetic Algorithm, isn’t it?
Concerning Apps, honestly it’s a feature I wasn’t aware of. Do they need to be purchased or are they freely available?

Regards,
Fabio

No, the genetic algorith logic is in io.openems.edge.energy.

“Apps” are a way to combine configurations of multiple Components. They make it easier to configure multiple Components or an entire system in a consistent way. They don’t need to be purchased for OpenEMS, but e.g. for FEMS this is what you would buy a license key for.

How do we enable it then? Is there an option in Apache Felix? What is the relationship with Controller.Ess.Time-Of-Use-Tariff?

As for Apps, is there a list of the available ones in OpenEMS?

Sorry if I asked so many questions, but I would like to have a better comprehension of how the system works.

Thanks.

I guess if you go throuhg the “Getting Started” it would be better understandable for you

Also this would be solved then :slight_smile:
:slight_smile:

Hi @Sn0w3y, I went through the Getting Started many times, and also implemented several fictitious simple devices communicating with a Modbus server, so I think I’ve understood that part of the documentation pretty well, but I don’t think it mentions the Apps nor the Genetic Algorithm. I also had a look at the code in the GitHub repo, but simply reading the code doesn’t help me understanding how it works, conceptually. I just wanted to know something more than what is written in the official documentation, especially because I’m interested in the topic of energy optimization, and knowing there was a genetic algorithm in OpenEMS piqued my curiosity.

„Getting Started“ currently does not cover apps.

Yes indeed, on last Hackathon we have been working on a tutorial that also covers Apps, but its not finished:

Available Apps are currently all located here:

You only need to activate the Controller.Ess.Time-Of-Use-Tariff. The “Energy Scheduler Component” is activated automatically, because its a “Singleton” without configuration.

Thank you @stefan.feilmeier. So, correct me if I’m wrong, the Controller.Ess.Time-Of-Use-Tariff leverages the Genetic Algorithm to determine the active (charge or discharge) power set-point to be sent to the ESS, according to consumption and non-programmable DERs’ output predictions and to grid power prices, right?
Does the following part in its readme refer to it? “(…) It takes into account the current state of the battery’s capacity, recalculates its operations, and generates a detailed schedule for the Energy Storage System (ESS) for the upcoming 24-hour period, in 15-minute intervals”.
What is the advantage of using a Genetic Algorithm for this kind of optimization? Is it related to the nature of the problem trying to be solved (linear vs non-linear)?
Also, would it be possible to develop another cost function or another algorithm, e.g. a Particle Swarm Optimization, in addition to the default algorithm?

P.S.: What is the meaning of the different options in the Core Energy Scheduler in OpenEMS Edge Felix page? Is it something related to the Genetic Algorithm too?

Regards,
Fabio

There is currently a discussion in German about similar topics, which should answer some of your questions: (Can you translate it automatically?)

P.S.: What is the meaning of the different options in the Core Energy Scheduler in OpenEMS Edge Felix page? Is it something related to the Genetic Algorithm too?

Code

  • LogVerbosity allows for easier debugging
  • Version: v1 can only optimize a Battery and is stable, v2 is able to combine all kind of Controllers, but is in an ALPHA state (running in production on only a few actual systems)
  • RiskLevel is not yet implemented. It’s meant to add some variance e.g. in the cost function for low/high risk.

Regards,
Stefan

Thank you @stefan.feilmeier for your prompt answer. Just to clarify some doubts:

  1. Is the Core Energy Scheduler somehow related to the Controller.Ess.Time-Of-Use-Tariff and, thus, to the Genetic Algorithm?
  2. Which steps would be required to implement another optimization algorithm, maybe a PSO, or another cost function? Is the code easily modifiable or extendable? What classes would I need to implement in OpenEMS Edge?
  3. If I don’t bother you too much (sorry if I 've done so far) could you briefly explain why or in what circumstances a non linear approach would be better than a linear one, and if a non-linear algorithm needs to run not in real-time (because I suppose it is slower than a linear one, like the self-consumption optimization or the peak-shaving)?

Thank you again for your patience.

Regards,
Fabio

  1. Is the Core Energy Scheduler somehow related to the Controller.Ess.Time-Of-Use-Tariff and, thus, to the Genetic Algorithm?

For “Energy Scheduler v2”, which is what according to your questions you should be interested in, the EnergySchedulerImpl holds references to EnergySchedulables like Controller.Ess.Time-Of-Use-Tariff.

  1. Which steps would be required to implement another optimization algorithm, maybe a PSO, or another cost function? Is the code easily modifiable or extendable? What classes would I need to implement in OpenEMS Edge?

I do not have much knowledge about PSO (just Particle swarm optimization - Wikipedia), but it should be possible to exchange Jenetics with a PSO optimizer in Simulator.java. Jenetics works by having a Engine that provides a Java stream of Schedules (i.e. multidimensional arrays of integers that are matched to EnergySchedulable Modes).

It still sounds like a lot of work, though. So I would rather invite you to work on improvements to Jenetics instead - like optimizing the initial population etc.

  1. If I don’t bother you too much (sorry if I 've done so far) could you briefly explain why or in what circumstances a non linear approach would be better than a linear one, and if a non-linear algorithm needs to run not in real-time (because I suppose it is slower than a linear one, like the self-consumption optimization or the peak-shaving)?

There are multiple constraints in an energy optimization that are non linear, e.g. charging an electric vehicle is typically either “0 A” or between “6 A” and “32 A”. This is why we separate the slow optimization (essentially once per 15 minutes) from the real-time operation, which just applies the predefined mode.

Thank you again @stefan.feilmeier. Just one more question: what is the criterion followed by the optimization performed via the genetic algorithm? How are users supposed to choose between e.g. the Controller.Ess.Balancing, the Controller.Peak-Shaving.Symmetric and the Controller.Ess.Time-of-Use-Tariff? Can they be combined? What real-time controllers can be combined with the Controller.Ess.Time-of-Use-Tariff?

Users basically are not supposed to decide.

For “users” I mean those who set up the EMS.