Ejemplo n.º 1
0
        protected override void NextStep(IMOOptProblem Problem)
        {
            int[] fronts = null;

            if (_isUseChachedFronts)
            {
                fronts = _currentFronts;
            }
            else
            {
                fronts = _nds.NonDominSort(_chargePoints.Select(item => item.Objs));
                _isUseChachedFronts = true;
            }

            var countFronts = fronts.GroupBy(frontIndex => frontIndex).ToDictionary(item => item.Key, item => item.Count());

            int maxFront = countFronts.Keys.Max() + 1;

            FindAmountDebris(fronts, countFronts, maxFront);

            GenerateDebris(Problem.LowerBounds, Problem.UpperBounds, fronts, countFronts, maxFront);

            EvalFunctionForDebris(Problem.TargetFunction);

            var allAgents = _chargePoints.Concat(_debris.SelectMany(coll => coll.Select(agent => agent)));

            int[] allFronts = _nds.NonDominSort(allAgents.Select(agent => agent.Objs));

            GenerateNextAgents(allAgents, allFronts);

            EvalFunctionForCharges(Problem.TargetFunction);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            int[][] seq1 = new int[10][];

            Random rand = new Random(6);

            var nds = new Ndsort <int>(CmpInt);

            // A first way.
            for (int i = 0; i < seq1.Length; i++)
            {
                seq1[i] = new int[4];

                for (int j = 0; j < seq1[i].Length; j++)
                {
                    seq1[i][j] = rand.Next(-10, 11);
                }
            }

            int[] fronts1 = nds.NonDominSort(seq1);

            // A second way.
            var seq2 = from item in seq1
                       select new { fitness = item };

            int[] fronts2 = nds.NonDominSort(seq2, item => item.fitness);

            Console.WriteLine($"Are the fronts equal? {fronts1.SequenceEqual(fronts2)}.");

            var groupedFronts = fronts1.Zip(seq1, (front, seq) => new ValueTuple <int, int[]>(front, seq)).GroupBy(tuple => tuple.Item1, tuple => tuple.Item2);

            foreach (var front in groupedFronts)
            {
                Console.WriteLine($"The front index is {front.Key}.");

                foreach (var seq in front)
                {
                    Console.WriteLine($"\t({seq.Select(num => num.ToString()).Aggregate((num1, num2) => $"{num1, 4}, {num2, 4}")})");
                }
            }

            Console.ReadKey();
        }