Beispiel #1
0
        public string RecreateDna()
        {
            //variables changing algorithm behaviour
            var maxRounds = 550;
            var nodeCountMaxDifferenceThreshold = 6;
            var shouldIncreaseProbabilityMatrix = 0;
            //--

            var round = 0;
            var probabilityMultipliers = UtilHelper.CreateProbabilityArray(new double[LengthK - 1]);

            var currentDna        = FindRandomDnaSequence();
            var currentSimilarity = UtilHelper.GetSimilarityOf(OriginalDna, currentDna);

            Console.WriteLine($"Ideal node count: {IdealNodeCount}");
            Console.WriteLine($"Similarity after random algorithm: {currentSimilarity}");

            while (round < maxRounds)
            {
                TweakProbabilityArray(probabilityMultipliers, shouldIncreaseProbabilityMatrix);

                currentDna        = FindDnaSequence(probabilityMultipliers, nodeCountMaxDifferenceThreshold, out var visitedNodesCount);
                currentSimilarity = UtilHelper.GetSimilarityOf(OriginalDna, currentDna);

                if (round % 10 == 0)
                {
                    Console.WriteLine($"Similarity after {round} rounds: {currentSimilarity} with node usage {visitedNodesCount}");
                }

                if (visitedNodesCount == IdealNodeCount && currentDna.Length == DnaLength)
                {
                    Console.WriteLine($"This DNA Sequence has ideal node count & ideal dna length");
                    return(currentDna);
                }

                if (visitedNodesCount + 10 < IdealNodeCount)
                {
                    shouldIncreaseProbabilityMatrix = 1;
                }
                else if (visitedNodesCount - 10 < IdealNodeCount)
                {
                    shouldIncreaseProbabilityMatrix = 0;
                }
                else
                {
                    shouldIncreaseProbabilityMatrix = -1;
                }

                round++;
            }
            return(currentDna);
        }