Пример #1
0
 public void StealWhenInCity(CityElement city)
 {
     if (city.itemsInTheCity.Count != 0)
     {
         ItemElement element = ChoosePerfectItem(city.itemsInTheCity);
         if (element != null)
         {
             knapsack.Add(element);
             SetParametersOfKnapsack(element);
             SetSpeedOfThief();
         }
     }
 }
        public void LoadFile()
        {
            DataLoaded dataLoaded = DataLoaded.GetInstance();

            try
            {
                string[] allLines = File.ReadAllLines(Utilities.FILE_NAME);
                dataLoaded.problemName         = allLines[0].Split(' ')[2].Trim();
                dataLoaded.totalNumberOfCities = int.Parse(ExtractData(allLines[2])[1]);

                dataLoaded.totalNumberOfItems = int.Parse(ExtractData(allLines[3])[3]);
                dataLoaded.capacityOfKnapsack = int.Parse(ExtractData(allLines[4])[3]);
                dataLoaded.minimumSpeed       = double.Parse(ExtractData(allLines[5])[2], CultureInfo.InvariantCulture);
                dataLoaded.maximumSpeed       = double.Parse(ExtractData(allLines[6])[2], CultureInfo.InvariantCulture);

                int      counter = 10; //10 linijka to pierwsze dane o miastach
                string[] line    = ExtractData(allLines[counter]);

                List <CityElement> allParsedCities = new List <CityElement>();

                line = ExtractData(allLines[counter]);
                dataLoaded.cities = new List <CityElement>();

                while (line[0] != "ITEMS")
                {
                    dataLoaded.cities.Add(new CityElement(int.Parse(line[0]), double.Parse(line[1], CultureInfo.InvariantCulture), double.Parse(line[2], CultureInfo.InvariantCulture)));
                    counter++;
                    line = ExtractData(allLines[counter]);
                }

                while (counter < allLines.Length - 1)
                {
                    counter++;
                    line = ExtractData(allLines[counter]);

                    ItemElement item = new ItemElement(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2]), int.Parse(line[3]));
                    dataLoaded.cities[item.assignedNodeNumber - 1].itemsInTheCity.Add(item);
                }
            }
            catch (IOException e)
            {
                WriteLine("Nie udało się odczytać pliku " + e);
            }
            catch (Exception e)
            {
                WriteLine("Problem z parsowaniem " + e);
            }
        }
Пример #3
0
 private void SetParametersOfKnapsack(ItemElement element)
 {
     currentValueOfItems  += element.profit;
     currentWeightOfItems += element.weight;
 }