コード例 #1
0
        private static void _SaveRouteAttributes(XmlWriter writer, Route route, IVrpSolver solver)
        {
            bool attributesContainsParams = false;

            Debug.Assert(solver.NetworkDescription != null);
            foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes)
            {
                foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                {
                    attributesContainsParams = true;
                    break;
                }
                if (attributesContainsParams)
                {
                    break;
                }
            }

            if (attributesContainsParams)
            {
                SolverSettings solverSettings = solver.SolverSettings;

                writer.WriteStartElement(ATTRIBUTE_PARAMS_NODE_NAME);
                foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes)
                {
                    bool containsParams = false;
                    foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                    {
                        containsParams = true;
                        break;
                    }

                    if (containsParams)
                    {
                        writer.WriteStartElement(ATTRIBUTE_NODE_NAME);
                        writer.WriteAttributeString(NAME_ATTR_NAME, attribute.Name);
                        foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                        {
                            writer.WriteStartElement(PARAM_NODE_NAME);
                            writer.WriteAttributeString(NAME_ATTR_NAME, parameter.Name);

                            object valueObj = null;
                            if (!solverSettings.GetNetworkAttributeParameterValue(attribute.Name,
                                                                                  parameter.Name,
                                                                                  out valueObj))
                            {
                                valueObj = null;
                            }

                            string value = _ConvertValue2String(valueObj);

                            writer.WriteAttributeString(VALUE_ATTR_NAME, value);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
            }
        }
コード例 #2
0
        internal static int[][] Calculate(Problem problem,
                                          SolverSettings settings,
                                          int categories)
        {
            Solver <List <Genome>, Problem, Fitness> solver = new Solver <List <Genome>, Problem, Fitness>(
                problem,
                settings,
                new TournamentBasedSelector <List <Genome>, Problem, Fitness>(10, 0.5),
                new RedivideFromLargeMutationOperation(),
                new RandomRandomSelectionCrossOverOperation(),
                new BestFastPlacementGenerationOperation(),
                new FitnessCalculator(categories));

            solver.ProgressReporter = _registered_progress_reporter;
            solver.NewFittest      += new Solver <List <Genome>, Problem, Fitness> .NewFittestDelegate(solver_NewFittest);

            Individual fittest = solver.Start(null) as Individual;

            int[][] solution = new int[fittest.Genomes.Count][];
            for (int route_idx = 0; route_idx < fittest.Genomes.Count; route_idx++)
            {
                solution[route_idx] = new int[fittest.Genomes[route_idx].Count];
                for (int idx = 0; idx < fittest.Genomes[route_idx].Count; idx++)
                {
                    solution[route_idx][idx] = fittest.Genomes[route_idx][idx];
                }
            }
            return(solution);
        }
コード例 #3
0
ファイル: SolverGroup.cs プロジェクト: zhuowp/ge
        /// <summary>
        /// Solves a child updateable.  Some children may override the group's update method;
        /// this avoids code repeat.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="activeConstraints"> </param>
        protected void SolveUpdateable(SolverUpdateable item, ref int activeConstraints)
        {
            if (item.isActiveInSolver)
            {
                SolverSettings subSolverSettings = item.solverSettings;

                subSolverSettings.currentIterations++;
                if (subSolverSettings.currentIterations <= solver.iterationLimit &&
                    subSolverSettings.currentIterations <= subSolverSettings.maximumIterationCount)
                {
                    if (item.SolveIteration() < subSolverSettings.minimumImpulse)
                    {
                        subSolverSettings.iterationsAtZeroImpulse++;
                        if (subSolverSettings.iterationsAtZeroImpulse > subSolverSettings.minimumIterationCount)
                        {
                            item.isActiveInSolver = false;
                        }
                        else
                        {
                            activeConstraints++;
                        }
                    }
                    else
                    {
                        subSolverSettings.iterationsAtZeroImpulse = 0;
                        activeConstraints++;
                    }
                }
                else
                {
                    item.isActiveInSolver = false;
                }
            }
        }
コード例 #4
0
        private void addSolverSettings(SolverSettings settings)
        {
            var solverSettingsExport = new SolverSettingsExport {
                Name = settings.Name
            };

            var solverPara = addSolverParameter("AbsTol", settings.AbsTol);

            solverSettingsExport.AbsTol = solverPara.Id;
            solverPara = addSolverParameter("RelTol", settings.RelTol);
            solverSettingsExport.RelTol = solverPara.Id;
            solverPara = addSolverParameter("H0", settings.H0);
            solverSettingsExport.H0 = solverPara.Id;
            solverPara = addSolverParameter("HMin", settings.HMin);
            solverSettingsExport.HMin = solverPara.Id;
            solverPara = addSolverParameter("HMax", settings.HMax);
            solverSettingsExport.HMax = solverPara.Id;
            solverPara = addSolverParameter("MxStep", settings.MxStep);
            solverSettingsExport.MxStep = solverPara.Id;
            solverPara = addSolverParameter("UseJacobian", settings.UseJacobian ? 1 : 0);
            solverSettingsExport.UseJacobian = solverPara.Id;

            var extraOptions = new List <SolverOptionExport>();

            solverSettingsExport.SolverOptions = extraOptions;
            Solver = solverSettingsExport;
        }
コード例 #5
0
        /// <summary>
        /// Calculates solution to the given problem.
        /// </summary>
        /// <param name="problem"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static int[][] Calculate(OsmSharp.Math.VRP.Core.IProblemWeights problem,
                                        Second min, Second max)
        {
            Problem        local_problem = new LocalProblem(problem, min, max);
            SolverSettings settings      = new SolverSettings(1000, 10, 0, 10, 20, 30);

            return(Facade.Calculate(local_problem, settings, 50));
        }
コード例 #6
0
        public Task <ISolver> CreateSolverAsync()
        {
            var @checked   = IncludeChecked.Value ? Tree.GetCheckedNodes() : null;
            var crossed    = ExcludeCrossed.Value ? Tree.GetCrossedNodes() : null;
            var iterations = Iterations.Value;
            var settings   = new SolverSettings(@checked, crossed, iterations);

            return(CreateSolverAsync(settings));
        }
コード例 #7
0
        protected override void Context()
        {
            _objectPathFactory = IoC.Resolve <IObjectPathFactory>();
            var solverSettingsFactory = IoC.Resolve <ISolverSettingsFactory>();

            _solverSettings = solverSettingsFactory.CreateCVODE();
            _simulationExporterCreatorFactory = IoC.Resolve <ISimulationExportCreatorFactory>();
            sut = new SimModelExporter(_simulationExporterCreatorFactory, new ExportSerializer(_simModelXmlSerializerRepository));
        }
コード例 #8
0
 public IObjectBaseDTO MapFrom(SolverSettings solverSettings)
 {
     return(new ObjectBaseDTO
     {
         Id = AppConstants.SolverSettingsId,
         Icon = ApplicationIcons.Solver.IconName,
         Name = AppConstants.Captions.SolverSettings,
     });
 }
コード例 #9
0
 protected override ISolver CreateSolver(SolverSettings settings)
 {
     if (!settings.Checked.Any())
     {
         DialogCoordinator.ShowInfoAsync(this,
                                         L10n.Message("Please tag non-skilled nodes by right-clicking them."));
         return(null);
     }
     return(new SteinerSolver(Tree, settings));
 }
コード例 #10
0
        public SolverSettingsDTO MapFrom(SolverSettings solverSettings)
        {
            var dto = new SolverSettingsDTO
            {
                Name          = solverSettings.Name,
                SolverOptions = dtoBaseOptionsFrom(solverSettings)
            };

            return(dto);
        }
コード例 #11
0
        protected override void Context()
        {
            _objectPathFactory = IoC.Resolve <IObjectPathFactory>();
            var solverSettingsFactory = IoC.Resolve <ISolverSettingsFactory>();

            _solverSettings = solverSettingsFactory.CreateCVODE();
            _tableFormulaToTableFormulaExportMapper = IoC.Resolve <ITableFormulaToTableFormulaExportMapper>();
            _concentrationBasedFormulaUpdater       = IoC.Resolve <IConcentrationBasedFormulaUpdater>();
            sut = new SimModelExporter(new CreateExportModelVisitor(_objectPathFactory, _tableFormulaToTableFormulaExportMapper, _concentrationBasedFormulaUpdater), new ExportSerializer(_simModelXmlSerializerRepository));
        }
コード例 #12
0
        /// <summary>
        /// Saves Curb approach settings.
        /// </summary>
        private void _SaveCurbApproachSettings()
        {
            IVrpSolver     solver   = App.Current.Solver;
            SolverSettings settings = _GetSolverSettings(solver);

            if (settings != null)
            {
                settings.UTurnAtStops    = MakeUTurnsAtStops.IsChecked ?? false;
                settings.StopOnOrderSide = StopOnOrderSide.IsChecked ?? false;
            }
        }
コード例 #13
0
        /// <summary>
        /// Saves UTurn settings.
        /// </summary>
        private void _SaveUTurnSettings()
        {
            IVrpSolver     solver   = App.Current.Solver;
            SolverSettings settings = _GetSolverSettings(solver);

            if (settings != null)
            {
                settings.UTurnAtIntersections = MakeUTurnsAtIntersections.IsChecked ?? false;
                settings.UTurnAtDeadEnds      = MakeUTurnsAtDeadEnds.IsChecked ?? false;
            }
        }
コード例 #14
0
        public override ISolver CreateSolver(SolverSettings settings)
        {
            var attributeConstraints = AttributeConstraints.ToDictionary(
                constraint => constraint.Data,
                constraint => new Tuple <float, double>(constraint.TargetValue, constraint.Weight / 100.0));
            var pseudoConstraints = PseudoAttributeConstraints.ToDictionary(
                constraint => constraint.Data,
                constraint => new Tuple <float, double>(constraint.TargetValue, constraint.Weight / 100.0));

            return(new AdvancedSolver(Tree, new AdvancedSolverSettings(settings, CreateInitialAttributes(), attributeConstraints,
                                                                       pseudoConstraints, WeaponClass, Tags, OffHand)));
        }
コード例 #15
0
ファイル: Solver.cs プロジェクト: ErtyHackward/utopia
 protected internal void UnsafePrestep(SolverUpdateable updateable)
 {
     updateable.UpdateSolverActivity();
     if (updateable.isActiveInSolver)
     {
         SolverSettings solverSettings = updateable.solverSettings;
         solverSettings.currentIterations       = 0;
         solverSettings.iterationsAtZeroImpulse = 0;
         updateable.Update(timeStepSettings.TimeStepDuration);
         updateable.ExclusiveUpdate();
     }
 }
コード例 #16
0
        protected override async Task <ISolver> CreateSolverAsync(SolverSettings settings)
        {
            if (!settings.Checked.Any())
            {
                // todo "this" as context is not registered when running without window
                await DialogCoordinator.ShowInfoAsync(DialogContext,
                                                      L10n.Message("Please tag non-skilled nodes by right-clicking them."));

                return(null);
            }
            return(new SteinerSolver(Tree, settings));
        }
コード例 #17
0
        /// <summary>
        /// Get value for parameter.
        /// </summary>
        /// <param name="attributeName">Attribute name.</param>
        /// <param name="parameterName">Parameter name.</param>
        /// <param name="solverSettings">Solver settings from which
        /// parameter value will be taken.</param>
        /// <returns>Parameter value or empty string if no such parameter.</returns>
        private string _GetParameterValue(string attributeName, string parameterName,
                                          SolverSettings solverSettings)
        {
            object valueObj = null;

            if (!solverSettings.GetNetworkAttributeParameterValue(attributeName,
                                                                  parameterName, out valueObj))
            {
                valueObj = null;
            }

            return(_ConvertValue2String(valueObj));
        }
コード例 #18
0
 private IEnumerable <ISolverOptionDTO> dtoBaseOptionsFrom(SolverSettings input)
 {
     return(new List <ISolverOptionDTO>
     {
         new SolverOptionDTO <double>("AbsTol", input.AbsTol, ToolTips.SolverOptions.AbsTol),
         new SolverOptionDTO <double>("RelTol", input.RelTol, ToolTips.SolverOptions.RelTol),
         new SolverOptionDTO <double>("H0", input.H0, ToolTips.SolverOptions.H0),
         new SolverOptionDTO <double>("HMin", input.HMin, ToolTips.SolverOptions.HMin),
         new SolverOptionDTO <double>("HMax", input.HMax, ToolTips.SolverOptions.HMax),
         new SolverOptionDTO <int>("MxStep", input.MxStep, ToolTips.SolverOptions.MxStep),
         new SolverOptionDTO <bool>("UseJacobian", input.UseJacobian, ToolTips.SolverOptions.UseJacobian)
     });
 }
コード例 #19
0
        protected override Task <ISolver> CreateSolverAsync(SolverSettings settings)
        {
            var attributeConstraints = AttributeConstraints.ToDictionary(
                constraint => constraint.Data,
                constraint => new Tuple <float, double>(constraint.TargetValue, constraint.Weight / 100.0));
            var pseudoConstraints = PseudoAttributeConstraints.ToDictionary(
                constraint => constraint.Data,
                constraint => new Tuple <float, double>(constraint.TargetValue, constraint.Weight / 100.0));
            var solver = new AdvancedSolver(Tree, new AdvancedSolverSettings(settings, TotalPoints,
                                                                             CreateInitialAttributes(), attributeConstraints,
                                                                             pseudoConstraints, WeaponClass.Value, Tags.Value, OffHand.Value));

            return(Task.FromResult <ISolver>(solver));
        }
コード例 #20
0
ファイル: Solver.cs プロジェクト: ErtyHackward/utopia
        void MultithreadedIteration(int i)
        {
            //'i' is currently an index into an implicit array of solver updateables that goes from 0 to solverUpdateables.count * iterationLimit.
            //It includes iterationLimit copies of each updateable.
            //Permute the entire set with duplicates.
            var updateable = solverUpdateables.Elements[(i * prime) % solverUpdateables.count];


            SolverSettings solverSettings = updateable.solverSettings;

            //Updateables only ever go from active to inactive during iterations,
            //so it's safe to check for activity before we do hard (synchronized) work.
            if (updateable.isActiveInSolver)
            {
                int incrementedIterations = -1;
                updateable.EnterLock();
                //This duplicate test protects against the possibility that the updateable went inactive between the first check and the lock.
                if (updateable.isActiveInSolver)
                {
                    if (updateable.SolveIteration() < solverSettings.minimumImpulse)
                    {
                        solverSettings.iterationsAtZeroImpulse++;
                        if (solverSettings.iterationsAtZeroImpulse > solverSettings.minimumIterations)
                        {
                            updateable.isActiveInSolver = false;
                        }
                    }
                    else
                    {
                        solverSettings.iterationsAtZeroImpulse = 0;
                    }

                    //Increment the iteration count.
                    incrementedIterations = solverSettings.currentIterations++;
                }
                updateable.ExitLock();
                //Since the updateables only ever go from active to inactive, it's safe to check outside of the lock.
                //Keeping this if statement out of the lock allows other waiters to get to work a few nanoseconds faster.
                if (incrementedIterations > iterationLimit ||
                    incrementedIterations > solverSettings.maximumIterations)
                {
                    updateable.isActiveInSolver = false;
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// Inits data grid.
        /// </summary>
        private void _InitDataGrid()
        {
            try
            {
                // If active schedule hasn't been set - do it.
                if (App.Current.Project != null &&
                    App.Current.Project.Schedules.ActiveSchedule == null)
                {
                    // Load schedule for current date.
                    var currentSchedule = OptimizeAndEditHelpers.LoadSchedule(
                        App.Current.Project,
                        App.Current.CurrentDate,
                        OptimizeAndEditHelpers.FindScheduleToSelect);

                    // If current date schedule have routes -
                    // select current schedule as active.
                    if (currentSchedule.Routes.Count > 0)
                    {
                        App.Current.Project.Schedules.ActiveSchedule = currentSchedule;
                    }
                }

                _ClearGridSource();

                IVrpSolver                solver         = App.Current.Solver;
                SolverSettings            solverSettings = solver.SolverSettings;
                ICollection <Restriction> restrictions   = solverSettings.Restrictions;
                if (0 < restrictions.Count)
                {
                    NetworkDescription networkDescription = solver.NetworkDescription;

                    // Obtain max "non-restriction" parameters count.
                    int maxParametersCount = _GetNonRestrictionParametersMaximumCount(
                        networkDescription, restrictions);

                    _InitDataGridLayout(maxParametersCount);
                }
            }
            catch (Exception ex)
            {
                Logger.Critical(ex);
            }
        }
コード例 #22
0
ファイル: Solver.cs プロジェクト: ErtyHackward/utopia
        protected internal void UnsafeSolveIteration(SolverUpdateable updateable)
        {
            if (updateable.isActiveInSolver)
            {
                SolverSettings solverSettings = updateable.solverSettings;


                solverSettings.currentIterations++;
                if (solverSettings.currentIterations <= iterationLimit &&
                    solverSettings.currentIterations <= solverSettings.maximumIterations)
                {
                    if (updateable.SolveIteration() < solverSettings.minimumImpulse)
                    {
                        solverSettings.iterationsAtZeroImpulse++;
                        if (solverSettings.iterationsAtZeroImpulse > solverSettings.minimumIterations)
                        {
                            updateable.isActiveInSolver = false;
                        }
                    }
                    else
                    {
                        solverSettings.iterationsAtZeroImpulse = 0;
                    }
                }
                else
                {
                    updateable.isActiveInSolver = false;
                }

                //if (++solverSettings.currentIterations > iterationLimit ||
                //    solverSettings.currentIterations > solverSettings.maximumIterations ||
                //    (updateable.SolveIteration() < solverSettings.minimumImpulse &&
                //    ++solverSettings.iterationsAtZeroImpulse > solverSettings.minimumIterations))
                //{
                //    updateable.isActiveInSolver = false;
                //}
                //else //If it's greater than the minimum impulse, reset the count.
                //    solverSettings.iterationsAtZeroImpulse = 0;
            }
        }
コード例 #23
0
        private DataTable tableFor(SolverSettings solver)
        {
            var dt = new DataTable(AppConstants.Captions.SolverSettings);

            dt.AddColumn(AppConstants.Captions.Name);
            dt.AddColumn(AppConstants.Captions.Value);

            dt.BeginLoadData();

            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.ABS_TOL, solver.AbsTol.ToString(CultureInfo.InvariantCulture));
            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.REL_TOL, solver.RelTol.ToString(CultureInfo.InvariantCulture));
            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.H0, solver.H0.ToString(CultureInfo.InvariantCulture));
            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.H_MIN, solver.HMin.ToString(CultureInfo.InvariantCulture));
            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.H_MAX, solver.HMax.ToString(CultureInfo.InvariantCulture));
            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.MX_STEP, solver.MxStep.ToString(CultureInfo.InvariantCulture));
            addRowFor(dt, OSPSuite.Core.Domain.Constants.Parameters.USE_JACOBIAN, solver.UseJacobian.ToString());


            dt.EndLoadData();
            dt.AcceptChanges();

            return(dt);
        }
コード例 #24
0
        /// <summary>
        /// Updates value.
        /// </summary>
        /// <param name="wrapper">Restriction data wrapper.</param>
        /// <param name="solverSettings">Solver settings.</param>
        /// <param name="attribute">Network attribute.</param>
        private void _UpdateValue(RestrictionDataWrapper wrapper, SolverSettings solverSettings,
                                  NetworkAttribute attribute)
        {
            Debug.Assert(null != wrapper);
            Debug.Assert(null != attribute);
            Debug.Assert(null != solverSettings);

            // Update restriction usage parameter if it exist.
            if (wrapper.RestrictionUsageParameter != null &&
                wrapper.RestrictionUsageParameter.Name != null)
            {
                _UpdateParameterIfNeeded(solverSettings, attribute,
                                         wrapper.RestrictionUsageParameter.Name, wrapper.RestrictionUsageParameter.Value);
            }

            // Update all other parameters.
            foreach (Parameter parameter in wrapper.Parameters)
            {
                if (!string.IsNullOrEmpty(parameter.Name))
                {
                    _UpdateParameterIfNeeded(solverSettings, attribute, parameter.Name, parameter.Value);
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// Update parameter if it has been changed.
        /// </summary>
        /// <param name="solverSettings">Solver settings in which
        /// parameter value will be updated.</param>
        /// <param name="attribute">Network attribute, which parameter must be updated.</param>
        /// <param name="parameterName">Name of the parameter which must be updated.</param>
        /// <param name="parameterValue">Value, which must be set in parameter.</param>
        /// <exception cref="System.ArgumentException">Is thrown when there is no
        /// attribute with such parameter name in solver settings.</exception>
        private void _UpdateParameterIfNeeded(SolverSettings solverSettings,
                                              NetworkAttribute attribute, string parameterName, string parameterValue)
        {
            Debug.Assert(solverSettings != null);
            Debug.Assert(attribute != null);
            Debug.Assert(parameterName != null);

            // Get parameter.
            var parameter = attribute.Parameters.First(par => par.Name == parameterName);

            // Get current parameter value.
            object valueObj = null;

            if (!solverSettings.GetNetworkAttributeParameterValue(attribute.Name, parameterName, out valueObj))
            {
                throw new ArgumentException("parameterName");
            }
            string value = _ConvertValue2String(valueObj);

            // If value has changed - set new value.
            if (!value.Equals(parameterValue, StringComparison.OrdinalIgnoreCase))
            {
                if (parameterValue != null)
                {
                    try
                    {
                        solverSettings.SetNetworkAttributeParameterValue(attribute.Name,
                                                                         parameter.Name, parameterValue);
                    }
                    // Inputed value is in wrong format - do not change solver settings.
                    catch
                    {
                    }
                }
            }
        }
コード例 #26
0
 public AutomatedSolverSettings(SolverSettings baseSettings)
     : base(baseSettings)
 {
 }
コード例 #27
0
        /// <summary>
        /// Returns a solution found using best-placement.
        /// </summary>
        /// <returns></returns>
        protected override IRoute DoSolve(OsmSharp.Math.TSP.Problems.IProblem problem)
        {
            // create the settings.
            SolverSettings settings = new SolverSettings(
                -1,
                -1,
                1000000000,
                -1,
                -1,
                -1);

            Solver <List <int>, GeneticProblem, Fitness> solver =
                new Solver <List <int>, GeneticProblem, Fitness>(
                    new GeneticProblem(problem),
                    settings,
                    null,
                    null,
                    null,
                    _generation_operation,
                    new FitnessCalculator(),
                    true, false);

            Population <List <int>, GeneticProblem, Fitness> population =
                new Population <List <int>, GeneticProblem, Fitness>(true);

            while (population.Count < _population_size)
            {
                // generate new.
                Individual <List <int>, GeneticProblem, Fitness> new_individual =
                    _generation_operation.Generate(solver);

                // add to population.
                population.Add(new_individual);
            }

            // select each individual once.
            Population <List <int>, GeneticProblem, Fitness> new_population =
                new Population <List <int>, GeneticProblem, Fitness>(true);
            Individual <List <int>, GeneticProblem, Fitness> best = null;
            int stagnation = 0;

            while (stagnation < _stagnation)
            {
                while (new_population.Count < _population_size)
                {
                    // select an individual and the next one.
                    int idx = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(population.Count);
                    Individual <List <int>, GeneticProblem, Fitness> individual1 = population[idx];
                    Individual <List <int>, GeneticProblem, Fitness> individual2 = null;
                    if (idx == population.Count - 1)
                    {
                        individual2 = population[0];
                    }
                    else
                    {
                        individual2 = population[idx + 1];
                    }
                    population.RemoveAt(idx);

                    Individual <List <int>, GeneticProblem, Fitness> new_individual = _cross_over_operation.CrossOver(solver,
                                                                                                                      individual1, individual2);

                    new_individual.CalculateFitness(solver.Problem, solver.FitnessCalculator);
                    if (new_individual.Fitness.CompareTo(
                            individual1.Fitness) < 0)
                    {
                        new_population.Add(new_individual);
                    }
                    else
                    {
                        new_population.Add(individual1);
                    }
                }

                population = new_population;
                population.Sort(solver, solver.FitnessCalculator);

                new_population = new Population <List <int>, GeneticProblem, Fitness>(true);

                if (best == null ||
                    best.Fitness.CompareTo(population[0].Fitness) > 0)
                {
                    stagnation = 0;
                    best       = population[0];
                }
                else
                {
                    stagnation++;
                }

                // report progress.
                OsmSharp.Logging.Log.TraceEvent("EdgeAssemblyCrossOverSolver", Logging.TraceEventType.Information,
                                                string.Format("Solving using EAX: Stagnation {0}.", stagnation));
            }

            var result = new List <int>(best.Genomes);

            result.Insert(0, 0);
            return(DynamicAsymmetricRoute.CreateFrom(result));
        }
コード例 #28
0
 protected override async Task Because()
 {
     _newSolverSettings = await sut.MapToModel(_snapshot);
 }
コード例 #29
0
 protected override Task <ISolver> CreateSolverAsync(SolverSettings settings)
 {
     throw new NotImplementedException();
 }
コード例 #30
0
 protected override ISolver CreateSolver(SolverSettings settings)
 {
     throw new System.NotImplementedException();
 }
コード例 #31
0
 /// <summary>
 /// Creates a solver that uses the settings defined by the user in this ViewModel.
 /// </summary>
 /// <param name="settings">(not null) Base settings specified in GeneratorTabViewModel.</param>
 protected abstract Task <ISolver> CreateSolverAsync(SolverSettings settings);