Skip to content

Conversation

@PaulScheerRLI
Copy link
Collaborator

@PaulScheerRLI PaulScheerRLI commented Aug 18, 2025

Improve the station optimizer per @mosc5 request.
This adds an optional pruning step after the main optimization loop.
For each electrified station by the optimizer a secenario is run without it. If the scenario still meets the minimal soc criteria the station is removed. Multiple stations may be removed by the pruning algorithm.
Pruning is done greedily without branching.

a deeper nested implementation in the main optimization could bring further improvements, e.g. at the end of each group optimization. This could lead to slightly faster execution since only subsystems are resimulated in comparison to the current solution and improve the general optimiziation speed in case of deep/ branching optimization.
This would come at the cost of increased complexity. For the current goal of django-simba optimization, where the optimization is greedy currently, deeper nesting would not improve the resulting optimizied scenario

misc:
Moved pytest.ini into root, so pytest can be called from root and cwd aligns automatically

Add feature to remove stations added by the optimizer without affecting
full electrification. Iterate over stations once. Greedy approach
leading to local minimum at least two changes away from better solution.
def prune_stations(self, electrified_station_set):
"""Prune electrified stations not needed for full electrification
This uses a single greedy approach, iterating over stations one by one,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This uses a single greedy pass, iterating..."

Comment on lines +1207 to +1208
If the removal of a station leads to low_socs,
the station is added again and not removed again.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the removal of a station were to lead to low socs, that station will not be removed.

Comment on lines +1213 to +1214
# These stations were given in the config to be electrified or where electrified before
# optimizing.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-electrified stations were set to be electrified or were electrified before optimizing.

removable_stations = electrified_station_set.difference(not_removable_stations)
self.logger.log(msg="Searching for stations not needed for a full electrification scenario",
level=100)
self.logger.log(msg=f"Deelectrifying {len(removable_stations)} stations one by one.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about "deelectrifying". There could be made a case for "de-electrifying", but here you can go simply with "Testing"

self.logger.log(msg=f"Deelectrifying {len(removable_stations)} stations one by one.",
level=100)
for station in sorted(removable_stations):
electrified_station_set = electrified_station_set.difference([station])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is difference_update for sets, but here you can use remove: electrified_station_set.remove(station) (since station is part of removable_stations, which is derived from electrified_station_set => station is always in electrified_station_set).

if soc_min < self.config.min_soc:
break
if min_soc < self.config.min_soc:
self.logger.info("%s , can't be deelectrified. SoC would drop to: %s",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deelectrified -> pruned or removed. To be consistent with the other info-log, I'm in favor of "removed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants