本文整理汇总了C#中Population类的典型用法代码示例。如果您正苦于以下问题:C# Population类的具体用法?C# Population怎么用?C# Population使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Population类属于命名空间,在下文中一共展示了Population类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAll
public void LoadAll(Population pop,float curHouses)
{
LoadAllHouses(curHouses);
LoadAllPeople(pop);
LoadAllBiomes();
}
示例2: RunGA
private void RunGA(){
_teams = LoadTeams();
_winners = _teams.FindAll(l => l.Winner == true);
_losers = _teams.FindAll(l => l.Winner == false);
const double crossoverProbability = 0.85;
const double mutationProbability = 0.15;
const int elitismPercentage = 5;
var population = new Population(1000, 72, true, false, ParentSelectionMethod.TournamentSelection);
var elite = new Elite(elitismPercentage);
var crossover = new Crossover(crossoverProbability, true)
{
CrossoverType = CrossoverType.DoublePoint
};
var mutation = new BinaryMutate(mutationProbability, true);
var ga = new GeneticAlgorithm(population, EvaluateFitness);
ga.OnGenerationComplete += ga_OnGenerationComplete;
ga.Operators.Add(elite);
ga.Operators.Add(crossover);
ga.Operators.Add(mutation);
ga.Run(TerminateAlgorithm);
}
示例3: FitnessFunction
public override void FitnessFunction(Population population, GeneticAlgorithm.NextStepDelegate callback)
{
this.population = population;
InitiateNewSimulation();
simulating = true;
doneCallback = callback;
}
示例4: PopulationSimulator
public PopulationSimulator(int width, int height)
{
swarmInBirthOrder = new Species();
swarmInXOrder = new Species();
swarmInYOrder = new Species();
Population = new Population();
}
示例5: LoadAllPeople
private void LoadAllPeople(Population pop)
{
float errorCounter = 0;
float totalError = 0;
bool recklessPlacement = false;
for (int i = 0; i < pop.currentPopulation; ++i)
{
Vector2 creationSpot = new Vector2(Random.Range(-Globals.mapRadiusX, Globals.mapRadiusX), Random.Range(-Globals.mapRadiusY, Globals.mapRadiusY));
RaycastHit2D[] allHit = Physics2D.RaycastAll(creationSpot, -Vector2.up,0);
if (allHit.Length == 0 || recklessPlacement)
{
GameObject go = Instantiate(Resources.Load("Villager"), creationSpot, Quaternion.identity) as GameObject;
go.GetComponent<Villager>().Initialize(pop.averagePercentLifePoints, pop.averageHappiness, pop.averageHealthiness);
} else {
errorCounter++;
totalError++;
if (errorCounter > 10) //too much wait, that vilagers toast, next one
{
errorCounter = 0;
++i;
}
if (totalError > 40) //too much thrashing, just place them ontop other objects and hope unity forces them out
{
recklessPlacement = true;
}
}
}
}
示例6: DemoPlayerInputStrategy
public DemoPlayerInputStrategy()
{
var population = new Population (6, 6, new DemoPlayerChromosome ());
var fitness = new DemoPlayerFitness ();
var selection = new EliteSelection ();
var crossover = new OnePointCrossover (0);
var mutation = new UniformMutation (true);
m_ga = new GeneticAlgorithm (
population,
fitness,
selection,
crossover,
mutation);
m_ga.MutationProbability = 0.5f;
m_ga.GenerationRan += (sender, e) => {
m_bestChromossome = m_ga.BestChromosome as DemoPlayerChromosome;
if(m_bestChromossome.AvoidAliensProjectilesProbability > 0.9f) {
HorizontalDirection = 1f;
}
};
m_ga.Start ();
SHThread.PingPong (.01f, 0, 1, (t) => {
m_ga.Termination = new GenerationNumberTermination (m_ga.GenerationsNumber + 1);
m_ga.Resume();
return true;
});
}
示例7: Select
public override void Select(Population population, SelectionBuffer selection, GeneticAlgorithm.NextStepDelegate callback)
{
int size = 0;
// TODO: Implement settings for how to truncate.
float cutoff = 0;
switch (truncationMode) {
case TruncationMode.AboveMiddle:
cutoff = population.MinFitness + (population.MaxFitness - population.MinFitness)/2;
break;
case TruncationMode.AboveMean:
cutoff = population.MeanFitness;
break;
case TruncationMode.AboveMedian:
cutoff = population.MedianFitness;
break;
}
for (int i = 0; i < population.Size; i++) {
if (population[i].Fitness > cutoff) {
selection[size].CloneFrom(population[i].Genome);
size++;
}
}
selection.Size = size;
callback();
}
示例8: InitializePanelWithTrainerData
public void InitializePanelWithTrainerData() {
DebugBot.DebugFunctionCall("TPopUI; InitializePanelWithTrainerData(); ", debugFunctionCalls);
Trainer trainer = trainerModuleScript.gameController.masterTrainer;
if(trainer.PlayerList != null) {
int curPlayer = trainer.CurPlayer;
//Debug.Log ("InitializePanelWithTrainerData(), " + trainer.PlayerList[curPlayer-1].maxMaxPopulationSize.ToString());
//sliderMaxPopulationSize.minValue = trainer.PlayerList[curPlayer-1].minMaxPopulationSize;
//sliderMaxPopulationSize.maxValue = trainer.PlayerList[curPlayer-1].maxMaxPopulationSize;
//sliderMaxPopulationSize.value = trainer.PlayerList[curPlayer-1].maxPopulationSize;
if(trainer.PlayerList[curPlayer-1].masterPopulation != null) { // if the current player has a Population instance:
populationRef = trainer.PlayerList[curPlayer-1].masterPopulation; // get current population instance
//Current Population text:
textCurrentPopulationSize.text = "Current Population Size: " + (populationRef.isFunctional ? populationRef.masterAgentArray.Length.ToString() : "0"); // Update this later!!
//Current Max Population Size:
sliderMaxPopulationSize.minValue = minMaxPopulationSize; // set up slider bounds
sliderMaxPopulationSize.maxValue = maxMaxPopulationSize;
sliderMaxPopulationSize.value = populationRef.populationMaxSize;
textMaxPopulationSize.text = populationRef.populationMaxSize.ToString();
}
else { // Population hasn't been created yet:
//textMaxPopulationSize.text = trainer.PlayerList[curPlayer-1].maxPopulationSize.ToString();
}
}
valuesChanged = false;
applyPressed = false;
UpdateUIWithCurrentData();
}
示例9: AdvancePopulation
public Population AdvancePopulation(Population population)
{
var chromosomes = new List<Chromosome>();
population = new Population(population.Take((int)(TruncationRate * population.Count()))); // TRUNCATION
do
{
Chromosome chosen1 = selection.Select(population),
chosen2 = selection.Select(population);
if (random.NextDouble() < CrossoverRate)
{
var children = crossover.Crossover(chosen1, chosen2); // CROSSOVER
chosen1 = children.Item1;
chosen2 = children.Item2;
}
if (random.NextDouble() < MutationRate)
{
chosen1 = mutation.Mutate(chosen1); // MUTATION
}
if (random.NextDouble() < MutationRate)
{
chosen2 = mutation.Mutate(chosen2); // MUTATION
}
chromosomes.Add(chosen1);
chromosomes.Add(chosen2);
} while (chromosomes.Count < ChromosomeCount);
return new Population(chromosomes);
}
示例10: Resource
public Resource(ResourceType type, ResourceLevel level)
{
Type = type;
Level = level;
Population = new Population();
StorageLevel = 20;
}
示例11: display
public static void display(Population p, int gen)
{
Tour best = p.findBest();
System.Console.WriteLine("Generation {0}\n" +
"Best fitness: {1}\n" +
"Best distance: {2}\n", gen, best.fitness, best.distance);
}
示例12: AdvanceGeneration
static Population AdvanceGeneration(Population population, ISelection selection, ICrossover crossover, IMutation mutation)
{
var chromosomes = new List<Chromosome>();
population = new Population(population.Take((int)(truncationRate * population.Count()))); // TRUNCATION
chromosomes.AddRange(population.Take((int)(elitismRate * chromosomeCount))); //ELITE (assuming that the chromosomes in the population are sorted by fitness (the fitter are at the top of the list)
do
{
Chromosome chosen1 = selection.Select(population),
chosen2 = selection.Select(population);
if (random.NextDouble() < crossoverRate)
{
var children = crossover.Crossover(chosen1, chosen2); // CROSSOVER
chosen1 = children.Item1;
chosen2 = children.Item2;
}
if (random.NextDouble() < mutationRate)
{
chosen1 = mutation.Mutate(chosen1); // MUTATION
}
if (random.NextDouble() < mutationRate)
{
chosen2 = mutation.Mutate(chosen2); // MUTATION
}
chromosomes.Add(chosen1);
chromosomes.Add(chosen2);
} while (chromosomes.Count < chromosomeCount);
return new Population(chromosomes);
}
示例13: InitializePanelWithTrainerData
public void InitializePanelWithTrainerData() {
Player currentPlayer = trainerModuleScript.gameController.masterTrainer.PlayerList[trainerModuleScript.gameController.masterTrainer.CurPlayer-1];
populationRef = currentPlayer.masterPopulation;
DebugBot.DebugFunctionCall("LoadPopulationUI; InitializePanelWithTrainerData(); ", debugFunctionCalls);
UpdateUIWithCurrentData();
}
示例14: Create
// string name,
// float fullFoodAmt,
// float feedIntSec,
// float hungryWindow,
// float energyProduceVal
public override Organism Create(Population population)
{
return new Organism(population,
"bacteria",
1f,
20f,
20f,
1f);
}
示例15: Scale
private void Scale(Population population)
{
foreach (var chromosome in population.Chromosomes)
{
double value = chromosome.Value + (population.AvgFitness - c * _sigma);
if (value < 0) value = 0;
chromosome.Value = value;
}
}