コード例 #1
0
        public KnapsackProcessor(XElement[] elements, int capacity)
        {
            _elements = elements;
            _capacity = capacity;
            _elementsCount = elements.Length;

            previousColumn = new int[capacity + 1];
            currentColumn = new int[capacity + 1];

            maxIndex = 0;
            maxValue = 0;

            Directory.CreateDirectory("./tempData");
        }
コード例 #2
0
        private static void ParseInput(string filePath)
        {
            Stream str = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            using (var sr = new StreamReader(str))
            {
                string[] strings = sr.ReadLine().Split(' ');
                int N = Convert.ToInt32(strings.First());
                int K = Convert.ToInt32(strings.Last());

                XElement[] elements = new XElement[N];
                for (int i = 0; i < N; i++)
                {
                    string[] element = sr.ReadLine().Split(' ');
                    int val = Convert.ToInt32(element.First());
                    int weight = Convert.ToInt32(element.Last());
                    elements[i] = new XElement(val, weight);
                }

                _knapsackProcessor = new KnapsackProcessor(elements, K);
            }
            str.Close();
        }