private void CreateNewRandomPopulation()
        {
            #region Create new defualt array {0,1,2,3,4,5, ... , dimension-1}
            int[] defaultArray = new int[Dimension];
            for (int i = 0; i < Dimension; i++)
            {
                defaultArray[i] = i;
            }
            #endregion

            for (int i = 0; i < POPULATION_SIZE; i++)
            {
                individuals.ElementAt(i).Permutation = Permutator.GetRandomPermutation(defaultArray);
            }
        }
Ejemplo n.º 2
0
        public void RandomPermutationAlgorythm()
        {
            int arraySize = dataFileReader.myObject.Dimension;

            int[] bestIndexesArray = new int[arraySize];
            for (int i = 0; i < arraySize; i++)
            {
                bestIndexesArray[i] = i;
            }

            ExcelWorker excel = new ExcelWorker("Random alg");

            int generationCounter = 1;

            while (generationCounter < MAX_COUNTER_VALUE)
            {
                int[] tmp      = Permutator.GetRandomPermutation(bestIndexesArray);
                int   tmpCost  = CountCost(tmp);
                int   mainCost = CountCost(bestIndexesArray);
                if (tmpCost < mainCost)
                {
                    Array.Copy(tmp, bestIndexesArray, arraySize);
                }

                excel.AddCellToWorksheetIntoColumnsAB(generationCounter++, CountCost(bestIndexesArray));
            }

            #region Show result
            string bestResult = "";

            foreach (var item in bestIndexesArray)
            {
                bestResult += item.ToString() + "; ";
            }

            textBoxTotalCost.Text = bestResult;
            #endregion
        }