Example #1
0
        /// <summary>
        /// Calculate the given nutrient's effect on the chromosome's cost (assuming this is the last nutrient added)
        /// If c is not provided, the winning chromosome will be used (if any)
        /// </summary>
        public float CalculateNutrientCostDifference(ushort nutrientId, float nutrientAmount, Chromosome c = null)
        {
            if (!HasWinner && c == null)
            {
                return(0);
            }
            else if (c == null)
            {
                c = winner;
            }

            var scoreSpace = (float[])null;

            return(scorer.ScoreDifference(c, new FoodNutrient[] { new FoodNutrient {
                                                                      nutrientId = nutrientId, nutrientAmount = nutrientAmount
                                                                  } }, ref scoreSpace));
        }
Example #2
0
        public float CalculateFoodCostDifference(int foodId, int count, ref float[] scoreSpace, Chromosome c)
        {
            var nutrientsToRemove = count == 1 ? nutrientsByFoodId[foodId] : //Minor optimization
                                    nutrientsByFoodId[foodId].Select(p => new FoodNutrient {
                foodId = p.foodId, nutrientId = p.nutrientId, nutrientAmount = p.nutrientAmount * count
            }).ToArray();

            return(scorer.ScoreDifference(c, nutrientsToRemove, ref scoreSpace));
        }