/// <summary> /// Generate a selection of randomly generated individuals. /// low range 0-0.5, high range 0.5-1.0. /// </summary> public void InitiatePopulation() { Random random = new Random(); for (int i = 0; i < populationSize; i++) { population.Add(new IndividualFP()); List <RuleFP> rulesToAdd = new List <RuleFP>(); for (int r = 0; r < numberOfRules; r++) { var currentRule = new RuleFP(); for (int c = 0; c < boundryLength; c++) { RuleFPBoundry conditionToAdd = null; var low = random.NextDouble() / 2; // 0 - 0.5 var high = 0.5 + random.NextDouble() / 2; // 0.5 - 1.0 conditionToAdd = new RuleFPBoundry((float)low, (float)high); currentRule.condBoundry.Add(conditionToAdd); } // Output (0,1) currentRule.output = random.Next(2); rulesToAdd.Add(currentRule); } population[i].Rulebase = rulesToAdd; } }
/// <summary> /// Used for cloning purposes. /// </summary> /// <param name="clonedRule"></param> public RuleFP(RuleFP clonedRule) { this.condBoundry = new List <RuleFPBoundry>(); this.output = clonedRule.output; this.fitness = clonedRule.fitness; foreach (var condBoundry in clonedRule.condBoundry) { this.condBoundry.Add(new RuleFPBoundry(condBoundry)); } }
/// <summary> /// Checks that Each RuleFPBoundry's range is inclusive of the supplied Data's condition. /// </summary> /// <param name="rule"></param> /// <param name="inputData"></param> /// <returns></returns> private bool ConditionsMatch(RuleFP rule, DataFP inputData) { for (int i = 0; i < rule.condBoundry.Count; i++) { if (rule.condBoundry[i].low > inputData.cond[i] || rule.condBoundry[i].high < inputData.cond[i]) { return(false); } } return(true); }