-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [pytest] | ||
| testpaths = | ||
| tests |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1199,6 +1199,52 @@ def lift_and_clip_positive_gradient(self, start_idx: int, soc: np.array, | |
| soc = np.hstack((soc_pre, soc)) | ||
| return soc | ||
|
|
||
| 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, | ||
| removing stations without reducing the level of electrification. | ||
| If the removal of a station leads to low_socs, | ||
| the station is added again and not removed again. | ||
|
Comment on lines
+1207
to
+1208
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| :param electrified_station_set: set of stations which are checked for remomval | ||
| :type electrified_station_set: set[str] | ||
| :return: None | ||
| """ | ||
| # These stations were given in the config to be electrified or where electrified before | ||
| # optimizing. | ||
|
Comment on lines
+1213
to
+1214
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| # They are not removed, since its assumed, they are "set in stone" | ||
| pre_electrified = self.config.inclusion_stations.union(self.base_schedule.stations.keys()) | ||
|
|
||
| # Without the must_include_stations the scenario can not be fully electrified. | ||
| # This was checked earlier | ||
| not_removable_stations = pre_electrified.union(self.must_include_set) | ||
|
|
||
| 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.", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" |
||
| level=100) | ||
| for station in sorted(removable_stations): | ||
| electrified_station_set = electrified_station_set.difference([station]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is |
||
| electrified_stations = not_removable_stations.union(electrified_station_set) | ||
| vehicle_socs = self.timeseries_calc(electrified_stations) | ||
| min_soc = 1 | ||
| for rot in self.schedule.rotations: | ||
| soc, start, end = self.get_rotation_soc(rot, vehicle_socs) | ||
| soc_min = np.min(soc[start:end]) | ||
| min_soc = min(min_soc, soc_min) | ||
| 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", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" |
||
| station, min_soc) | ||
| electrified_station_set.add(station) | ||
| continue | ||
| self.logger.info("%s can be removed. SoC drops to: %s", station, min_soc) | ||
| self.electrified_station_set.remove(station) | ||
| del self.electrified_stations[station] | ||
| return self.electrified_station_set, self.electrified_stations | ||
|
|
||
|
|
||
| def get_min_soc_and_index(soc_idx, mask): | ||
| """ Returns the minimal SoC and the corresponding index of a masked soc_idx. | ||
|
|
||
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..."