예제 #1
0
        public void Execute( )
        {
            RiverSystemScenario testScenario;
            RiverSystemProject  testProject;

            TestHelperRiverSystem.getAPreconfiguredTestScenarioWithAWBM(3, out testProject,
                                                                        out testScenario);

            IObjectiveEvaluator <MetaParameterSet> evaluator        = buildNewEvaluator(testScenario);
            ICandidateFactory <MetaParameterSet>   candidateFactory = new LumpedAWBMFactory(testScenario, new BasicRngFactory(123));

            int pSetNumber = 5;

            IObjectiveScores[]     scores = new IObjectiveScores[pSetNumber];
            ISystemConfiguration[] pSets  = new ISystemConfiguration[pSetNumber];


            int k = 0;

            foreach (Catchment c in testScenario.Network.catchmentList)
            {
                foreach (StandardFunctionalUnit fu in c.FunctionalUnits)
                {
                    var list = AccessorMemberInfo.GetFieldsAndPropertiesList(fu.rainfallRunoffModel.GetType(), typeof(double), typeof(ParameterAttribute));
                    foreach (MemberInfo m in list)
                    {
                        string metaParameterName = "$tag" + k++;
                        UpdateFunctionBuilder.CreateMetaParameter(testScenario, metaParameterName);
                        UpdateFunctionBuilder.CreateUpdateFunctionWithLinkToMetaParameter(testScenario, metaParameterName, m, fu.rainfallRunoffModel);
                    }
                }
            }

            for (int i = 0; i < scores.Length; i++)
            {
                pSets[i] = candidateFactory.CreateRandomCandidate();

                //Do we need to reset the model states??
                scores[i] = evaluator.EvaluateScore((MetaParameterSet)pSets[i]);

                //print Params after each iteration
                LumpedAWBMFactory.printPrams(testScenario, pSets[i]);
            }
            IObjectiveScores[] paretoScores = ParetoRanking <IObjectiveScores> .GetParetoFront(scores);


            SourceUtility.PrintObjScores(scores);
            Console.WriteLine("----------------------------------------");
            SourceUtility.PrintObjScores(paretoScores);
        }
        /// <summary>
        /// Apply this system configuration to a compatible system, usually a 'model' in the broad sense of the term.
        /// </summary>
        /// <param name="system">A compatible system, usually a 'model' in the broad sense of the term</param>
        /// <exception cref="ArgumentException">thrown if this system configuration cannot be meaningfully applied to the specified system</exception>
        public void ApplyConfiguration(object system)
        {
            foreach (KeyValuePair <string, double> keyValuePair in masterKnobs)
            {
                UpdateFunctionBuilder.SetMetaParameterValue(system as RiverSystemScenario, keyValuePair.Key, keyValuePair.Value);
            }

            //foreach (var keyValPair in masterParameterSetValues)
            //{
            //    double masterValue = keyValPair.Value.Value;
            //    foreach (var tiedParameter in this.ParameterMapping[keyValPair.Key])
            //    {
            //        tiedParameter.UseControllingValue(masterValue);
            //    }
            //}
        }