private void AddSupplements(List <AnimalFoodStoreType> types, AnimalFoodStore store) { // List of all supplement allocations (skipping metadata) var allocs = SuppAllocs.Elements().Skip(2).ToList(); // Indices of non-zero allocations var indices = from alloc in allocs where alloc.Elements().Select(e => e.Value).ToList().Exists(v => v != "0") select allocs.IndexOf(alloc); // List of all supplement specifications (skipping metadata) var supps = SuppSpecs.Elements().Skip(3).ToList(); // Collection of specifications with allocations var specs = from spec in supps where indices.Contains(supps.IndexOf(spec)) select new string[3] { spec.Name.LocalName, spec.Elements().ElementAt(1).Value, spec.Elements().ElementAt(2).Value }; foreach (var spec in specs) { types.Add(new AnimalFoodStoreType(store) { Name = spec[0], DMD = Convert.ToDouble(spec[1]), Nitrogen = Convert.ToDouble(spec[2]) }); } }
public NABSA(string path) { Source = XElement.Load(path); Name = Path.GetFileNameWithoutExtension(path); // General Data SingleParams = Source.Element("SingleParams"); // Land Data LandSpecs = Source.Element("LandSpecs"); // Labour Data Priority = FindByNameTag(Source, "Labour Number and Priority"); Supply = FindByNameTag(Source, "Labour Supply"); // Ruminant Data SuppAllocs = FindFirst(Source, "SuppAllocs"); SuppSpecs = FindFirst(Source, "SuppSpecs"); RumSpecs = FindFirst(Source, "RumSpecs"); Numbers = FindByNameTag(Source, "Startup ruminant numbers"); Ages = FindByNameTag(Source, "Startup ruminant ages"); Weights = FindByNameTag(Source, "Startup ruminant weights"); Prices = FindByNameTag(Source, "Ruminant prices"); Fodder = FindFirst(Source, "Fodder"); FodderSpecs = FindFirst(Source, "FodderSpecs"); // List of all possible breeds Breeds = SuppAllocs.Element("ColumnNames").Elements().Select(e => e.Value).ToList(); // Index of each breed var indices = from breed in Breeds select Breeds.IndexOf(breed); // Breeds that have a presence in the simulation PresentBreeds = from index in indices where ( // The total number of each breed from cohort in Numbers.Elements().Skip(1) select Convert.ToInt32(cohort.Elements().ToList()[index].Value) ).Sum() > 0 // Breeds with a non-zero number of ruminants present select Breeds.ElementAt(index); }