public void CompabilityDistanceFunction_Test() { float result = Genome.CompabilityDistanceFunction(parent1Genome, parent2Genome, 1f, 1, 0.4f, 20); Assert.AreEqual(6, result); result = Genome.CompabilityDistanceFunction(parent1Genome, parent2Genome, 5f, 4, 0.4f, 1); Assert.AreEqual(1.8f, result, 0.01f); }
/// <summary> /// Check if a species is for the given agent available /// </summary> /// <param name="agent">The agent that should be checked</param> /// <param name="species">List of species that will be checked</param> /// <returns>The first matching species or null if no species was found</returns> public Species IsSpeciesAvailableForAgent(AgentObject agent, List <Species> species) { foreach (Species s in species) { float distanceValue = Genome.CompabilityDistanceFunction(s.RepresentiveAgent.Genome, agent.Genome, _FACTOR_EXCESS_GENES, _FACTOR_DISJOINT_GENES, _FACTOR_AVG_WEIGHT_DIF, _THRESHOLD_NUMBER_OF_GENES); if (distanceValue <= _COMPABILITY_THRESHOLD) { //Species found return(s); } } return(null); }