/// <summary> /// The get algorithm backpack algorith execution time in clock ticks. /// </summary> /// <param name="numberOfItems"> /// The nubmer of tested items. /// </param> /// <param name="backpackAlgorithm"> /// The type of tested backpack algorithm. /// </param> public void TestSingleAlgorithmExectionTime(int numberOfItems, AlgorithmType backpackAlgorithm) { int randomMaxSize = BackPackDataGenerator.GenerateRandomInput(numberOfItems, randomNumberLimit, out int[] itemsSizes, out int[] itemsValues); stopwatch.Start(); switch (backpackAlgorithm) { case AlgorithmType.DynamicHighestBackpackValue: { BackPack.GetHighestBackpackValue(ref itemsValues, ref itemsSizes, itemsSizes.Length, randomMaxSize); break; } case AlgorithmType.DynamicLowestBackpackSize: { BackPack.GetLowestBackpackSize(ref itemsValues, ref itemsSizes, itemsSizes.Length, randomMaxSize); break; } } stopwatch.Stop(); var elapsedTicks = stopwatch.ElapsedTicks; Console.WriteLine("{0}: {1} items, tested size: {2} ticks - {3}", backpackAlgorithm, itemsSizes.Length, randomMaxSize, elapsedTicks); }
/// <summary> /// The test example shown in the tutor. /// </summary> private static void TestExample() { var itemsValues = new int[] { 5, 1, 4, 2 }; var itemsSizes = new int[] { 6, 3, 4, 2 }; var highestValue = BackPack.GetHighestBackpackValue(ref itemsValues, ref itemsSizes, NumberOfItems, ItemsMaxSize); Console.WriteLine("Highest backpack value: " + highestValue); var lowestSize = BackPack.GetLowestBackpackSize(ref itemsValues, ref itemsSizes, NumberOfItems, ItemsMaxSize); Console.WriteLine("Lowest bakcpack size: " + lowestSize); }