Exemplo n.º 1
0
        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();*/
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public void SmallKnapsack()
        {
            var sut = new UnboundedKnapsack();

            Assert.Equal(100, sut.GetMaxGain(new[] { 1, 50 }, new[] { 1, 30 }, 100));
        }
Exemplo n.º 4
0
        public void Baseline()
        {
            var sut = new UnboundedKnapsack();

            Assert.Equal(300, sut.GetMaxGain(new[] { 5, 10, 15 }, new[] { 10, 30, 20 }, 100));
        }