/** Assign the individual into a species, if not found, create a new one */ public void Speciate(IEvolutionState state, Individual ind) { NEATIndividual neatInd = (NEATIndividual)ind; // For each individual, search for a subspecies it is compatible to if (Subspecies.Count == 0) // not subspecies available, create the // first species { NEATSubspecies newSubspecies = (NEATSubspecies)SubspeciesPrototype.EmptyClone(); newSubspecies.Reset(); Subspecies.Add(newSubspecies); newSubspecies.AddNewGenIndividual(neatInd); } else { bool found = false; foreach (NEATSubspecies s in Subspecies) { NEATIndividual represent = (NEATIndividual)s.NewGenerationFirst(); if (represent == null) { represent = (NEATIndividual)s.First(); } // found compatible subspecies, add this individual to it if (Compatibility(neatInd, represent) < CompatThreshold) { s.AddNewGenIndividual(neatInd); found = true; // change flag break; // search is over, quit loop } } // if we didn't find a match, create a new subspecies if (!found) { NEATSubspecies newSubspecies = (NEATSubspecies)SubspeciesPrototype.EmptyClone(); newSubspecies.Reset(); Subspecies.Add(newSubspecies); newSubspecies.AddNewGenIndividual(neatInd); } } }
public override void Setup(IEvolutionState state, IParameter paramBase) { IParameter def = DefaultBase; NodePrototype = (NEATNode)state.Parameters.GetInstanceForParameterEq(paramBase.Push(P_NODE), def.Push(P_NODE), typeof(NEATNode)); NodePrototype.Setup(state, paramBase.Push(P_NODE)); SubspeciesPrototype = (NEATSubspecies)state.Parameters.GetInstanceForParameterEq( paramBase.Push(P_SUBSPECIES), def.Push(P_SUBSPECIES), typeof(NEATSubspecies)); SubspeciesPrototype.Setup(state, paramBase.Push(P_SUBSPECIES)); InnovationPrototype = (NEATInnovation)state.Parameters.GetInstanceForParameterEq( paramBase.Push(P_INNOVATION), def.Push(P_INNOVATION), typeof(NEATInnovation)); SubspeciesPrototype.Setup(state, paramBase.Push(P_INNOVATION)); NetworkPrototype = (NEATNetwork)state.Parameters.GetInstanceForParameterEq(paramBase.Push(P_NETWORK), def.Push(P_NETWORK), typeof(NEATNetwork)); NetworkPrototype.Setup(state, paramBase.Push(P_NETWORK)); // make sure that super.setup is done AFTER we've loaded our gene // prototype. base.Setup(state, paramBase); Subspecies = new List <NEATSubspecies>(); Innovations = new Dictionary <NEATInnovation, NEATInnovation>(); HighestFitness = 0; HighestLastChanged = 0; // Load parameters from the parameter file // Load parameters from the parameter file WeightMutationPower = state.Parameters.GetDouble(paramBase.Push(P_WEIGHT_MUT_POWER), def.Push(P_WEIGHT_MUT_POWER), 2.5); DisjointCoeff = state.Parameters.GetDouble(paramBase.Push(P_DISJOINT_COEFF), def.Push(P_DISJOINT_COEFF), 1.0); ExcessCoeff = state.Parameters.GetDouble(paramBase.Push(P_EXCESS_COEFF), def.Push(P_EXCESS_COEFF), 1.0); MutDiffCoeff = state.Parameters.GetDouble(paramBase.Push(P_MUT_DIFF_COEFF), def.Push(P_MUT_DIFF_COEFF), 0.4); CompatThreshold = state.Parameters.GetDouble(paramBase.Push(P_COMPAT_THRESH), def.Push(P_COMPAT_THRESH), 3.0); AgeSignificance = state.Parameters.GetDouble(paramBase.Push(P_AGE_SIGNIFICANCE), def.Push(P_AGE_SIGNIFICANCE), 1.0); SurvivalThreshold = state.Parameters.GetDouble(paramBase.Push(P_SURVIVIAL_THRESH), def.Push(P_SURVIVIAL_THRESH)); MutateOnlyProb = BoundProbabilityParameter(state, paramBase, P_MUTATE_ONLY_PROB, "Mutate only probability"); MutateLinkWeightsProb = BoundProbabilityParameter(state, paramBase, P_MUTATE_LINK_WEIGHT_PROB, "Mutate Link Weight probability"); MutateToggleEnableProb = BoundProbabilityParameter(state, paramBase, P_MUTATE_TOGGLE_ENABLE_PROB, "Mutate Toggle Enable probability"); MutateGeneReenableProb = BoundProbabilityParameter(state, paramBase, P_MUTATE_GENE_REENABLE_PROB, "Mutate Gene Reenable"); MutateAddNodeProb = BoundProbabilityParameter(state, paramBase, P_MUTATE_ADD_NODE_PROB, "Mutate Add Node probability"); MutateAddLinkProb = BoundProbabilityParameter(state, paramBase, P_MUTATE_ADD_LINK_PROB, "Mutate Add Link probability"); InterspeciesMateRate = BoundProbabilityParameter(state, paramBase, P_INTERSPECIES_MATE_PROB, "Interspecies Mate probability"); MateMultipointProb = BoundProbabilityParameter(state, paramBase, P_MATE_MULTIPOINT_PROB, "Mate Multipoint probability"); MateMultipointAvgProb = BoundProbabilityParameter(state, paramBase, P_MATE_MULTIPOINT_AVG_PROB, "Mate Multipoint Average probability"); MateSinglepointProb = BoundProbabilityParameter(state, paramBase, P_MATE_SINGLE_POINT_PROB, "Single Point probability"); MateOnlyProb = BoundProbabilityParameter(state, paramBase, P_MATE_ONLY_PROB, "Mate Only probability"); RecurOnlyProb = BoundProbabilityParameter(state, paramBase, P_RECUR_ONLY_PROB, "Recurrent Only probability"); DropoffAge = state.Parameters.GetInt(paramBase.Push(P_DROPOFF_AGE), def.Push(P_DROPOFF_AGE), 0); NewLinkTries = state.Parameters.GetInt(paramBase.Push(P_NEW_LINK_TRIES), def.Push(P_NEW_LINK_TRIES), 1); NewNodeTries = state.Parameters.GetInt(paramBase.Push(P_NEW_NODE_TRIES), def.Push(P_NEW_NODE_TRIES), 1); BabiesStolen = state.Parameters.GetInt(paramBase.Push(P_BABIES_STOLEN), def.Push(P_BABIES_STOLEN), 0); MaxNetworkDepth = state.Parameters.GetInt(paramBase.Push(P_MAX_NETWORK_DEPTH), paramBase.Push(P_MAX_NETWORK_DEPTH), 30); AddNodeMaxGenomeLength = state.Parameters.GetInt(paramBase.Push(P_ADD_NODE_MAX_GENOME_LENGTH), paramBase.Push(P_ADD_NODE_MAX_GENOME_LENGTH), 15); }