I want to move EVs to charge at the nearest charging stations. but if the station is occupied, other EVs should move to the available and second nearest location. I wrote this code but EVs are still going to the closest and occupied station. How to fix this issue? Any help is appreciated…
Set<Station> occupiedStation = new HashSet<>();
List<Station> candidateStation = new ArrayList<>();
for (int i = 0; i < main.Lev2Station.size(); i++) {
candidateStation.add( main.Lev2Station.get(i) );
}
for (int i = 0; i < main.DCStation.size(); i++) {
candidateStation.add( main.DCStation.get(i) );
}
List<Station> filteredStation = new ArrayList<>();
for (Station st: candidateStation) {
if (this.distanceTo(st.getX(), st.getY()) <= 10000 && !occupiedStation.contains(st)){
filteredStation.add(st);
}
}
Collections.sort(filteredStation, Comparator.comparingDouble(st -> this.distanceTo(st.getX(), st.getY())));
if (!filteredStation.isEmpty()) {
Station nearestStation = filteredStation.get(0);
this.moveTo(nearestStation);
}
And how to remove EV from the occupiedStation List when it transition through the statechart back to the initial location (Home). Noting that I want EV to move back after 1 hour for DCStation and 2hours for Lev2Station.
Frank Peter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.