Esempio n. 1
0
        public static Result GenerateGreedySolution()
        {
            IList <int> sequence = new List <int>();
            IList <int> notUsed  = Enumerable.Range(0, Global.Nucleotids.Count).ToList();

            int starting = StaticRandom.Rand(Global.Nucleotids.Count - 1);

            sequence.Add(starting);
            notUsed.Remove(starting);

            while (sequence.Count != Global.Nucleotids.Count)
            {
                var current = sequence.Last();
                var best    = notUsed.Select(i => new Tuple <int, int>(i, EvaluationLogic.GetSinglePartialSum(Global.Nucleotids[current], Global.Nucleotids[i]))).OrderBy(i => i.Item2).First().Item1;
                sequence.Add(best);
                notUsed.Remove(best);
            }

            return(new Result()
            {
                SequenceIndexes = sequence.Select(i => i + 1).ToArray()
            });
        }
Esempio n. 2
0
        public static void Execute(ref Result[] input, int tournamentSize, int singleTournamentSize = 4)
        {
            var slicedInput = input.Take(tournamentSize).ToArray();

            Result[] randomOrder = slicedInput.OrderBy(s => StaticRandom.Rand()).ToArray();
            Result[] results     = new Result[slicedInput.Length / singleTournamentSize];
            for (int i = 0; i < slicedInput.Length - 1; i += singleTournamentSize)
            {
                var bestResult = randomOrder[i];
                for (int j = 1; j < singleTournamentSize; j++)
                {
                    if (randomOrder[i + j].EvaluationPoints > bestResult.EvaluationPoints || (randomOrder[i + j].EvaluationPoints == bestResult.EvaluationPoints && randomOrder[i + j].TotalLength < bestResult.TotalLength) || (randomOrder[i + j].EvaluationPoints == bestResult.EvaluationPoints && EvaluationLogic.GetWeakConnectedNucleotidIndexes(bestResult).Count > EvaluationLogic.GetWeakConnectedNucleotidIndexes(randomOrder[i + j]).Count))
                    {
                        bestResult = randomOrder[i + j];
                    }
                }
                results[i / singleTournamentSize] = bestResult;
            }

            for (int i = 0; i < slicedInput.Length / singleTournamentSize; i++)
            {
                input[i] = results[i];
            }
        }