public Plan SA(Instance inst, int k, int noise, double temp = 0.01, int max_it = 100) { Plan best_plan = Heuristics.CreateInitialPlan(inst, noise, max_it); double best_obj = best_plan.QualityPlan().tot_rank; double t0 = best_obj * temp; double tf = t0 * temp; double t = t0; double c = Math.Pow(tf / t0, 1 / (double)max_it); Plan current_plan = Plan.Copy(best_plan); for (int i = 0; i < max_it; i++) { Plan neighbor_plan = Plan.Copy(current_plan); neighbor_plan = Heuristics.Ruin(inst, neighbor_plan, k); neighbor_plan = Heuristics.Recreate(inst, neighbor_plan, noise); List <Plan> ps = Heuristics.CompareSA(best_plan, neighbor_plan, current_plan, t); best_plan = (ps[0] != null) ? Plan.Copy(ps[0]) : best_plan; current_plan = (ps[1] != null) ? Plan.Copy(ps[1]) : current_plan; t *= c; } return(best_plan); }
public Plan RuinRecreate(Instance inst, int k, int noise, int max_it = 100) { Plan best_plan = Heuristics.CreateInitialPlan(inst, noise, max_it); for (int i = 0; i < max_it; i++) { Plan star_plan = Plan.Copy(best_plan); star_plan = Heuristics.Ruin(inst, star_plan, k); star_plan = Heuristics.Recreate(inst, star_plan, noise); best_plan = Heuristics.CompareRR(best_plan, star_plan); } return(best_plan); }
// Genera 4 piani ordinati per: memoria, rank, rank/memoria, rank/memoria disturbato public static void GeneratePlans(Instance instance) { //Console.WriteLine("Test Piano in ordine di memoria"); //instance.SortARDTOsByMemory(); //Plan plan_mem = new Plan(instance); //plan_mem.BuildPlan(); //plan_mem.QualityPlan().PrintQuality(); //Console.WriteLine("\nTest Piano in ordine di rank"); //instance.SortARDTOsByDecreasingRank(); //Plan plan_rank = new Plan(instance); //plan_rank.BuildPlan(); //plan_rank.QualityPlan().PrintQuality(); //Console.WriteLine("\nTest Piano in ordine di rank/memoria"); //instance.SortARDTOsByDecreasingRankOverMemory(); //Plan plan_rankmem = new Plan(instance); //plan_rankmem.BuildPlan(); //plan_rankmem.QualityPlan().PrintQuality(); Console.WriteLine("\nTest Piano in ordine di rank/memoria disturbato"); Plan plan_noisyrankmem = Heuristics.CreateInitialPlan(instance, noise, max_it); plan_noisyrankmem.QualityPlan().PrintQuality(); //Stopwatch watch = Stopwatch.StartNew(); //Plan rr = RuinRecreate(instance, plan_noisyrankmem, max_it); //Console.WriteLine("--------------------------------"); //rr.QualityPlan().PrintQuality(); //watch.Stop(); //var elapsedMs = watch.ElapsedMilliseconds; //Console.WriteLine("Tempo: " + elapsedMs + " ms"); //watch = Stopwatch.StartNew(); //Plan sa = SA(instance, plan_noisyrankmem, t_max, max_it); //Console.WriteLine("--------------------------------"); //sa.QualityPlan().PrintQuality(); //watch.Stop(); //elapsedMs = watch.ElapsedMilliseconds; //Console.WriteLine("Tempo: " + elapsedMs + " ms"); }