//---------------------------------------------------------------------
 /// <summary>
 /// constructor, assign members of the stucture
 /// </summary>
 public InclusionRule(string inclusion_type,
     AgeRange age_range,
     string temp_percent,
     List<string> species_list)
 {
     //assign members of the struct
     this.inclusion_type = inclusion_type;
     this.age_range = age_range;
     //check for type 'percentage' by looking for the % character
     string [] split = temp_percent.Split(new char [] {'%'});
     //try to make a percentage.  if this doesn't work then check for keyword 'highest'
     try {
         percentOfCells = ((double) Convert.ToInt32(split[0])) / 100;
     }
     catch (Exception) {
         //and set percentOfCells to -1 (the flag for InclusionRequirement to handle)
         percentOfCells = -1;
     }
     this.species_list = species_list;
     //get the species index list using species name
     this.species_index_list = new List<int>();
     foreach (string species in species_list) {
         if (Model.Core.Species[species] != null)
         {
             this.species_index_list.Add(Model.Core.Species[species].Index);
         }
     }
     //Model.Core.UI.WriteLine("species index = {0}", this.species_index);
 }
        //---------------------------------------------------------------------

    	/// <summary>
        /// Is a particular age included among the set of specific ages and ranges?
        /// </summary>
        public bool Contains(ushort age, out AgeRange? containingRange)
        {
            containingRange = null;
            if (ages.Contains(age))
                return true;
            foreach (AgeRange range in ranges)
            {
                if (range.Contains(age))
                {
                    containingRange = range;
                    return true;
                }
            }
            return false;
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Validates a cohort age or age range against previous ages and
        /// ranges.
        /// </summary>
        /// <param name="ageOrRange">
        /// The age or age range that's being validated.
        /// </param>
        /// <param name="ages">
        /// List of previous ages.
        /// </param>
        /// <param name="ranges">
        /// List of previous ranges.
        /// </param>
        /// <remarks>
        /// If the age or range is validated, it is added to the corresponding
        /// list.
        /// </remarks>
        protected void ValidateAgeOrRange(InputValue <AgeRange> ageOrRange,
                                          List <ushort> ages,
                                          List <AgeRange> ranges)
        {
            if (ageOrRange.String.Contains("-"))
            {
                AgeRange range = ageOrRange.Actual;

                //  Does the range contain any individual ages?
                foreach (ushort age in ages)
                {
                    if (range.Contains(age))
                    {
                        throw new InputValueException(ageOrRange.String,
                                                      "The range {0} contains the age {1}",
                                                      ageOrRange.String, age);
                    }
                }

                //  Does the range overlap any previous ranges?
                foreach (AgeRange previousRange in ranges)
                {
                    if (range.Overlaps(previousRange))
                    {
                        throw new InputValueException(ageOrRange.String,
                                                      "The range {0} overlaps the range {1}-{2}",
                                                      ageOrRange.String, previousRange.Start, previousRange.End);
                    }
                }

                ranges.Add(range);
            }
            else
            {
                ushort age = ageOrRange.Actual.Start;

                //  Does the age match any of the previous ages?
                foreach (ushort previousAge in ages)
                {
                    if (age == previousAge)
                    {
                        throw new InputValueException(ageOrRange.String,
                                                      "The age {0} appears more than once",
                                                      ageOrRange.String);
                    }
                }

                //  Is the age in any of the previous ranges?
                foreach (AgeRange previousRange in ranges)
                {
                    if (previousRange.Contains(age))
                    {
                        throw new InputValueException(ageOrRange.String,
                                                      "The age {0} lies within the range {1}-{2}",
                                                      ageOrRange.String, previousRange.Start, previousRange.End);
                    }
                }

                ages.Add(age);
            }
        }