private void BranchesOperation(List <AntBranch> antBranches, List <Ant> ants) { int i = 0; while (!CheckWeatherAllAntsHaveParents(ants, antBranches.Count())) { foreach (AntBranch branch in antBranches) { foreach (Ant ant in branch.Ants) { if (i != 0 && ant.ParentIndex == 0 && ant.ParenTemp != 0) { Ant apos = branch.Ants.Where(a => a.Number == ant.ParenTemp).FirstOrDefault(); if (CountSim(ant, apos) >= ant.TSim) { Ant aplus = FindTheMostSimilarAnt(ant, branch.Ants.Where(a => a.ParentIndex == apos.Number).ToList()) ?? apos; if (CountSim(ant, aplus) < ant.TDissim) { ant.ParentIndex = apos.Number; ant.ParenTemp = 0; } else { ChangeSim(ant); ant.ParenTemp = PickRandomAnt(branch.Ants.Where(a => a.ParentIndex == apos.Number).ToList(), apos.Number); } } else { ant.ParenTemp = PickRandomAnt(branch.Ants.Where(a => a.ParentIndex == apos.Number).ToList(), apos.Number); } } i++; } } } }
void Support(Ant ant, List <AntBranch> antBranches) { List <Ant> antFromSupport = (from rekord in antBranches select rekord.Ants[0]).ToList(); Ant theMostSimilar = FindTheMostSimilarAnt(ant, antFromSupport); double tempSim = CountSim(ant, theMostSimilar); if (tempSim >= ant.TSim) { ant.Index = theMostSimilar.Index; ant.ParenTemp = theMostSimilar.Number; antBranches.FirstOrDefault(a => a.Index == theMostSimilar.Index).Ants.Add(ant); } else { if (tempSim <= ant.TDissim) { antBranches.Add(CreateNewBranch(ant, antBranches.Count())); } else { ChangeSim(ant); } } }
public List <Ant> RandomAnts(int lenght, double TSim, double TDissim) { Random random = new Random(); List <Ant> antsList = new List <Ant>(); while (lenght > 0) { Ant newAnt = new Ant(TSim, TDissim); // newAnt.Points = new Points() { X = random.NextDouble(), Y = random.NextDouble() }; //if(lenght==8) newAnt.Points = new Points() { X = 0, Y = 0 }; //if (lenght == 7) newAnt.Points = new Points() { X = 0.15, Y = 0.15 }; //if (lenght == 6) newAnt.Points = new Points() { X = 0, Y = 1 }; //if (lenght == 5) newAnt.Points = new Points() { X = 0.15, Y = 1}; //if (lenght == 4) newAnt.Points = new Points() { X = 1, Y = 0 }; //if (lenght == 3) newAnt.Points = new Points() { X = 0.9, Y = 0 }; //if (lenght == 2) newAnt.Points = new Points() { X = 1, Y = 1 }; //if (lenght == 1) newAnt.Points = new Points() { X = 0.9, Y =0.9 }; newAnt.Number = lenght; antsList.Add(newAnt); lenght--; } return(antsList); }
public void AddDataToChart(Ant ant, Color color) { int index = Chart.Series[0].Points.AddXY(ant.Points.X, ant.Points.Y); Chart.Series[0].Points[index].Color = color; }
void ChangeSim(Ant ant) { ant.TSim = ant.TSim * 0.9; ant.TDissim = ant.TDissim + 0.01; }