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