Beispiel #1
0
        public override Solution Run()
        {
            Log($"Assign a path for each train ... ", Utils.Logging.LogEventArgs.MessageType.Info, false);
            if (CurrentSolution.AssignPaths())
            {
                Log($"done.", Utils.Logging.LogEventArgs.MessageType.Success);
            }
            else
            {
                Log($"failed.", Utils.Logging.LogEventArgs.MessageType.Error);
            }

            // Only one iteration for this solver
            {
                Log(HorizontalLine);
                Log($"Loop on trains and assign entry-exit times ... ");
                var usedResources = new UsedResourceCollection();
                ScheduleTrains(CurrentProblem, CurrentSolution.TrainRunsDic.Values.OrderBy(tr => tr.Train.MinEntryEarliest), usedResources);

                var validation = CurrentSolution.Validate();
                if (CurrentSolution.IsAdmissible) // Only consider admissible solution
                {
                    Log($"Compute objective function ... ");
                    CurrentSolution.ComputeObjectiveFunction();
                    CompareWithBest(CurrentSolution);
                }
                else
                {
                    Log(validation);
                }
            }

            return(BestSolution);
        }
        public override Solution Run()
        {
            do
            {
                BasicSchedule(OrderedTrainRuns);
                int subIter = 0;
                int nbConflicts;
                do
                {
                    nbConflicts = IterativeConflictSolver.ScheduleTrains(CurrentProblem, OrderedTrainRuns);
                    Log($"Iteration {Iteration}: {nbConflicts} conflicts.");
                } while (++subIter < SubIteration && nbConflicts > 0);

                CurrentSolution.ComputeObjectiveFunction();
                Log($"Iteration {Iteration}, Objective value {CurrentSolution.ObjectiveValue}");
                CurrentSolution.Validate();
                if (CurrentSolution.IsAdmissible) // Only consider admissible solution
                {
                    CompareWithBest(CurrentSolution);
                }

                // Reorder trains and start again (unless optimal has been reached)
                OrderedTrainRuns = CurrentSolution.TrainRunsDic.Values.OrderByDescending(tr => tr.ObjectiveValue).ToArray();

                // We need a way to identify that some ordering has been used already. Hash of the array ?
            } while (++Iteration < MaxIteration && (BestSolution == null || !BestSolution.IsOptimal));

            return(BestSolution ?? CurrentSolution);
        }
Beispiel #3
0
        public override Solution Run()
        {
            do
            {
                // Assign path randomly
                CurrentSolution.AssignRandomPaths();

                // Simple Schedule
                BasicSchedule(CurrentSolution.TrainRuns.OrderBy(tr => tr.Train.MinEntryEarliest));

                // Detect conflicts
                var conflicts = CurrentSolution.GetConflicts();
                foreach (var c in conflicts)
                {
                    CurrentSolution.TrainRunsDic[c.Key].IsScheduled = false;
                }

                // Apply simple algorithm for trains with no conflicts
                var usedResources = new UsedResourceCollection();
                DummySolver.ScheduleTrains(CurrentProblem, CurrentSolution.TrainRuns.Where(tr => tr.IsScheduled).OrderBy(tr => tr.Train.MinEntryEarliest), usedResources);

                // Schedule conflicted trains
                DummySolver.ScheduleTrains(CurrentProblem, CurrentSolution.TrainRuns.Where(tr => !tr.IsScheduled).OrderBy(tr => tr.Train.MinEntryEarliest), usedResources);

                var validation = CurrentSolution.Validate();
                if (CurrentSolution.IsAdmissible) // Only consider admissible solution
                {
                    Log($"Compute objective function ... ");
                    CurrentSolution.ComputeObjectiveFunction();
                    CompareWithBest(CurrentSolution);
                }
                else
                {
                    Log(validation);
                }
            } while (++Iteration < MaxIteration && !BestSolution.IsOptimal);

            return(BestSolution);
        }
Beispiel #4
0
        public override Solution Run()
        {
            int nbConflicts = 0;

            // Only one iteration for this solver
            do
            {
                nbConflicts = ScheduleTrains(CurrentProblem, CurrentSolution.TrainRunsDic.Values
                                             .OrderBy(tr => tr.Train.MinEntryEarliest).ThenBy(tr => tr.Train.MaxDelayPenalty));

                Log($"Iteration {Iteration}: {nbConflicts} conflicts.");

                CurrentSolution.Validate();
                if (CurrentSolution.IsAdmissible) // Only consider admissible solution
                {
                    Log($"Compute objective function ... ");
                    CurrentSolution.ComputeObjectiveFunction();
                    CompareWithBest(CurrentSolution);
                    break;
                }
            } while (++Iteration < MaxIteration && nbConflicts > 0);

            return(BestSolution);
        }