Beispiel #1
0
        public void ValidateTestManagerItemAttributes()
        {
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, 10, 0, 0);
            //<Item ID="1" Value="20" Weight="22" Volume="13"></Item>
            KSItem item = tm.ItemList.Find(i => i.Id == 1);

            Assert.Equal(20, item.Value);
            Assert.Equal(22, item.Weight);
            Assert.Equal(13, item.Volume);
        }
Beispiel #2
0
        public void Run5ItemTestLargeWeightCombinations(TestType type)
        {
            KnapsackTestManager tm   = CreateTestManager(TestData.KSItemList, 5, 500);
            KnapSackTest        test = (KnapSackTest)CreateTest(type);

            TimeSpan t = tm.RunTest(test);

            Assert.Equal(16, test.OptimalSolution.Result.Value);
            Assert.Equal(18, test.OptimalSolution.Result.Weight);
            Assert.Equal(17, test.OptimalSolution.Result.Volume);
        }
Beispiel #3
0
        public void ValidateTestManagerItemAttributes()
        {
            //<Item Id="1" Value="1" Weight="2" Volume="5"></Item>
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, 5, 100, 100);

            KSItem item = tm.ItemList.Find(i => i.Id == 1);

            Assert.Equal(1, item.Value);
            Assert.Equal(2, item.Weight);
            Assert.Equal(5, item.Volume);
        }
Beispiel #4
0
        public void Run5ItemTestMidWeightDynamic(TestType type)
        {
            KnapsackTestManager tm   = CreateTestManager(TestData.KSItemList, 5, 10);
            KnapSackTest        test = (KnapSackTest)CreateTest(type);

            TimeSpan t = tm.RunTest(test);

            Assert.Equal(12, test.OptimalSolution.Result.Value);
            Assert.Equal(9, test.OptimalSolution.Result.Weight);
            Assert.Equal(9, test.OptimalSolution.Result.Volume);
            Assert.Equal(3, test.OptimalSolution.Solution.Count);
        }
Beispiel #5
0
        public void OneD_Mid_10_Items(TestType type)
        {
            KnapsackTestManager TM   = CreateTestManager(TestData.KSItemList, 10, 100);
            KnapSackTest        test = (KnapSackTest)CreateTest(type);
            TimeSpan            t    = TM.RunTest(test);

            Assert.Equal(217, test.OptimalSolution.Result.Value);
            Assert.Equal(90, test.OptimalSolution.Result.Weight);
            Assert.Equal(167, test.OptimalSolution.Result.Volume);
            Assert.Equal(6, test.OptimalSolution.Solution.Count);

            long testSolutionCnt = TestSolutions(type, TM.ItemList.Count, TM.MaxWeight, TM.MaxVolume);

            Assert.Equal(testSolutionCnt, test.SolutionCount);
        }
Beispiel #6
0
        public void TwoD_Zero_10Items(TestType type)
        {
            KnapsackTestManager TM = CreateTestManager(TestData.KSItemList, 10, 0, 0);

            KnapSackTest test = (KnapSackTest)CreateTest(type);
            TimeSpan     t    = TM.RunTest(test);

            Assert.Equal(0, test.OptimalSolution.Result.Value);
            Assert.Equal(0, test.OptimalSolution.Result.Weight);
            Assert.Equal(0, test.OptimalSolution.Result.Volume);
            Assert.Empty(test.OptimalSolution.Solution);

            long testSolutionCnt = TestSolutions(type, TM.ItemList.Count, TM.MaxWeight, TM.MaxVolume);

            Assert.Equal(testSolutionCnt, test.SolutionCount);
        }
Beispiel #7
0
        public void TwoD_Mid_2_25_Items(TestType type)
        {
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, 25, 425, 550);

            KnapSackTest test = (KnapSackTest)CreateTest(type);
            TimeSpan     t    = tm.RunTest(test);

            Assert.Equal(664, test.OptimalSolution.Result.Value);
            Assert.Equal(422, test.OptimalSolution.Result.Weight);
            Assert.Equal(517, test.OptimalSolution.Result.Volume);
            Assert.Equal(21, test.OptimalSolution.Solution.Count);

            long testSolutionCnt = TestSolutions(type, tm);

            Assert.Equal(testSolutionCnt, test.SolutionCount);
        }
Beispiel #8
0
        public void TwoD_Large_20_Items(TestType type)
        {
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, 20, 1000, 440);

            KnapSackTest test = (KnapSackTest)CreateTest(type);
            TimeSpan     t    = tm.RunTest(test);

            Assert.Equal(554, test.OptimalSolution.Result.Value);
            Assert.Equal(426, test.OptimalSolution.Result.Weight);
            Assert.Equal(437, test.OptimalSolution.Result.Volume);
            Assert.Equal(18, test.OptimalSolution.Solution.Count);

            long testSolutionCnt = TestSolutions(type, tm);

            Assert.Equal(testSolutionCnt, test.SolutionCount);
        }
Beispiel #9
0
        public void TwoD_Mid_11_Items(TestType type)
        {
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, 11, 100, 150);

            KnapSackTest test = (KnapSackTest)CreateTest(type);
            TimeSpan     t    = tm.RunTest(test);

            Assert.Equal(208, test.OptimalSolution.Result.Value);
            Assert.Equal(87, test.OptimalSolution.Result.Weight);
            Assert.Equal(135, test.OptimalSolution.Result.Volume);
            Assert.Equal(6, test.OptimalSolution.Solution.Count);

            long testSolutionCnt = TestSolutions(type, tm);

            Assert.Equal(testSolutionCnt, test.SolutionCount);
        }
Beispiel #10
0
        public void TwoD_Large_10_Items(TestType type)
        {
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, 10, 500, 220);

            KnapSackTest test = (KnapSackTest)CreateTest(type);
            TimeSpan     t    = tm.RunTest(test);

            Assert.Equal(290, test.OptimalSolution.Result.Value);
            Assert.Equal(156, test.OptimalSolution.Result.Weight);
            Assert.Equal(209, test.OptimalSolution.Result.Volume);
            Assert.Equal(9, test.OptimalSolution.Solution.Count);

            long testSolutionCnt = TestSolutions(type, tm);

            Assert.Equal(testSolutionCnt, test.SolutionCount);
        }
Beispiel #11
0
 public KnapsackSolution(KnapsackTestManager tm)
 {
     TM = tm;
 }
Beispiel #12
0
        public void ValidateTestManagerVariableItemCountTooLarge(int itemCnt)
        {
            KnapsackTestManager TM = CreateTestManager(TestData.KSItemList, itemCnt, 1000);

            Assert.Empty(TM.ItemList);
        }
Beispiel #13
0
        public void ValidateTestManagerVariableItemCount(int itemCnt)
        {
            KnapsackTestManager TM = CreateTestManager(TestData.KSItemList, itemCnt, 1000);

            Assert.Equal(itemCnt, TM.ItemList.Count);
        }
Beispiel #14
0
 public long TestSolutions(TestType type, KnapsackTestManager tm)
 {
     return(TestSolutions(type, tm.ItemList.Count, tm.MaxWeight, tm.MaxVolume));
 }
Beispiel #15
0
        public void ValidateTestManagerVariableItemCount(int cnt)
        {
            KnapsackTestManager tm = CreateTestManager(TestData.KSItemList, cnt, 0, 0);

            Assert.Equal(cnt, tm.ItemList.Count);
        }