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

Bug fix regarding multiple plug in #2909

Closed
wants to merge 12 commits into from

Conversation

auzpatwary37
Copy link

I have added necessary comments in he file for a smooth understanding. Basically, when the charging end event happens the vehicles are removed from the vehiclesAtCharger map. But if the charging is not started, they are never put into the map in the first place. So, assuming if the vehicles are not there they are full charge is not right as they might be still in the queue and was never plugged in the first place. As a result, the queue in the charging logic is not cleaned and they still await for plug in. The car can then be put into the logic of another charger and gets plugged in simultaneously in two chargers, hence the bug.

Comment on lines 122 to 125
}else {
Id<Charger> chargerId = tuple.getSecond();
Charger c = chargingInfrastructure.getChargers().get(chargerId);
if(c.getLogic().getQueuedVehicles().contains(electricFleet.getElectricVehicles().get(evId)))c.getLogic().removeVehicle(electricFleet.getElectricVehicles().get(evId), event.getTime());// so it is important to remove the vehicle from queue as well.
Copy link
Member

Choose a reason for hiding this comment

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

Please reformat and rearrange your code (e.g. by adding local variables) so it is easier to read.

Copy link
Author

Choose a reason for hiding this comment

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

I have added a local variable for the EV for easier reading

Copy link
Contributor

Choose a reason for hiding this comment

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

the code should be shorter and easier to read like this:

if(vehiclesAtChargers.remove(evId) != null || c.getLogic().getQueuedVehicles().contains(ev)){ 
	Id<Charger> chargerId = tuple.getSecond();
	Charger c = chargingInfrastructure.getChargers().get(chargerId);
	c.getLogic().removeVehicle(ev, event.getTime());
}

@tschlenther
Copy link
Contributor

tschlenther commented Nov 6, 2023

this makes me wonder whether we need the vehiclesAtChargers map at all...

By definetely removing the vehicle both from the charger logic and it's queue, I think we don't need this helper memory map and can thus also get rid of three methods, i.e. do not need to implement neither of the following itnerfaces

ChargingEndEventHandler, ChargingStartEventHandler, QueuedAtChargerEventHandler

As a result, the method in focus here would only be as follows:

@Override
	public void handleEvent(ActivityEndEvent event) {
		if (event.getActType().endsWith( UrbanEVModule.PLUGOUT_INTERACTION )) {
			Tuple<Id<Vehicle>, Id<Charger>> tuple = chargingProcedures.get(event.getLinkId()).remove(event.getPersonId());
			if (tuple != null) {
				Id<Vehicle> evId = Id.create(tuple.getFirst(), Vehicle.class);
				ElectricVehicle ev = electricFleet.getElectricVehicles().get(evId);
				Id<Charger> chargerId = tuple.getSecond();
				Charger c = chargingInfrastructure.getChargers().get(chargerId);
				// remove the vehicle (even if it is only queued)
				c.getLogic().removeVehicle(ev, event.getTime());
			} else {
				throw new RuntimeException("there is something wrong with the charging procedure of person=" + event.getPersonId() + " on link= " + event.getLinkId());
			}
		}
	}

@auzpatwary37 can you confirm ?

@auzpatwary37
Copy link
Author

auzpatwary37 commented Nov 6, 2023

@tschlenther this would throw an error in the charging with queuing logic. This is because if the vehicle is not found anywhere the precondition checker in the remove vehicle function in the ChargingWithQueuingLogic class throws an error that the vehicle is neither plugged in nor in queue in this charger.

@tschlenther
Copy link
Contributor

@tschlenther this would throw an error in the charging with queuing logic. This is because if the vehicle is not found anywhere the precondition checker in the remove vehicle function in the ChargingWithQueuingLogic class throws an error that the vehicle is neither plugged in nor in queue in this charger.

right. thanks.
I think we should merge then (if the tests pass). Just on eminor comment: the code would be easier to read if you would separate the statement from the if clause more clearly, in line 125. Best would be to use braces and a new line, but at least a tab between the bracket and the beginning of the statement would be necessary to help the eye ;)

Thank you for the bug fix!!

@tschlenther tschlenther disabled auto-merge November 14, 2023 17:09
@tschlenther
Copy link
Contributor

thanks again for providing this bug fix. i will address in another PR with the attempt for clean and short code

@tschlenther
Copy link
Contributor

actually, this should already have been fixed in #2442
@auzpatwary37 yo must have used a (local) version from before #2442 , right? can you confirm?

@auzpatwary37
Copy link
Author

@tschlenther maybe, seems like the same issue. Adding the vehicles that are queued in the chargers as well will indeed fix the issue without modifying the condition. We are still using an old version and currently trying to shift to the most recent one.

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