本文整理汇总了C#中Chromosome类的典型用法代码示例。如果您正苦于以下问题:C# Chromosome类的具体用法?C# Chromosome怎么用?C# Chromosome使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chromosome类属于命名空间,在下文中一共展示了Chromosome类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Population_GetBestChromosome
public void Population_GetBestChromosome()
{
List<City> cities = new List<City>();
cities.Add(new City(1, 1, "A"));
cities.Add(new City(2, 2, "B"));
cities.Add(new City(3, 3, "C"));
cities.Add(new City(4, 4, "D"));
cities.Add(new City(5, 5, "E"));
List<City> cities2 = new List<City>();
cities2.Add(new City(1, 1, "A"));
cities2.Add(new City(5, 5, "B"));
cities2.Add(new City(3, 3, "C"));
cities2.Add(new City(4, 4, "D"));
cities2.Add(new City(2, 2, "E"));
Population p = new Population();
Chromosome c = new Chromosome(cities);
Chromosome c2 = new Chromosome(cities2);
p.Add(c);
p.Add(c2);
Chromosome best = p.GetBestChromosome();
Assert.AreEqual(c, best);
}
开发者ID:,项目名称:,代码行数:27,代码来源:
示例2: Test_CompareTo
public void Test_CompareTo()
{
Chromosome c1 = new Chromosome("Hello, world!");
Assert.AreEqual(0, c1.GetFitness());
Chromosome c2 = new Chromosome("H5p&J;!l<X\\7l");
Assert.AreEqual(399, c2.GetFitness());
Chromosome c3 = new Chromosome("Vc;fx#QRP8V\\$");
Assert.AreEqual(297, c3.GetFitness());
Chromosome c4 = new Chromosome("t\\O`E_Jx$n=NF");
Assert.AreEqual(415, c4.GetFitness());
Assert.AreEqual(0, c1.CompareTo(c1));
Assert.IsTrue(c1.CompareTo(c2) < 0);
Assert.IsTrue(c1.CompareTo(c3) < 0);
Assert.IsTrue(c1.CompareTo(c4) < 0);
Assert.AreEqual(0, c2.CompareTo(c2));
Assert.IsTrue(c2.CompareTo(c1) > 0);
Assert.IsTrue(c2.CompareTo(c3) > 0);
Assert.IsTrue(c2.CompareTo(c4) < 0);
Assert.AreEqual(0, c3.CompareTo(c3));
Assert.IsTrue(c3.CompareTo(c1) > 0);
Assert.IsTrue(c3.CompareTo(c2) < 0);
Assert.IsTrue(c3.CompareTo(c4) < 0);
Assert.AreEqual(0, c4.CompareTo(c4));
Assert.IsTrue(c4.CompareTo(c1) > 0);
Assert.IsTrue(c4.CompareTo(c2) > 0);
Assert.IsTrue(c4.CompareTo(c3) > 0);
}
开发者ID:markashleybell,项目名称:geneticalgorithm-csharp,代码行数:34,代码来源:ChromosomeTest.cs
示例3: SpawnNeutralCell
void SpawnNeutralCell()
{
Chromosome outputChromosome = new Chromosome(NeutralType);
Vector2 RandomPosition = Random.insideUnitCircle * SpawnDistanceScale;
Vector3 spawnLocation = new Vector3(transform.position.x + RandomPosition.x, 0, transform.position.z + RandomPosition.y);
manager.SpawnNeutral(spawnLocation, outputChromosome);
}
开发者ID:Andrewnopoulos,项目名称:StrainAlpha,代码行数:7,代码来源:CampScript.cs
示例4: EqualsObj_xEqualsy_and_yEqualsx_returns_xEqualsz
public void EqualsObj_xEqualsy_and_yEqualsx_returns_xEqualsz()
{
var x = new Chromosome();
var y = new Chromosome();
var z = new Chromosome();
Assert.IsTrue(!(x.Equals((object)y) && y.Equals((object)z)) || x.Equals((object)z));
}
开发者ID:EddPorter,项目名称:GeneCodeCS,代码行数:7,代码来源:ChromosomeTests.cs
示例5: ChromosomePair_CreateCrossoverChild
public void ChromosomePair_CreateCrossoverChild()
{
List<City> cities = new List<City>();
cities.Add(new City(1, 1, "A"));
cities.Add(new City(2, 2, "B"));
cities.Add(new City(3, 3, "C"));
cities.Add(new City(4, 4, "D"));
cities.Add(new City(5, 5, "E"));
List<City> cities2 = new List<City>();
cities2.Add(new City(1, 1, "A"));
cities2.Add(new City(5, 5, "B"));
cities2.Add(new City(3, 3, "C"));
cities2.Add(new City(4, 4, "D"));
cities2.Add(new City(2, 2, "E"));
Chromosome c = new Chromosome(cities);
Chromosome c2 = new Chromosome(cities2);
ChromosomePair pair = new ChromosomePair(c, c2);
Chromosome child = pair.CreateCrossoverChild();
Assert.AreNotEqual(c, child);
}
开发者ID:,项目名称:,代码行数:25,代码来源:
示例6: Reorder
//int maxLength; // maximum length of string to invert.
/// <summary>
/// Reorders the genes in the chromosome.
/// </summary>
/// <param name="c">The chromosome to be reordered.</param>
public static void Reorder(Chromosome c)
{
// This is like two-point crossover, in that we pick two
// random points on the chromosome. We then reverse the order
// of the genes contained between those two points.
int NumberOfGenes;
NumberOfGenes = c.Genes.Length;
int CrossoverPoint1 = Utils.Rand.Next( NumberOfGenes );
int CrossoverPoint2 = Utils.Rand.Next( NumberOfGenes );
if ( CrossoverPoint1 > CrossoverPoint2 )
{
int tmp = CrossoverPoint1;
CrossoverPoint1 = CrossoverPoint2;
CrossoverPoint2 = tmp;
}
for (
int i=CrossoverPoint1, j=CrossoverPoint2;
(i - CrossoverPoint1) < (CrossoverPoint2-CrossoverPoint1)/2;
i++,j--
)
{
Gene g = c.Genes[i];
c.Genes[i] = c.Genes[j];
c.Genes[j] = g;
}
}
开发者ID:mykwillis,项目名称:genX,代码行数:34,代码来源:Reordering.cs
示例7: Crossover
public Tuple<Chromosome, Chromosome> Crossover(Chromosome c1, Chromosome c2)
{
var locus = random.Next(0, c1.Value.Length + 1); // Locus: http://en.wikipedia.org/wiki/Locus_(genetics)
string ch1 = c1.Value.Substring(0, locus) + c2.Value.Substring(locus),
ch2 = c2.Value.Substring(0, locus) + c1.Value.Substring(locus);
return new Tuple<Chromosome, Chromosome>(new Chromosome(ch1, fitnessCalculator), new Chromosome(ch2, fitnessCalculator));
}
开发者ID:TotallyBullshit,项目名称:StringEvolver,代码行数:8,代码来源:OnePointCrossover.cs
示例8: TestFitnessNoMatch
public void TestFitnessNoMatch()
{
Chromosome.SetTargetGene("ABCF");
Chromosome first = new Chromosome("ABCE");
System.Diagnostics.Debug.Assert(first.Fitness == 1);
}
开发者ID:rbo7nik,项目名称:GAHelloWorld,代码行数:8,代码来源:ChromosomeTest.cs
示例9: Population
public Population(float target, IEnumerable<Chromosome> chromos, Random random, Chromosome solution, int generation)
{
this.target = target;
this.chromos = chromos.ToList();
this.solution = solution;
this.generation = generation;
this.random = random;
}
开发者ID:jfloodnet,项目名称:GeneticAlgorithms,代码行数:8,代码来源:Population.cs
示例10: Mutate
public Chromosome Mutate(Chromosome ch)
{
var sb = new StringBuilder(ch.Value);
var randomPositon = random.Next(0, ch.Value.Length);
sb[randomPositon] = generator.GenerateCharacter();
return new Chromosome(sb.ToString(), fitnessCalculator);
}
开发者ID:dreasgrech,项目名称:StringEvolver,代码行数:8,代码来源:SinglePointMutation.cs
示例11: CalculateFitness
public override double CalculateFitness(Chromosome ch)
{
var score = game.Start(ch.Replay);
//var filledSpaces = game.FilledSpaces();
// TODO: find a way to calculate a fitness based on the score and filledSpaces
return score;// (score + 1) * filledSpaces;
}
开发者ID:dreasgrech,项目名称:HATETRIS-GA,代码行数:8,代码来源:HighestScoreFitnessCalculator.cs
示例12: chromosomeToString
// Converts a chromosome to its respective sequence of cities' indexes.
public static string chromosomeToString(Chromosome chromosome)
{
string str = "";
foreach (var gene in chromosome.Genes)
{
str += ((int)gene.RealValue).ToString() + " ";
}
return str;
}
开发者ID:Cowalters,项目名称:mTSP_GA,代码行数:10,代码来源:Utils.cs
示例13: Mutate
public Chromosome Mutate(Chromosome ch)
{
var replay = ch.Replay.ToString();
var sb = new StringBuilder(replay);
var randomPositon = random.Next(0, replay.Length);
sb[randomPositon] = characterSet.GetRandomCharacter();
return new Chromosome(new Replay(sb.ToString()), fitnessCalculator);
}
开发者ID:dreasgrech,项目名称:HATETRIS-GA,代码行数:9,代码来源:SinglePointMutation.cs
示例14: RandomPopulation
public Population RandomPopulation()
{
var chromosomes = new Chromosome[ChromosomeCount];
for (int i = 0; i < ChromosomeCount; i++)
{
chromosomes[i] = RandomChromosome();
}
return new Population(chromosomes);
}
开发者ID:TotallyBullshit,项目名称:StringEvolver,代码行数:9,代码来源:RandomElementFactory.cs
示例15: CreateInfectedCell
public void CreateInfectedCell(Chromosome _inputChromosome, Vector3 _location)
{
GameObject newCell = (GameObject)Instantiate(cell, _location, transform.rotation);
CellScript script = newCell.GetComponent<CellScript>();
script.manager = this;
script.CreateInfected(_inputChromosome);
infectedList.Add(script);
}
开发者ID:Andrewnopoulos,项目名称:StrainAlpha,代码行数:9,代码来源:NPCManager.cs
示例16: Chromosome_Calculate_Fitness
public void Chromosome_Calculate_Fitness()
{
List<City> cities = new List<City>();
cities.Add(new City(1, 2, "A"));
cities.Add(new City(5, 5, "B"));
Chromosome c = new Chromosome(cities);
Assert.AreEqual<double>(5, c.Fitness());
}
开发者ID:,项目名称:,代码行数:9,代码来源:
示例17: Start
// Use this for initialization
void Start()
{
infected = false;
myRenderer = GetComponent<Renderer>();
colourBlend = 0.0f;
parentScript = GetComponentInParent<CellScript>();
type = parentScript.infectedType;
cellGenes = parentScript.GetChromosome();
}
开发者ID:Andrewnopoulos,项目名称:StrainAlpha,代码行数:10,代码来源:BlendColourScript.cs
示例18: CalculateFitness
protected double CalculateFitness(Chromosome solution)
{
int totWaste = 0, totStock = 0;
foreach (var gene in solution.Genes)
{
totWaste += (gene.ObjectValue as CutPlan).Waste;
totStock += (gene.ObjectValue as CutPlan).StockLength;
}
return (totWaste / totStock)*100+1/totWaste;
}
开发者ID:jcambert,项目名称:Webcorp.Erp,代码行数:10,代码来源:Solver.cs
示例19: IsSuccess
private static bool IsSuccess(BulldozerAlgorithm<double> algorithm, double threshold, out Chromosome chromosome)
{
var chromosomes = algorithm.ChromosomePool
.Union(algorithm.ChromosomeBank)
.OfType<TreeChromosome>()
.ToList();
var maxValue = chromosomes.Max(c => c.Metrics[2]);
chromosome = chromosomes.FirstOrDefault(c => c.Metrics[2] == maxValue);
return maxValue >= threshold;
}
开发者ID:vadimostanin,项目名称:GA,代码行数:10,代码来源:DoubleBulldozerBalancer.cs
示例20: Crossover
public Tuple<Chromosome, Chromosome> Crossover(Chromosome c1, Chromosome c2)
{
string replay1 = c1.Replay.ToString(), replay2 = c2.Replay.ToString();
var locus = random.Next(0, replay1.Length + 1); // Locus: http://en.wikipedia.org/wiki/Locus_(genetics)
string ch1 = replay1.Substring(0, locus) + replay2.Substring(locus),
ch2 = replay2.Substring(0, locus) + replay1.Substring(locus);
return new Tuple<Chromosome, Chromosome>(new Chromosome(new Replay(ch1), fitnessCalculator), new Chromosome(new Replay(ch2),fitnessCalculator));
}
开发者ID:dreasgrech,项目名称:HATETRIS-GA,代码行数:10,代码来源:OnePointCrossover.cs
注:本文中的Chromosome类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论