public int euclid_2d(Allel gen1, Allel gen2) { int difx; int dify; difx = gen1.x_nav - gen2.x_nav; dify = gen1.y_nav - gen2.y_nav; return(Convert.ToInt32(Math.Abs(Math.Sqrt(difx * difx + dify * dify)))); }
public void createNewLeaves() { ownAllel = possibleCitys[0]; possibleCitys.RemoveAt(0); if (possibleCitys.Count > 1) { children.Add(new AllelComposite(possibleCitys)); } else { children.Add(new AllelLeave(possibleCitys[0])); } }
public int euclid_2d(Allel gen1, Allel gen2) { int difx; int dify; difx = gen1.x_nav - gen2.x_nav; dify = gen1.y_nav - gen2.y_nav; var xPower = difx * difx; var yPower = dify * dify; var root = Math.Sqrt(xPower + yPower); var conv = Convert.ToInt32(root); return(Convert.ToInt32(Math.Abs(Math.Sqrt(difx * difx + dify * dify)))); }
private void Crossover(Individuum mother, Individuum father) { Random rnd = new Random(); Individuum child1 = new Individuum(); Individuum child2 = new Individuum(); List <Allel> genNewPart = new List <Allel>(); List <KeyValuePair <Allel, int> > newPositions = new List <KeyValuePair <Allel, int> >(); int crossoverPoint = rnd.Next(0, parents.population[0].gen.Count); for (int i = crossoverPoint; i < mother.gen.Count; i++) { Allel all = mother.gen[i]; int position = father.gen.FindIndex(ax => ax.id == all.id); newPositions.Add(new KeyValuePair <Allel, int>(all, position)); } newPositions.Sort((ind1, ind2) => ind1.Value.CompareTo(ind2.Value)); foreach (KeyValuePair <Allel, int> kvp in newPositions) { genNewPart.Add(kvp.Key); } child1.gen.AddRange(mother.gen.GetRange(0, crossoverPoint)); child1.gen.AddRange(genNewPart); newPositions = new List <KeyValuePair <Allel, int> >(); genNewPart = new List <Allel>(); for (int i = crossoverPoint; i < father.gen.Count; i++) { Allel all = father.gen[i]; int position = mother.gen.FindIndex(ax => ax.id == all.id); newPositions.Add(new KeyValuePair <Allel, int>(all, position)); } newPositions.Sort((ind1, ind2) => ind1.Value.CompareTo(ind2.Value)); foreach (KeyValuePair <Allel, int> kvp in newPositions) { genNewPart.Add(kvp.Key); } child2.gen.AddRange(father.gen.GetRange(0, crossoverPoint)); child2.gen.AddRange(genNewPart); children.addIndividuum(child1); children.addIndividuum(child2); }
public AllelLeave(Allel allel) { singleAllel = allel; }