Beispiel #1
0
        public ICommand TransferParametersFrom(ParameterIdentification parameterIdentification, ParameterIdentificationRunResult runResult)
        {
            if (runResult.Status == RunStatus.Canceled)
            {
                var res = _dialogCreator.MessageBoxYesNo(Warning.ImportingParameterIdentificationValuesFromCancelledRun);
                if (res == ViewResult.No)
                {
                    return(new OSPSuiteEmptyCommand <TExecutionContext>());
                }
            }

            if (parameterIdentification.IsCategorialRunMode())
            {
                _dialogCreator.MessageBoxInfo(Warning.ImportingParameterIdentificationValuesFromCategorialRun);
            }

            var macroCommand = new OSPSuiteMacroCommand <TExecutionContext>
            {
                BuildingBlockType = ObjectTypes.Simulation,
                CommandType       = Command.CommandTypeEdit,
                ObjectType        = ObjectTypes.Simulation,
                Description       = Captions.ParameterIdentification.ParameterIdentificationTransferredToSimulations(parameterIdentification.Name)
            };

            foreach (var optimizedParameter in runResult.BestResult.Values)
            {
                var identificationParameter = parameterIdentification.IdentificationParameterByName(optimizedParameter.Name);
                if (identificationParameter == null)
                {
                    throw new OSPSuiteException(Error.IdentificationParameterCannotBeFound(optimizedParameter.Name));
                }

                macroCommand.AddRange(setOptimalParameterValueIn(identificationParameter, optimizedParameter.Value));
            }

            macroCommand.AddRange(parameterIdentification.AllFixedIdentificationParameters.SelectMany(x => setOptimalParameterValueIn(x, x.StartValue)));

            return(macroCommand);
        }