private static void TestBinPackingRealistic() { const int size = 32; const int amount = 200; var packets = new List <Packet>(); var rnd = new Random(); for (int i = 0; i < 40 * amount; i++) { packets.Add(new Packet(null, rnd.Next(1, 6))); } for (int i = 0; i < 15 * amount; i++) { packets.Add(new Packet(null, rnd.Next(6, 20))); } for (int i = 0; i < 3 * amount; i++) { packets.Add(new Packet(null, rnd.Next(16, 33))); } var sws = new Stopwatch(); sws.Start(); var binsStupid = BinPackingSolvers.SolveStupid(new List <Packet>(packets), size); sws.Stop(); var swBf = new Stopwatch(); swBf.Start(); var binsBf = BinPackingSolvers.SolveBestFitMaybe(new List <Packet>(packets), size); swBf.Stop(); // Console.WriteLine("binsStupid:"); // printBin(binsStupid, size); // Console.WriteLine("binsBF:"); // printBin(binsBF, size); Console.WriteLine( $"binsStupid:{binsStupid.Count} {CalcFreeSpaceBins(binsStupid, size)} {sws.ElapsedMilliseconds}ms+{sws.ElapsedTicks}"); Console.WriteLine( $"binsBF:{binsBf.Count} {CalcFreeSpaceBins(binsBf, size)} {swBf.ElapsedMilliseconds}ms+{swBf.ElapsedTicks}"); Console.ReadKey(); }
private static void TestBinPacking() { List <Packet> packets = new List <Packet>(); const int min = 3; const int max = 8; const int size = 10; const int amount = 1; for (int j = 0; j < amount; j++) { for (int i = min; i <= max; i++) { packets.Add(new Packet(null, i)); } } var binsStupid = BinPackingSolvers.SolveStupid(new List <Packet>(packets), size); var binsBf = BinPackingSolvers.SolveBestFitMaybe(new List <Packet>(packets), size); Console.WriteLine($"binsStupid:{binsStupid.Count} {CalcFreeSpaceBins(binsStupid, size)}"); PrintBin(binsStupid, size); Console.WriteLine($"binsBF:{binsBf.Count} {CalcFreeSpaceBins(binsBf, size)}"); PrintBin(binsBf, size); Console.WriteLine("now random numbers"); packets = new List <Packet>(); var rnd = new Random(); for (int i = 0; i < (max - min + 1) * amount; i++) { packets.Add(new Packet(null, rnd.Next(min, max))); } binsStupid = BinPackingSolvers.SolveStupid(new List <Packet>(packets), size); binsBf = BinPackingSolvers.SolveBestFitMaybe(new List <Packet>(packets), size); Console.WriteLine($"binsStupid:{binsStupid.Count} {CalcFreeSpaceBins(binsStupid, size)}"); PrintBin(binsStupid, size); Console.WriteLine($"binsBF:{binsBf.Count} {CalcFreeSpaceBins(binsBf, size)}"); PrintBin(binsBf, size); Console.ReadKey(); }