/// <summary> /// Evaluates the solution found by the algorithm by a given evaluation method /// </summary> /// <typeparam name="Score">The type of scoring the evaluation uses</typeparam> /// <param name="evaluationMethod">The evaluation method used to score the solution</param> /// <returns>The score given by the evaluation method</returns> public Score Evaluate <Score>(EvaluationBase <Score> evaluationMethod) { if (_solution == null) { throw new AlgorithmException("Stable Marriage not calculated yet"); } return(evaluationMethod.Evaluate(_stableMarriage, _solution)); }
public PeaResult Run(PeaSettings settings, IEvaluationInitData initData, LaunchTravelersDelegate launchTravelers = null) { string[] keys = new string[settings.SubProblemList.Count]; for (int i = 0; i < settings.SubProblemList.Count; i++) { keys[i] = settings.SubProblemList[i].Encoding.Key; } Key = new MultiKey(keys); var islandEngine = IslandEngineFactory.Create(Key, settings, settings.Seed); AddCallbackEvents(islandEngine, settings.NewEntityMergedToBest); Evaluator = (EvaluationBase)TypeLoader.CreateInstance(settings.Evaluation, settings.ParameterSet); Evaluator.Init(initData); islandEngine.Algorithm.SetEvaluationCallback(Evaluate); islandEngine.Init(initData); if (launchTravelers != null) { islandEngine.LaunchTravelers += launchTravelers; } var c = 0; StopDecision stopDecision; while (true) { islandEngine.Algorithm.RunOnce(); stopDecision = islandEngine.StopCriteria.MakeDecision(islandEngine, islandEngine.Algorithm.Population); if (stopDecision.MustStop) { Debug.WriteLine(stopDecision.Reasons[0]); break; } c++; } return(new PeaResult(stopDecision.Reasons, islandEngine.Algorithm.Population.Bests)); }