Skip to content
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

(edrt) Allow multi. chargers per link #2919

Merged

Conversation

steffenaxer
Copy link
Collaborator

@steffenaxer steffenaxer commented Nov 5, 2023

The default EmptyVehicleChargingScheduler throws an error, if more than one charger has been deployed per link. If multiple chargers are available, a random charger is now selected in this PR.

@steffenaxer steffenaxer requested a review from michalmac November 5, 2023 15:47
List<Charger> chargers = linkToChargerMap.get(currentLink.getId());
if (chargers != null) {
// Pick a random charger of all available chargers at this link
Charger charger = chargers.get(RND.nextInt(chargers.size()));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead take the one with highest number of unused plugs. If there is none with unused plugs, take the one with shortest queue or lowest queue.size/plugCount. You could also include charger power in choosing the charger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea! Thanks.

Copy link
Member

@michalmac michalmac left a comment

Choose a reason for hiding this comment

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

Nice!

List<Charger> chargers = linkToChargersMap.get(currentLink.getId());
if (chargers != null) {
// Take the charger with the smallest queue
Charger charger = chargers.stream().min(Comparator.comparing(e -> e.getLogic().getQueuedVehicles().size())).orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

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

Replace comparing() with comparingInt()

Copy link
Member

Choose a reason for hiding this comment

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

You can also change

min(Comparator.comparing(e -> e.getLogic().getQueuedVehicles().size()))

to something like this:

mapToInt(e -> e.getLogic().getQueuedVehicles().size()).min()

Copy link
Collaborator Author

@steffenaxer steffenaxer Nov 5, 2023

Choose a reason for hiding this comment

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

mapToInt(e -> e.getLogic().getQueuedVehicles().size()).min() but we want to get the Charger with the lowest number of queued vehicles. The object of intreset is charger not the int.

Copy link
Member

Choose a reason for hiding this comment

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

True:-) Suggesting code changes without trying them in an IDE...

@steffenaxer steffenaxer merged commit a337eca into matsim-org:master Nov 6, 2023
46 checks passed
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.

2 participants