I am trying to find a shortest path (the cheapest) in a weighted multi-directional graph where the vertices are cities, the edges are routes between cities and the weights are prices.
each route/edge is owned by one of 3 companies. The price is the same for all edges owned by a company. So all edges owned by company 'A' will have a price of X.
So if a final path goes through 2 of company A's routes and 1 of company B's routes, then the final price is 2PriceofA + 1PriceOfB. Also the weight of a edge is simply the price of the associated company.
This is a normal case so far, however, the following extra rule is making it difficult for me:
The 3rd company 'C' applies it's price ONCE regardless of how many routes it has in the final path, but it's price is usually higher than the previous companies. Therefore C's routes are ideal for longer paths, while A and B are best for shorter paths.
Here is what i have done so far (and why it does not work):
I am using Dijkstra to get the cheapest path and i have simply set the weights of each edge to be the price of the company. Even for C.
Then if the algorithm visits a node owned by C, it sets the weight of all the other edges that C owns to 0. Otherwise the algorithm continues as normal.
The problem is that Dijkstras algorithm always prioritizes the immediate best choice, and since company A and B have smaller prices than C, then it will try to avoid C. Sometimes this results in a path that the algorithm thinks is the shortest/cheapest, but in reality could have been much cheaper if it had chosen C to begin with.
How can i get the true cheapest path in this case?
Should i change to another algorithm? and if so, which one?