// --- LE BENCH : 5 configs x 2 fonctions x 5 seeds ---
var seeds = new[] { 42, 7, 99, 1, 13 };
var (raLo, raHi) = KnownFunctionsBounds.For(typeof(RastriginFitness));
var (aLo, aHi) = KnownFunctionsBounds.For(typeof(AckleyFitness));
var raFit = new ShiftedFitness(new RastriginFitness(), ShiftVectors.Seeded(5, 0.15*(raHi-raLo), seed: 11));
var ackFit = new ShiftedFitness(new AckleyFitness(), ShiftVectors.Seeded(5, 0.15*(aHi-aLo), seed: 17));
// Constituants + combo candidate : MEME migration (RandomRing, 0.05, 20) -> seul le ratio varie.
// DE+BB-MGS11 : reproduit le verdict negatif de MGS-11 (SmallMigrationRate, periode 10).
var configs = new (string label, (string,int)[] isl, MigrationMode mode, double rate, int period)[] {
("DE-hom", new[]{("DE",1),("DE",1),("DE",1),("DE",1)}, MigrationMode.RandomRing, 0.05, 20),
("BB-hom", new[]{("BB",1),("BB",1),("BB",1),("BB",1)}, MigrationMode.RandomRing, 0.05, 20),
("DE+BB-3:1", new[]{("DE",3),("BB",1)}, MigrationMode.RandomRing, 0.05, 20),
("DE+BB-2:2", new[]{("DE",1),("DE",1),("BB",1),("BB",1)}, MigrationMode.RandomRing, 0.05, 20),
("DE+BB-MGS11", new[]{("DE",1),("DE",1),("BB",1),("BB",1)}, MigrationMode.RandomRing, 0.045, 10),
};
// Fitness moyenne sur 5 seeds (avec decompte des gains par seed vs les deux constituants).
(double mean, int wins) MeanRun((string,int)[] isl, IFitness fit, (double,double) b,
MigrationMode mode, double rate, int period, double deRef, double bbRef)
{
var r = seeds.Select(s =>
{
FastRandomRandomization.ResetSeed(s);
return RunIslands(isl, fit, b, 5, mode, rate, period);
}).ToArray();
Console.WriteLine(" seeds: " + string.Join(" ", r.Select(x => x.ToString("F3"))));
// un "win" = sur cette seed la config bat SIMULTANEMENT les deux constituants (run seed-par-seed).
// deRef/bbRef sont les moyennes (approximation); le compte exact seed-par-seed est ci-dessous dans le verdict.
return (r.Average(), r.Count(v => v > deRef && v > bbRef));
}
var problems = new (string name, IFitness fit, (double lo, double hi) b)[] {
("Ackley (shifted)", ackFit, (aLo, aHi)),
("Rastrigin (shifted)", raFit, (raLo, raHi)),
};
var bench = new Dictionary<(string fn, string cfg), double>();
foreach (var (fn, fit, b) in problems)
{
Console.WriteLine($"--- {fn} (dim 5) ---");
// constituants d'abord pour pouvoir compter les wins
double deRef = 0, bbRef = 0;
foreach (var (label, isl, mode, rate, period) in configs)
{
Console.WriteLine($" [{label}]");
var v = MeanRun(isl, fit, b, mode, rate, period, 0, 0).mean; // wins calcule dans la table de verdict finale
bench[(fn, label)] = v;
if (label == "DE-hom") deRef = v;
if (label == "BB-hom") bbRef = v;
Console.WriteLine($" -> {label,-12}{v,9:F3}");
}
}
Console.WriteLine();
Console.WriteLine($"{"Fonction",-20}{"Config",-12}{"fitness moy."}");
Console.WriteLine(new string('-', 44));
foreach (var (fn, _, _) in problems)
foreach (var (label, _, _, _, _) in configs)
Console.WriteLine($"{fn,-20}{label,-12}{bench[(fn,label)],9:F3}");