inet-framework / inet

INET Framework for the OMNeT++ discrete event simulator
https://inet.omnetpp.org
Other
435 stars 486 forks source link

`getResidualEnergyCapacity() const` changes the state of `inet::power::SimpleEpEnergyStorage` #694

Open torokati44 opened 3 years ago

torokati44 commented 3 years ago

The getResidualEnergyCapacity() const implementation in inet::power::SimpleEpEnergyStorage incorrectly changes state (with the help of a const_cast). It can be called (indirectly) from refreshDisplay(), so it can introduce instability to the simulation results and fingerprints. See https://github.com/omnetpp/omnetpp/issues/873#issuecomment-833649718 for a stack trace of how this can happen.

This bug is the cause of: https://github.com/omnetpp/omnetpp/issues/873

torokati44 commented 3 years ago

The examples/wireless/power simulation also exhibits unstable fingerprints because of this.

To verify, use these commands:

inet_dbg -u Cmdenv --sim-time-limit=100s --fingerprint=0000-0000/tplx,0000-0000/zvs
inet_dbg -u Cmdenv --sim-time-limit=100s --fingerprint=0000-0000/tplx,0000-0000/zvs --cmdenv-fake-gui=true --cmdenv-fake-gui-before-event-probability=0.01 --cmdenv-fake-gui-after-event-probability=0.01 --cmdenv-fake-gui-on-hold-probability=0.01 --cmdenv-fake-gui-on-simtime-probability=0.01

These are supposed to calculate the same fingerprints. In most other example simulations they do, but not here. Varying the *-probability options also changes the fingerprints, even though it is not supposed to.