I am working on an elevator simulator in c++. I have a class passenger and the program creates "randomized" instances of that class with different starting floors and different destinations within the building then stores them in a vector
vector<passenger> passengers;
I am working on the dispatch algorithm for the 4 elevators in the building. However, because of the fact that the algorithm compares all 4 elevators in the building, it is possible that the passenger cannot have an elevator assigned right away (i.e. not available IDLE elevator or elevator having enough space going in the same direction as the passenger).
Problem:
I want to apply the algorithm constantly to all the elements of the vector passengers simultaneously and can't do it with a traditional for loop as it could get stuck mid-way with passenger instances down the vector that could be assigned an elevator left waiting.
Anyone knows if there is a way to do so?
Thanks.
Copyright Notice:Content Author:「Quentin_P」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55665087/is-there-a-way-to-loop-through-all-elements-of-a-vector-in-parallel-in-c