private MpiObjectiveScores CalculateCatchmentScores(CatchmentDefinition catchment, SerializableDictionary <string, MpiTimeSeries> catchmentTimeSeries, MpiSysConfig sysConfig)
        {
            // convert back to the Time.Data.TimeSeries objects for use by the statistics objects.
            SerializableDictionary <string, TimeSeries> convertedCatchmentTimeSeries = new SerializableDictionary <string, TimeSeries>();

            foreach (KeyValuePair <string, MpiTimeSeries> keyValuePair in catchmentTimeSeries)
            {
                MpiTimeSeries value = keyValuePair.Value;
                convertedCatchmentTimeSeries.Add(keyValuePair.Key, new TimeSeries(value.Start, value.TimeStep, value.TimeSeries));
            }

            // make the pre-calculated time series look like a point time series model so it can be used by the statistics evaluator
            PointTimeSeriesSimulationDictionaryAdapter catchmentTimeSeriesAdapter = new PointTimeSeriesSimulationDictionaryAdapter(convertedCatchmentTimeSeries);

            catchmentTimeSeriesAdapter.SetPeriod(catchment.Cells[0].ModelRunDefinition.StartDate, catchment.Cells[0].ModelRunDefinition.EndDate);

            // retrieve the statistics evaluator for this catchment
            Log.DebugFormat("Rank {0}: Catchment '{1}' creating score evaluator", WorldRank, catchment.Id);
            var catchmentScoreEvaluator = GetCatchmentStatisticsEvaluator(catchment, catchmentTimeSeriesAdapter);

            catchmentScoreEvaluator.SetModelRunner(catchmentTimeSeriesAdapter);
            Log.DebugFormat("Rank {0}: Catchment '{1}' evaluating score", WorldRank, catchment.Id);
            MpiObjectiveScores calculateCatchmentScores = new MpiObjectiveScores(catchmentScoreEvaluator.EvaluateScore(catchmentTimeSeriesAdapter, sysConfig), catchment.Id);

            return(calculateCatchmentScores);
        }
        private MpiObjectiveScores CalculateCatchmentScores(CatchmentDefinition catchment, SerializableDictionary <string, MpiTimeSeries>[] cellResults, MpiSysConfig sysConfig, int cellCount)
        {
            LumpedCatchmentObjectivesDefinition objDef = SerializationHelper.XmlDeserialize <LumpedCatchmentObjectivesDefinition>(new FileInfo(ObjectiveDefinitionFileName));

            objDef.CatchmentIdentifier = catchment.Id;

            PointTimeSeriesSimulationDictionaryAdapter catchmentTimeSeriesAdapter = new PointTimeSeriesSimulationDictionaryAdapter(AverageCellTimeSeries(cellResults, cellCount));

            catchmentTimeSeriesAdapter.SetPeriod(catchment.Cells[0].ModelRunDefinition.StartDate, catchment.Cells[0].ModelRunDefinition.EndDate);
            IClonableObjectiveEvaluator <MpiSysConfig> catchmentScoreEvaluator = new CatchmentStatisticsEvaluator <ICloneableSimulation, MpiSysConfig>(
                catchmentTimeSeriesAdapter,
                objDef.BuildAnalysis(),
                objDef.GetMaximizable(),
                objDef.GetObjectiveNames());

            return(new MpiObjectiveScores(catchmentScoreEvaluator.EvaluateScore(sysConfig)));
        }
        private CatchmentStatisticsEvaluator <ICloneableSimulation, MpiSysConfig> GetCatchmentStatisticsEvaluator(
            CatchmentDefinition catchment,
            PointTimeSeriesSimulationDictionaryAdapter catchmentTimeSeriesAdapter)
        {
            CatchmentStatisticsEvaluator <ICloneableSimulation, MpiSysConfig> catchmentScoreEvaluator;

            CatchmentStatisticsEvaluatorCache.TryGetValue(catchment.Id, out catchmentScoreEvaluator);
            if (catchmentScoreEvaluator == null)
            {
                LumpedCatchmentObjectivesDefinition objDef =
                    SerializationHelper.XmlDeserialize <LumpedCatchmentObjectivesDefinition>(new FileInfo(ObjectiveDefinitionFileName));
                objDef.CatchmentIdentifier = catchment.Id;
                catchmentScoreEvaluator    = new CatchmentStatisticsEvaluator <ICloneableSimulation, MpiSysConfig>(
                    catchmentTimeSeriesAdapter,
                    objDef.BuildAnalysis(),
                    objDef.GetMaximizable(),
                    objDef.GetObjectiveNames());

                CatchmentStatisticsEvaluatorCache.Add(catchment.Id, catchmentScoreEvaluator);
            }

            return(catchmentScoreEvaluator);
        }