-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/improve optimizer #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
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, |
There was a problem hiding this comment.
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..."
| If the removal of a station leads to low_socs, | ||
| the station is added again and not removed again. |
There was a problem hiding this comment.
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.
| # These stations were given in the config to be electrified or where electrified before | ||
| # optimizing. |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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"
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