Changeset 8812
- Timestamp:
- 10/16/12 13:07:54 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Operators/PriorityDispatchingMetaOptEvaluator.cs
r8808 r8812 47 47 double quality = 0; 48 48 49 ItemList<PickupDeliverySimulation> simulations = SimulationParameter.Value; 49 List<PickupDeliverySimulation> simulations = new List<PickupDeliverySimulation>(); 50 foreach (var originalSimulation in SimulationParameter.Value) { 51 PickupDeliverySimulation simulation = originalSimulation.Clone() as PickupDeliverySimulation; 52 PriorityDispatching dispatching = simulation.OptimizationParameter.Value as PriorityDispatching; 53 Parameterize(dispatching); 54 55 simulations.Add(simulation); 56 } 57 50 58 int repetitions = 0; 51 52 59 object locker = new object(); 53 60 var options = new ParallelOptions(); 54 61 //options.MaxDegreeOfParallelism = Math.Max(Environment.ProcessorCount - 1, 1); 55 Parallel.ForEach<PickupDeliverySimulation>(simulations, options, originalSimulation => { 56 int index = simulations.IndexOf(originalSimulation); 62 Parallel.ForEach<PickupDeliverySimulation>(simulations, options, simulation => { 63 int index = simulations.IndexOf(simulation); 64 int executions = 0; 57 65 58 PickupDeliverySimulation simulation = originalSimulation.Clone() as PickupDeliverySimulation; 59 PriorityDispatching dispatching = simulation.OptimizationParameter.Value as PriorityDispatching; 60 Parameterize(dispatching); 61 62 EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); 63 EventHandler handler = new EventHandler(delegate(object o, EventArgs e) { 64 waitHandle.Set(); 66 using (EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset)) { 67 EventHandler handler = new EventHandler(delegate(object o, EventArgs e) { 68 waitHandle.Set(); 65 69 }); 66 70 67 int executions = 0; 68 while (executions < RepetitionsParameter.Value.Value) { 69 waitHandle.Reset(); 71 while (executions < RepetitionsParameter.Value.Value) { 72 waitHandle.Reset(); 70 73 71 simulation.Prepared += handler;72 simulation.Prepare(true);73 waitHandle.WaitOne();74 simulation.Prepared -= handler;74 simulation.Prepared += handler; 75 simulation.Prepare(true); 76 waitHandle.WaitOne(); 77 simulation.Prepared -= handler; 75 78 76 waitHandle.Reset();79 waitHandle.Reset(); 77 80 78 simulation.Stopped += handler;79 simulation.Start();80 waitHandle.WaitOne();81 simulation.Stopped -= handler;81 simulation.Stopped += handler; 82 simulation.Start(); 83 waitHandle.WaitOne(); 84 simulation.Stopped -= handler; 82 85 83 Debug.Assert(simulation.Results.ContainsKey("Finished")); 84 double leadTime = (simulation.Results["LeadTime"].Value as DoubleValue).Value; 85 double tardiness = (simulation.Results["TardinessPenalty"].Value as DoubleValue).Value; 86 if (!simulation.Results.ContainsKey("Finished")) { 87 throw new Exception("Simulation did not finish"); 88 } 89 executions++; 86 90 87 lock (locker) {88 double runQuality = leadTime + tardiness;91 double leadTime = (simulation.Results["LeadTime"].Value as DoubleValue).Value; 92 double tardiness = (simulation.Results["TardinessPenalty"].Value as DoubleValue).Value; 89 93 90 quality += runQuality; 91 repetitions++; 94 lock (locker) { 95 double runQuality = leadTime + tardiness; 96 97 quality += runQuality; 98 repetitions++; 99 } 92 100 } 93 94 executions++;95 101 } 96 102 });
Note: See TracChangeset
for help on using the changeset viewer.