예제 #1
0
        private void SelectParents(IReadOnlyList <Individual> parents, int length)
        {
            //perform a nondominated sort to assign the rank to every element
            int[] ranks;
            var   fronts = DominationCalculator <Individual> .CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization, out ranks);

            //deselect the highest rank fronts until we would end up with less or equal mu elements
            var rank    = fronts.Count - 1;
            var popSize = parents.Count;

            while (popSize - fronts[rank].Count >= length)
            {
                var front = fronts[rank];
                foreach (var i in front)
                {
                    i.Item1.Selected = false;
                }
                popSize -= front.Count;
                rank--;
            }

            //now use the indicator to deselect the approximatingly worst elements of the last selected front
            var front1 = fronts[rank].OrderBy(x => x.Item1.PenalizedFitness[0]).ToList();

            for (; popSize > length; popSize--)
            {
                var lc = Indicator.LeastContributer(front1.Select(i => i.Item1).ToArray(), Problem);
                front1[lc].Item1.Selected = false;
                front1.Swap(lc, front1.Count - 1);
                front1.RemoveAt(front1.Count - 1);
            }
        }
예제 #2
0
        public override IOperation Apply()
        {
            bool dominateOnEqualQualities = DominateOnEqualQualitiesParameter.ActualValue.Value;

            bool[]     maximization = MaximizationParameter.ActualValue.ToArray();
            double[][] qualities    = QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray();
            if (qualities == null)
            {
                throw new InvalidOperationException(Name + ": No qualities found.");
            }

            IScope scope          = ExecutionContext.Scope;
            int    populationSize = scope.SubScopes.Count;

            int[] rank;
            var   fronts = DominationCalculator <IScope> .CalculateAllParetoFronts(scope.SubScopes.ToArray(), qualities, maximization, out rank, dominateOnEqualQualities);

            RankParameter.ActualValue = new ItemArray <IntValue>(rank.Select(x => new IntValue(x)));

            scope.SubScopes.Clear();

            for (var i = 0; i < fronts.Count; i++)
            {
                Scope frontScope = new Scope("Front " + i);
                foreach (var p in fronts[i])
                {
                    frontScope.SubScopes.Add(p.Item1);
                }
                if (frontScope.SubScopes.Count > 0)
                {
                    scope.SubScopes.Add(frontScope);
                }
            }
            return(base.Apply());
        }
예제 #3
0
        private const int dimensionCount = 10; // todo: use parameters

        /// <summary>
        /// returns population of next generation after applying necessary operations
        /// </summary>
        /// <param name="pt">parent population</param>
        /// <param name="referencePoints">structured reference points or supplied aspiration points</param>
        /// <returns></returns>
        private List <Solution> GetNextGeneration(List <Solution> pt, List <ReferencePoint> referencePoints)
        {
            bool aspirationPointsWereSupplied = false; // todo: use parameters

            List <Solution> st = new List <Solution>();
            int             i  = 1;

            Recombine(pt);
            Mutate(pt);
            double[][] qualities    = Evaluate(pt);
            bool[]     maximization = new bool[dimensionCount];
            int[]      rank;

            List <List <Tuple <Solution, double[]> > > allParetoFronts = DominationCalculator <Solution> .CalculateAllParetoFronts(pt.ToArray(), qualities, maximization, out rank, true);

            return(null);
        }