private void TournamentSelection(ref List <Individual> afterSelection, int outSize) { CollectionActions.Shuffle(populationOfSolutions); //zmniejszamy ryzyko wylosowania dwa razy tych samych for (int i = 0; i < populationOfSolutions.Count - 2 && afterSelection.Count < outSize; i += 2) //porównujemy pary { afterSelection.Add(GetSelectedIndividual(i, i + 1)); } }
private void PrepareBasicPopulation() { for (int i = 0; i < populationSize; i++) { List <int> clonedIndexes = CloneIndexesList(columnsIndexes); CollectionActions.Shuffle(clonedIndexes); populationOfSolutions.Add(new Individual(clonedIndexes, this)); } }
internal void Mutate(float mutationPower) { Random rand = new Random(); int numberOfMutations = Convert.ToInt32(columnsPermutation.Count * mutationPower); for (int i = 0; i < numberOfMutations; i++) { int index1 = 0; int index2 = 0; while (index1 == index2) { index1 = rand.Next(columnsPermutation.Count); index2 = rand.Next(columnsPermutation.Count); } CollectionActions.Swap(columnsPermutation, index1, index2); } }
private string GetTransponedMatrix() { List <string> columns = new List <string>(); string outLine = ""; for (int column = 0; column < dataGridView1.Columns.Count; column++) { string outColumn = ""; for (int row = 0; row < dataGridView1.Rows.Count; row++) { outColumn += ValueInCell(column, row) + " "; } columns.Add(outColumn); } CollectionActions.Shuffle(columns); //Losowe mieszanie kolumn foreach (string col in columns) { outLine += col + Environment.NewLine; } return(outLine); }