当前位置: 首页>>代码示例>>C#>>正文


C# Solution.LocalSearch方法代码示例

本文整理汇总了C#中Solution.LocalSearch方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.LocalSearch方法的具体用法?C# Solution.LocalSearch怎么用?C# Solution.LocalSearch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Solution的用法示例。


在下文中一共展示了Solution.LocalSearch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Schedule

        static Solution Schedule(TimeTableData problemData, int week, 
            WeeklyEventAssignment[] guidingAssignments = null)
        {
            TimeTableData timeTable = problemData;
            problemData.PrepareSuitableTimeSlots(false);

            MMASData mmasData = new MMASData(timeTable, week, EVAPORATION, MIN_PHERAMONE);
            bool secondWeek = guidingAssignments != null;

            if (secondWeek)
                mmasData.SetPheromoneFromExistingAssignments(guidingAssignments);
            else
                mmasData.ResetPheromone();

            Solution bestSoFarSolution = new Solution(problemData, week);

            bestSoFarSolution.RandomInitialSolution();
            bestSoFarSolution.ComputeFeasibility();
            bestSoFarSolution.ComputeHcv();

            int currIter = 0;
            int lastImprIter = 0;
            while (currIter - lastImprIter < 200)
            {
                Solution bestIterSolution = Enumerable.Range(0, ANTS_NUMBER)
                                                      .AsParallel()
                                                      .Select(_ =>
                                                      {
                                                          var ant = new Ant(timeTable, mmasData, week);
                                                          return !secondWeek ?
                                                              ant.GetSolution() :
                                                              ant.GetSolution(guidingAssignments);
                                                      })
                                                      .Min();

                // apply local search until local optimum is reached or a steps limit reached
                if (secondWeek)
                {
                    DEFAULT_MAX_STEPS = Math.Min(DEFAULT_MAX_STEPS + 50, 5000);
                    bestIterSolution.ResolveOnlyWeekSpecificConflicts = true;
                }
                bestIterSolution.LocalSearch(bestIterSolution.IsFeasible ? 3000 : DEFAULT_MAX_STEPS);

                // output the new best solution, if found
                if (bestIterSolution.CompareTo(bestSoFarSolution) < 0)
                {
                    bestIterSolution.CopyTo(bestSoFarSolution);
                    lastImprIter = currIter;
                }

                // update pheromones
                mmasData.EvaporatePheromone();
                mmasData.SetPheromoneLimits();
                if (bestIterSolution.ResolveOnlyWeekSpecificConflicts)
                    mmasData.DepositPheromone(bestIterSolution);
                else
                    mmasData.DepositPheromone(bestSoFarSolution);

                currIter++;
                Console.WriteLine("iter: {0}, HCV: {1}, SCV: {2}", currIter, bestSoFarSolution.Hcv, bestSoFarSolution.Scv);
            }

            bestSoFarSolution.ComputeHcv();
            bestSoFarSolution.ComputeScv();
            Console.WriteLine("RAW: HCV: {0}, SCV: {1}", bestSoFarSolution.Hcv, bestSoFarSolution.Scv);

            problemData.PrepareSuitableTimeSlots(true);

            bestSoFarSolution.TryResolveHcv();
            bestSoFarSolution.ComputeHcv();
            bestSoFarSolution.ComputeScv();
            Console.WriteLine("RESOLVE: HCV: {0}, SCV: {1}", bestSoFarSolution.Hcv, bestSoFarSolution.Scv);

            bestSoFarSolution.LocalSearch(10000, 1, 1); //try to resolve scv
            bestSoFarSolution.ComputeHcv();
            bestSoFarSolution.ComputeScv();
            Console.WriteLine("RESULT: HCV: {0}, SCV: {1}", bestSoFarSolution.Hcv, bestSoFarSolution.Scv);

            return bestSoFarSolution;
        }
开发者ID:ramazanalic,项目名称:savkin-timetable-scheduler,代码行数:80,代码来源:Scheduler.cs


注:本文中的Solution.LocalSearch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。