private static void UnboundedKnapsackTest(int seed, int size, int weight) { Stopwatch stopwatch = new Stopwatch(); double ts; int W = weight; int[] val = RndIntArray(seed, size); int[] wt = RndIntArray(seed, size); int n = size; //W = 100; //val = new int[] { 10, 30, 20, 20, 15 }; //wt = new int[] { 5, 10, 15, 20, 2 }; //n = val.Length; stopwatch.Reset(); stopwatch.Start(); Console.Write("Rezultatas: " + UnboundedKnapsack.UnboundedKnapsackDynamic(n, W, val, wt) + " "); stopwatch.Stop(); ts = stopwatch.Elapsed.TotalSeconds; Console.WriteLine("Unbounded Knapsack Dynamic - kiekis: {0} laikas: {1}", n, ts.ToString()); Console.Beep(); /*stopwatch.Reset(); * stopwatch.Start(); * Console.Write("Rezultatas: " + UnboundedKnapsack.UnboundedKnapsackRecursive(W, wt, val, n) + " "); * stopwatch.Stop(); * ts = stopwatch.Elapsed.TotalSeconds; * Console.WriteLine("Unbounded Knapsack Recursive - kiekis: {0} laikas: {1}", n, ts.ToString()); * Console.Beep();*/ }
private static void TestUnboundedKnapsack() { UnboundedKnapsack ks = new UnboundedKnapsack(); int[] profits = { 15, 50, 60, 90 }; int[] weights = { 1, 3, 4, 5 }; Console.WriteLine(ks.GetMaximumProfit(profits, weights, 8)); Console.WriteLine(ks.GetMaximumProfit(profits, weights, 6)); }
public void SmallKnapsack() { var sut = new UnboundedKnapsack(); Assert.Equal(100, sut.GetMaxGain(new[] { 1, 50 }, new[] { 1, 30 }, 100)); }
public void Baseline() { var sut = new UnboundedKnapsack(); Assert.Equal(300, sut.GetMaxGain(new[] { 5, 10, 15 }, new[] { 10, 30, 20 }, 100)); }