public BinaryGreedyRSOptimizer(IEvaluation <bool> evaluation, AStopCondition stopCondition,
                                AStopCondition greedyStopCondition, int?seed = null)
     : base(evaluation, stopCondition)
 {
     generator       = new BinaryRandomGenerator(evaluation.pcConstraint, seed);
     greedyOptimizer = new BinaryGreedyOptimizer(evaluation, null, greedyStopCondition, seed);
 }
        protected String FormatProblemParameters(IEvaluation <E> problem)
        {
            String parametry = "";

            parametry += problem.GetType().Name + ", " + problem.iSize.ToString();
            return(parametry);
        }
 public GAStallDetection(IEvaluation<Element> evaluation, AStopCondition stopCondition, AGenerator<Element> generator,
                         ASelection selection, ACrossover crossover, IMutation<Element> mutation, int populationSize, 
                         int maxNoChangeDetections)
     : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize)
 {
     MaxNCD = maxNoChangeDetections;
 }
Esempio n. 4
0
 public ResettingGA(IEvaluation <Element> evaluation, AStopCondition stopCondition, AGenerator <Element> generator,
                    ASelection selection, ACrossover crossover, IMutation <Element> mutation, int populationSize, int patience, int?seed = null)
     : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize)
 {
     this.patience = patience;
     rng           = seed.HasValue ? new Random(seed.Value) : new Random();
 }
Esempio n. 5
0
 public RealEvolutionStrategy11(IEvaluation <double, double> evaluation, IStopCondition stopCondition,
                                ARealMutationES11Adaptation mutationAdaptation, int?seed = null)
     : base(evaluation, stopCondition, new OptimizationState <double>(evaluation.tMaxValue))
 {
     this.mutationAdaptation = mutationAdaptation;
     randomGeneration        = new RealRandomGenerator(evaluation.pcConstraint, seed);
 }
 public ASimpleOptimizer(IEvaluation <Element> evaluation, AStopCondition stopCondition, AGenerator <Element> generator)
 {
     Result             = null;
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     this.generator     = generator;
 }
Esempio n. 7
0
        private ExitCondition ExitCriteriaSatisfied(IEvaluation candidate_point, IEvaluation last_point)
        {
            Vector <double> rel_grad          = new MathNet.Numerics.LinearAlgebra.Double.DenseVector(candidate_point.Point.Count);
            double          relative_gradient = 0.0;
            double          normalizer        = Math.Max(Math.Abs(candidate_point.Value), 1.0);

            for (int ii = 0; ii < rel_grad.Count; ++ii)
            {
                double tmp = candidate_point.Gradient[ii] * Math.Max(Math.Abs(candidate_point.Point[ii]), 1.0) / normalizer;
                relative_gradient = Math.Max(relative_gradient, Math.Abs(tmp));
            }
            if (relative_gradient < this.GradientTolerance)
            {
                return(ExitCondition.RelativeGradient);
            }

            if (last_point != null)
            {
                double most_progress = 0.0;
                for (int ii = 0; ii < candidate_point.Point.Count; ++ii)
                {
                    var tmp = Math.Abs(candidate_point.Point[ii] - last_point.Point[ii]) / Math.Max(Math.Abs(last_point.Point[ii]), 1.0);
                    most_progress = Math.Max(most_progress, tmp);
                }
                if (most_progress < this.ParameterTolerance)
                {
                    return(ExitCondition.LackOfProgress);
                }
            }

            return(ExitCondition.None);
        }
Esempio n. 8
0
 public GeneticAlgorithm(IEvaluation <Element, Tuple <double, double> > evaluation, IStopCondition stopCondition,
                         AGenerator <Element> generator, ASelection <Tuple <double, double> > selection, ACrossover crossover,
                         IMutation <Element> mutation, int populationSize, int?seed = null)
     : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize,
            new OptimizationState <Element>(evaluation.tMaxValue, evaluation.lOptimalParetoFront), seed)
 {
 }
Esempio n. 9
0
 private void ValidateValue(IEvaluation eval)
 {
     if (!this.IsFinite(eval.Value))
     {
         throw new EvaluationException(String.Format("Non-finite value returned by objective function: {0}", eval.Value), eval);
     }
 }
Esempio n. 10
0
        private bool IsCharacteristicConformFor(IEvaluation consequence)
        {
            switch (consequence.Persona.Characteristic)
            {
            case Characteristics.UNKNOWN:
                throw new NotImplementedException();


            case Characteristics.AGE:
                throw new NotImplementedException();

            case Characteristics.GENDER:
                throw new NotImplementedException();

            case Characteristics.HEALTH:
                throw new NotImplementedException();

            case Characteristics.GOLD:
                throw new NotImplementedException();

            case Characteristics.RENOWN:
                return(IsRenownConformFor(consequence));

            case null:
                throw new NotImplementedException();

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 11
0
        private bool IsRenownConformFor(IEvaluation consequence)
        {
            switch (consequence.Numbers.Operator)
            {
            case Operator.UNKNOWN:
                break;

            case Operator.GREATERTHAN:
                break;

            case Operator.LOWERTHAN:
                break;

            case Operator.EQUALTO:
            {
                //TODO: must find how to recover renown
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(false);
        }
Esempio n. 12
0
 public NSGA2(IEvaluation <Element, Tuple <double, double> > evaluation, IStopCondition stopCondition, AGenerator <Element> generator,
              IDominationComparer dominationComparer, ACrossover crossover, IMutation <Element> mutation, int populationSize,
              int?seed = null)
     : base(evaluation, stopCondition, generator, new NSGA2Selection(2, evaluation.tMaxValue, dominationComparer, true, seed),
            crossover, mutation, populationSize, seed)
 {
 }
Esempio n. 13
0
 private void ValidateObjective(IEvaluation eval)
 {
     if (Double.IsNaN(eval.Value) || Double.IsInfinity(eval.Value))
     {
         throw new EvaluationException("Non-finite objective function returned.", eval);
     }
 }
Esempio n. 14
0
        private ExitCondition ExitCriteriaSatisfied(IEvaluation candidate_point, IEvaluation last_point, Vector <double> lower_bound, Vector <double> upper_bound, int iterations)
        {
            Vector <double> rel_grad          = new MathNet.Numerics.LinearAlgebra.Double.DenseVector(candidate_point.Point.Count);
            double          relative_gradient = 0.0;
            double          normalizer        = Math.Max(Math.Abs(candidate_point.Value), 1.0);

            for (int ii = 0; ii < rel_grad.Count; ++ii)
            {
                var projected_gradient = 0.0;

                bool at_lower_bound = candidate_point.Point[ii] - lower_bound[ii] < VERY_SMALL;
                bool at_upper_bound = upper_bound[ii] - candidate_point.Point[ii] < VERY_SMALL;

                if (at_lower_bound && at_upper_bound)
                {
                    projected_gradient = 0.0;
                }
                else if (at_lower_bound)
                {
                    projected_gradient = Math.Min(candidate_point.Gradient[ii], 0.0);
                }
                else if (at_upper_bound)
                {
                    projected_gradient = Math.Max(candidate_point.Gradient[ii], 0.0);
                }
                else
                {
                    projected_gradient = candidate_point.Gradient[ii];
                }

                double tmp = projected_gradient * Math.Max(Math.Abs(candidate_point.Point[ii]), 1.0) / normalizer;
                relative_gradient = Math.Max(relative_gradient, Math.Abs(tmp));
            }
            if (relative_gradient < this.GradientTolerance)
            {
                return(ExitCondition.RelativeGradient);
            }

            if (last_point != null)
            {
                double most_progress = 0.0;
                for (int ii = 0; ii < candidate_point.Point.Count; ++ii)
                {
                    var tmp = Math.Abs(candidate_point.Point[ii] - last_point.Point[ii]) / Math.Max(Math.Abs(last_point.Point[ii]), 1.0);
                    most_progress = Math.Max(most_progress, tmp);
                }
                if (most_progress < this.ParameterTolerance)
                {
                    return(ExitCondition.LackOfProgress);
                }

                double function_change = candidate_point.Value - last_point.Value;
                if (iterations > 500 && function_change < 0 && Math.Abs(function_change) < this.FunctionProgressTolerance)
                {
                    return(ExitCondition.LackOfProgress);
                }
            }

            return(ExitCondition.None);
        }
        protected override IEvaluation <bool>[] GenerateProblems()
        {
            int[] concatStandardN = { 3, 5, 10, 20 };
            int[] concatBimodalN  = { 5, 10, 15, 20 };
            int[] standardBlocks  = { 1, 2, 4, 6, 8, 10 };
            int[] bimodalBlocks   = { 1, 2, 3, 4, 5 };
            int   nProblems       = concatStandardN.Length * standardBlocks.Length + //Order-5 deceptive concatenation
                                    concatBimodalN.Length * bimodalBlocks.Length;    //Bimodal-10 deceptive concatenation

            int iterator = 0;

            IEvaluation <bool>[] problems = new IEvaluation <bool> [nProblems];

            //Order-n deceptive concatenation, where n in { 3, 5, 10, 20 }
            foreach (int n in concatStandardN)
            {
                foreach (int block in standardBlocks)
                {
                    problems[iterator] = new CBinaryStandardDeceptiveConcatenationEvaluation(n, block);
                    iterator++;
                }
            }

            //Bimodal-n deceptive concatenation, where n in { 5, 10, 15, 20 }
            foreach (int n in concatBimodalN)
            {
                foreach (int block in bimodalBlocks)
                {
                    problems[iterator] = new CBinaryBimodalDeceptiveConcatenationEvaluation(n, block);
                    iterator++;
                }
            }

            return(problems);
        }
Esempio n. 16
0
        private static OptimizationResult <double> RunExperiment(IEvaluation <double> evaluation, int maxIterations, double sigma, bool adjustSigmas, int adaptation, int?seed = null, int archiveSize = 1, double modifier = 1.0)
        {
            lock (evaluation)
            {
                IterationsStopCondition stopCondition = new IterationsStopCondition(evaluation.dMaxValue, maxIterations);
                List <double>           sigmas;
                if (adjustSigmas)
                {
                    sigmas = AdjustSigmas(evaluation, sigma);
                }
                else
                {
                    sigmas = Enumerable.Repeat(sigma, evaluation.iSize).ToList();
                }
                RealGaussianMutation        mutation = new RealGaussianMutation(sigmas, evaluation, seed);
                ARealMutationES11Adaptation mutationAdaptation;
                switch (adaptation)
                {
                case 0:
                    mutationAdaptation = new RealNullRealMutationES11Adaptation(mutation);
                    break;

                case 1:
                    mutationAdaptation = new RealOneFifthRuleMutationES11Adaptation(archiveSize, modifier, mutation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                RealEvolutionStrategy11 es11 = new RealEvolutionStrategy11(evaluation, stopCondition, mutationAdaptation, seed);
                es11.Run();
                return(es11.Result);
            }
        }
Esempio n. 17
0
        public IEnumerable <MOVE> Solve(NPuzzle Puzzle, IEvaluation Eval)
        {
            List <NPuzzleNode> Open   = new List <NPuzzleNode>();
            List <NPuzzleNode> Closed = new List <NPuzzleNode>();

            NPuzzleNode Goal = null;

            Open.Add(new NPuzzleNode(null, Puzzle, Eval));

            while (Open.Count > 0)
            {
                NPuzzleNode U = Open[0];
                Open.RemoveAt(0);

                Closed.Add(U);

                if (U.H == 0.0f)
                {
                    Goal = U;
                    break;
                }

                foreach (NPuzzleNode S in U.Successors())
                {
                    if (!Open.Contains(S) && !Closed.Contains(S))
                    {
                        Open.Add(S);
                    }
                }
            }

            return(Goal.State.PreviousMoves);
        }
        public OneMinus(IEvaluation other)
        {
            Value = 1 - other.Value;
#if TRACING
            Explain = $"(1 - {other.Explain})";
#endif
        }
Esempio n. 19
0
 public RealRandomSearch(IEvaluation <double, double> evaluation, IStopCondition stopCondition, int?seed = null)
 {
     Result             = null;
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     generator          = new RealRandomGenerator(evaluation.pcConstraint, seed);
 }
Esempio n. 20
0
 public BinaryGreedyRandomGeneration(IEvaluation <bool> evaluation, int?greedyIterations = null, int?seed = null)
     : base(evaluation.pcConstraint)
 {
     _greedyIterations = greedyIterations;
     brg = new BinaryRandomGeneration(evaluation.pcConstraint, seed);
     ga  = new GreedyAlgorithm(evaluation, seed);
 }
Esempio n. 21
0
        private bool Conforms(IEvaluation starting_point, Vector <double> search_direction, double step, IEvaluation ending_point)
        {
            bool sufficient_decrease = ending_point.Value <= starting_point.Value + this.C1 * step * (starting_point.Gradient * search_direction);
            bool not_too_steep       = ending_point.Gradient * search_direction >= this.C2 * starting_point.Gradient * search_direction;

            return(step > 0 && sufficient_decrease && not_too_steep);
        }
Esempio n. 22
0
 public AOptimizer(IEvaluation <Element> evaluation, AStopCondition stopCondition)
 {
     Result                   = null;
     this.Evaluation          = evaluation;
     this.StopCondition       = stopCondition;
     this.divergenceException = false;
 }
Esempio n. 23
0
 public AOptimizer(IEvaluation <Element, EvaluationResult> evaluation, IStopCondition stopCondition,
                   AOptimizationState <Element, EvaluationResult, OptimizationResult> state)
 {
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     this.state         = state;
 }
Esempio n. 24
0
 public BinaryRandomSearch(IEvaluation <bool> evaluation, AStopCondition stopCondition, int?seed = null)
 {
     Result             = null;
     this.evaluation    = evaluation;
     this.stopCondition = stopCondition;
     generator          = new BinaryRandomGenerator(evaluation.pcConstraint, seed);
 }
Esempio n. 25
0
        public IActionResult Import([FromForm] FileViewModel model)
        {
            try
            {
                IFormFile file = model.importedFile;
                List <EvaluationExportImportViewModel> importedEvaluations = service.import(file);

                if (!cache.TryGetValue(CacheKeys.EVALUATION, out evaluations))
                {
                    evaluations = new List <IEvaluation>();
                }

                List <IVehicle> vehicles;
                if (!cache.TryGetValue(CacheKeys.VEHICLE, out vehicles))
                {
                    vehicles = new List <IVehicle>();
                }

                foreach (EvaluationExportImportViewModel e in importedEvaluations)
                {
                    IEvaluation eva    = e.generateEvaluation();
                    bool        unique = true;
                    foreach (IEvaluation evaluation in evaluations)
                    {
                        if (eva.scenario.id.Equals(evaluation.scenario.id))
                        {
                            unique = false;
                            break;
                        }
                    }
                    if (unique)
                    {
                        evaluations.Add(eva);
                    }
                    foreach (Vehicle v in eva.scenario.vehicles)
                    {
                        unique = true;
                        foreach (Vehicle vehicle in vehicles)
                        {
                            if (vehicle.id.Equals(v.id))
                            {
                                unique = false;
                                break;
                            }
                        }
                        if (unique)
                        {
                            vehicles.Add(v);
                        }
                    }
                }
                cache.Set(CacheKeys.VEHICLE, vehicles);
                cache.Set(CacheKeys.EVALUATION, evaluations);
                return(View("Index", evaluations));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 26
0
 public RealRestartingEvolutionStrategy11(IEvaluation <double> evaluation, AStopCondition stopCondition, ARealMutationES11Adaptation mutationAdaptation, int patience, int?seed = null)
     : base(evaluation, stopCondition)
 {
     this.mutationAdaptation = mutationAdaptation;
     randomGeneration        = new RealRandomGenerator(evaluation.pcConstraint, seed);
     this.patience           = patience;
 }
Esempio n. 27
0
 public Evaluation(IEvaluation condition)
 {
     Persona    = condition.Persona;
     Numbers    = condition.Numbers;
     Outcome    = condition.Outcome;
     Equipments = condition.Equipments;
     PartyType  = condition.PartyType;
 }
Esempio n. 28
0
 public RealEvolutionStrategy11(IEvaluation <double, double> evaluation, IStopCondition stopCondition, ARealMutationES11Adaptation mutationAdaptation, int?seed = null)
 {
     Result                  = null;
     this.evaluation         = evaluation;
     this.stopCondition      = stopCondition;
     this.mutationAdaptation = mutationAdaptation;
     randomGeneration        = new RealRandomGenerator(evaluation.pcConstraint, seed);
 }
 public ClusteringGeneticAlgorithm(IEvaluation <Element, Tuple <double, double> > evaluation, IStopCondition stopCondition,
                                   AGenerator <Element> generator, ASelection <Tuple <double, double> > selection, ACrossover crossover,
                                   IMutation <Element> mutation, int populationSize, int clusters, int?seed = null)
     : base(evaluation, stopCondition, generator, selection, crossover, mutation, populationSize, seed)
 {
     no_clusters = clusters;
     rng         = seed.HasValue ? new Random(seed.Value) : new Random();
 }
Esempio n. 30
0
 public void Evaluate(IEvaluation <Element, EvaluationResult> evaluation)
 {
     if (!evaluated)
     {
         Fitness   = evaluation.tEvaluate(Genotype);
         evaluated = true;
     }
 }
        /// <summary>
        /// Constructor accepting an expression evaluator object
        /// </summary>
        public ConditionalInclusionsMachine(IEvaluation evaluator)
        {
            this.Evaluator = evaluator;
            this._parserState = new Stack<ParserState>();

            _normalState = new NormalState(this);
            _includingDueToIf = new IncludingDueToIf(this);
            _discardingDueToSuccessfullIf = new DiscardingDueToSuccessfullIf(this);
            _discardingDueToFailedIf = new DiscardingDueToFailedIf(this);
            _discardingDueToMultilineDefine = new DiscardingDueToMultilineDefine(this);
        }
Esempio n. 32
0
        public QueryConstraint(IQuery query, string fieldName, object theObject)
        {
            if (query == null)
                throw new ArgumentNullException("query");

            if (string.IsNullOrEmpty(fieldName))
                throw new ArgumentNullException("fieldName");

            _query = query;
            _attributeName = fieldName;
            _theObject = theObject;

            ((IInternalQuery) _query).Add(this);

            _evaluation = new EqualsEvaluation(_theObject, _attributeName, _query);
        }
Esempio n. 33
0
        public IConstraint Equal()
        {
            if (IsPreEvaluationTheGreater())
            {
                _evaluation = new ComparisonEvaluation(_theObject, _attributeName,
                                                                       ComparisonConstraint.ComparisonTypeGe);
                return this;
            }

            if (IsPreEvaluationTheSmaller())
            {
                _evaluation = new ComparisonEvaluation(_theObject, _attributeName,
                                                                       ComparisonConstraint.ComparisonTypeLe);
                return this;
            }

            _evaluation = new EqualsEvaluation(_theObject, _attributeName, _query);
            return this;
        }
		public void HasSuggestion(IEvaluation rule)
		{
			Assert.That(rule.Suggestion, Is.Not.Null.Or.Empty);
		}
		public void HasTitle(IEvaluation rule)
		{
			Assert.That(rule.Title, Is.Not.Null.Or.Empty);
		}
		public void HasQualityAttribute(IEvaluation rule)
		{
			Assert.That(rule.QualityAttribute.ToString(), Is.Not.Null.Or.Empty);
		}
		public void HasImpactLevel(IEvaluation rule)
		{
			Assert.That(rule.ImpactLevel.ToString(), Is.Not.Null.Or.Empty);
		}
Esempio n. 38
0
 public IConstraint SizeLe()
 {
     _evaluation = new CollectionSizeEvaluation(_theObject, _attributeName, _query, CollectionSizeEvaluation.SizeLe);
     return this;
 }
Esempio n. 39
0
 public IConstraint StartsWith(bool isCaseSensitive)
 {
     _evaluation = new StartsWithEvaluation(_theObject, _attributeName, isCaseSensitive);
     return this;
 }
 /// <summary>
 /// Constructor accepting an expression evaluator
 /// </summary>
 /// <param name="evaluator">expression evaluator</param>
 public ConditionalInclusionsFilter(IEvaluation evaluator)
 {
     _conditionalInclusionsMachine = new ConditionalInclusionsMachine(evaluator);
 }
 public void HasTitle(IEvaluation rule)
 {
     Assert.False(string.IsNullOrEmpty(rule.Title));
 }
Esempio n. 42
0
 public IConstraint Contains()
 {
     _evaluation = new ContainsEvaluation(_theObject, _attributeName, _query);
     return this;
 }
 public void HasSuggestion(IEvaluation rule)
 {
     Assert.False(string.IsNullOrEmpty(rule.Suggestion));
 }
 public void HasImpactLevel(IEvaluation rule)
 {
     Assert.False(string.IsNullOrEmpty(rule.ImpactLevel.ToString()));
 }
Esempio n. 45
0
 public IConstraint Identity()
 {
     _evaluation = new IdentityEvaluation(_theObject, _attributeName, _query);
     return this;
 }
 public void HasQualityAttribute(IEvaluation rule)
 {
     Assert.False(string.IsNullOrEmpty(rule.QualityAttribute.ToString()));
 }
Esempio n. 47
0
 public IConstraint InvariantLike()
 {
     _evaluation = new LikeEvaluation(_theObject, _attributeName, false);
     return this;
 }
Esempio n. 48
0
 public IConstraint Smaller()
 {
     _evaluation = new ComparisonEvaluation(_theObject, _attributeName,
                                            ComparisonConstraint.ComparisonTypeLt);
     return this;
 }