/// <param name="pop">Population pattern</param> /// <param name="loc">The location used to decide if this object /// can subscribe to a given station.</param> public StationListenerImpl(BasePopulation pop, Location loc) { this.population = pop; this.location = loc; stations = new ArrayList(MaxStationCount); if (population != null) { attachToStation(); // attach to the existing station if any } }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="ownerId"></param> public EntityBuilderInternal(XmlElement e, string ownerId) { XmlNode nameNode = e.SelectSingleNode("name"); XmlNode groupNode = e.SelectSingleNode("group"); _name = (nameNode != null) ? nameNode.InnerText : (groupNode != null ? groupNode.InnerText : null); if (Name == null) { throw new FormatException("<name> and <group> are both missing"); } price = int.Parse(XmlUtil.SelectSingleNode(e, "price").InnerText); _computerCannotBuild = (e.SelectSingleNode("computerCannotBuild") != null); _playerCannotBuild = (e.SelectSingleNode("playerCannotBuild") != null); XmlElement pop = (XmlElement)e.SelectSingleNode("population"); if (pop != null) { _population = new PersistentPopulation(BasePopulation.Load(pop), new PopulationReferenceImpl(ownerId)); } }
//HACKS TODO protected override void Evolve(EvaluatorBase evaluator) { var offspringPopulationSize = Parameters.OffspringPopulationSize; //var stdDevsMutationTime = TimeSpan.Zero; //var rotationsMutationTime = TimeSpan.Zero; //var objectMutationTime = TimeSpan.Zero; //var evaluationTime = TimeSpan.Zero; //var stoper = new Stopwatch(); for (var i = 0; i < offspringPopulationSize; i++) { OffspringPopulation[i] = ParentsSelector.Select(BasePopulation); if (Parameters.TrackEvolutionSteps) { CurrentMutation = new MutationStep(ParentsSelector.LastSelectedParentIndex, OffspringPopulation[i]); } //stoper.Restart(); OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //stdDevsMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //rotationsMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]); //stoper.Stop(); //objectMutationTime += stoper.Elapsed; //stoper.Restart(); OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]); //stoper.Stop(); //evaluationTime += stoper.Elapsed; if (Parameters.TrackEvolutionSteps) { CurrentMutation.Offspring = OffspringPopulation[i].DeepCopyByExpressionTree(); CurrentEvolutionStep.Mutations.Add(CurrentMutation); } } //stoper.Restart(); BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation); //stoper.Stop(); //Statistics.MeanSurvivorsSelectionTime += stoper.Elapsed; //Statistics.MeanStdDevsMutationTime += TimeSpan.FromTicks(stdDevsMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanRotationsMutationTime += TimeSpan.FromTicks(rotationsMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanObjectMutationTime += TimeSpan.FromTicks(objectMutationTime.Ticks / offspringPopulationSize); //Statistics.MeanEvaluationTime += TimeSpan.FromTicks(evaluationTime.Ticks / offspringPopulationSize); if (Parameters.TrackEvolutionSteps) { CurrentEvolutionStep.NewPopulation = BasePopulation.DeepCopyByExpressionTree(); } }