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); }
//Apllica l'algoritmo Simulated Annealing per ottenere un'ipotetica soluzione migliore public static Plan SA(Instance instance, Plan best_plan, double t_max, int max_it) { Console.WriteLine("--------------------------------"); Console.WriteLine("SIMULATED ANNEALING"); double best_obj = best_plan.QualityPlan().tot_rank; double t0 = best_obj * t_max; double tf = t0 * t_max; 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(instance, neighbor_plan, k_ruin); neighbor_plan = Heuristics.Recreate(instance, 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); }
//Apllica l'algoritmo Ruin&Recreate per ottenere un'ipotetica soluzione migliore public static Plan RuinRecreate(Instance instance, Plan best_plan, int max_it) { Console.WriteLine("--------------------------------"); Console.WriteLine("RUIN & RECREATE"); for (int i = 0; i < max_it; i++) { Plan star_plan = Plan.Copy(best_plan); star_plan = Heuristics.Ruin(instance, star_plan, k_ruin); star_plan = Heuristics.Recreate(instance, star_plan, noise); best_plan = Heuristics.CompareRR(best_plan, star_plan); } return(best_plan); }