I am making a scheduler for truck rides that minimizes the total costs of driving by reducing deadhead. There are two phases in my program: making an initial planning and optimizing the planning. The planning is currently saved as a Dictionary<Truck, List <Trip>>
. Here each truck has to drive all trips in the order of the list of trips. The sequence of the trips is the same as the sequence of the list.
An initial schedule is created using Munkres’ algorithm on different phases of deadlines. If the initial schedule is ready, it will be optimized by an evolving genetic algorithm. In the GA a lot of threads try to improve the schedule. A thread can work follows:
- Get the current schedule.
- Randomly change the sequence of trips for a truck or change the distribution of trips to trucks.
- Check if deadlines are still made in the modified schedule. If not start at 1 again, otherwise go on.
- Check if costs of schedule are reduced by modification. If not start at 1 again, otherwise go on.
- Set/Merge/Change the schedule.
Step 3 and 4 are very expensive operations (can take more than 500ms). I thought about saving the schedule as an ImmutableDictionary
instead of a Dictionary
, so that after step 1 to the working schedule will not be changed by other threads. Then the problem is: How to do step 5. Any idea how I can handle this well? Or should I do it in another way than the ImmutableDictionary
idea?
Making it more general: What is a good way to merge a Dictionary
that other threads are also working with?