When using Dijkstra's algorithm, is there a good way to keep track of a variable that changes with the path?

Viewed 173

I'm writing a scheduling program using C# in which I construct a graph of people's availabilities and run Dijkstra's algorithm from every start node to every end node to determine the optimal path.

I would like to use the number of times a specific person has worked as an edge weight (i.e if the algorithm has to choose between John who has worked 2 times and Sue who has worked 1, it will choose Sue because she has worked fewer times).

The problem with this is that this number will be ever changing depending on which vertex I'm currently viewing. I think I can create a class, lets call it TimesWorked, that keeps a list of people and the number of times they have worked and then add an object for said class to my vertex class. From there on each edge from vertex1 to vertex2, assuming this edge creates a better path to vertex2 than current, I can deep copy TimesWorked from vertex1, make the required change to the copy, and assign that to vertex2. This will require me to check all paths into any vertex before checking the paths out of the vertex which should be possible because I can guarantee this is a directed acyclic graph.

I haven't written any code for the algorithm yet, otherwise I would paste it, but does anyone have any insight into whether or not my idea would work or possibly have a better idea?

here is an example graph, I made it in paint so it wasn't super easy to add arrows, but it is directed and always goes from left to right. start and end reflect the start time and end time of an availability.

example graph

0 Answers
Related