Beispiel #1
0
        /// <summary>
        /// Test 0-1 knapsack problem with random values and weights.
        /// </summary>
        public void TestCase0()
        {
            const int    TOTAL_ITEMS_NUM = 20;
            const double WEIGHT_MEAN     = 4.0;
            const double VALUE_MEAN      = 10.0;
            const double CAPACITY        = 40.0;

            var        v  = KnapsackSol.GenerateGroceries(TOTAL_ITEMS_NUM, WEIGHT_MEAN, VALUE_MEAN, 1);
            WeightNode wn = KnapsackSol.Process(v, CAPACITY);

            Console.WriteLine(wn.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Test 0-1 knapsack problem with fixed values and weights.
        /// </summary>
        public void TestCase1()
        {
            const int    ITEM_NUM          = 10;
            const double KNAPSACK_CAPACITY = 30;

            double[] weight = new double[ITEM_NUM] {
                1, 9, 3, 6, 5, 4, 7, 2, 8, 10
            };
            double[] price = new double[ITEM_NUM] {
                2, 8, 9, 4, 7, 3, 1, 6, 5, 10
            };
            List <Item> l  = KnapsackSol.GenerateItems(weight, price);
            WeightNode  wn = KnapsackSol.Process(l, KNAPSACK_CAPACITY);

            Console.Write(wn.ToString());
        }