/// <summary> /// Gets solver function by adequacy criterion type /// </summary> /// <param name="key"><see cref="AdequacyCriterionType"/></param> /// <returns>Solver for the specified criterion type</returns> public Func <double, double, double> this[AdequacyCriterionType key] { get { return(solvers[key]); } }
/// <summary> /// Initializes new instance of <see cref="AdequacyCriterion"/> /// </summary> /// <param name="id">Adequacy criterion identifier</param> /// <param name="name">Adequacy criterion name</param> /// <param name="variableIdentifier">Adequacy criterion variable identifier</param> /// <param name="adequacyType">Adequacy criterion type</param> public AdequacyCriterion( TId id, string name, string variableIdentifier, AdequacyCriterionType adequacyType) : base(id, name, variableIdentifier, CriterionType.Minimizing, string.Empty) { AdequacyType = adequacyType; }
/// <summary> /// Gets adequacy criterion value (residual) by its type /// </summary> /// <param name="criterionType">Type of the adequacy criterion - defines residual function /// to use to calculate adequacy criterion value</param> /// <param name="mathCriterionValue">Value of the criterion calculated by mathematical model (Φc)</param> /// <param name="realCriterionValue">Value of the criterion observed during the real experiment (Φexp)</param> /// <returns>adequacy criterion value</returns> /// <remarks>Utilizes <see cref="ResidualFunctionRegistry"/></remarks> /// <exception cref="NotSupportedException">If there is no residual function for <paramref name="criterionType"/></exception> private static double GetResidual(AdequacyCriterionType criterionType, double mathCriterionValue, double realCriterionValue) { Func <double, double, double> residualFunction = ResidualFunctionRegistry.Instance[criterionType]; if (residualFunction == null) { throw new NotSupportedException("Adequacy criterion type " + criterionType.ToString() + " is not currently supported"); } return(residualFunction(mathCriterionValue, realCriterionValue)); }
private void btnOK_Click(object sender, EventArgs e) { string critName = this.txtCriterionName.Text.Trim(); string critVariableIdentifier = this.txtCriterionVariableIdentifier.Text.Trim(); AdequacyCriterionType critType = AdequacyCriterionTypeManager.ParseName(this.cmbAdequacyCriterionType.Text); if (string.IsNullOrEmpty(critName)) { MessageBoxHelper.ShowExclamation("Введите имя критерия оптимальности"); return; } if (!string.IsNullOrEmpty(critVariableIdentifier)) { if (!VariableIdentifierChecker.RegExCheck(critVariableIdentifier)) { MessageBoxHelper.ShowExclamation("Идентификатор переменной должен начинаться только с заглавной или строчной буквы \nлатинского алфавита и содержать заглавные и строчные буквы латинского алфавита,\n цифры и символ подчеркивания"); return; } if (criterion == null || criterion.VariableIdentifier != critVariableIdentifier) { if (model.CheckCriterionVariableIdentifier(critVariableIdentifier)) { MessageBoxHelper.ShowExclamation("Параметр с таким идентификатором переменной уже существует в модели"); return; } } } if (criterion == null) { TId criterionId = model.Criteria.GetFreeConsequentId(); criterion = new AdequacyCriterion( criterionId, critName, critVariableIdentifier, critType); model.Criteria.Add(criterion); } else { criterion.Name = critName; criterion.VariableIdentifier = critVariableIdentifier; criterion.AdequacyType = critType; } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Reads a collection of <see cref="AdequacyCriterion"/> from XML /// </summary> /// <param name="criteriaCollection">A collection to be read from XML</param> /// <param name="criteriaCollectionElement"><see cref="XElement"/> to read a collection from</param> private static void ReadCriteria(NamedModelEntityCollection <AdequacyCriterion> criteriaCollection, XElement criteriaCollectionElement) { IEnumerable <XElement> criterionElements = criteriaCollectionElement.Descendants(Elements.Criterion); foreach (XElement criterionElement in criterionElements) { TId id = TId.Parse(criterionElement.Attribute(Attributes.Id).Value); string name = criterionElement.Attribute(Attributes.Name).Value; string variableIdentifier = criterionElement.Attribute(Attributes.VariableIdentifier).Value; AdequacyCriterionType criterionType = EnumEx.Parse <AdequacyCriterionType>(criterionElement.Attribute(Attributes.Type).Value); AdequacyCriterion criterion = new AdequacyCriterion(id, name, variableIdentifier, criterionType); ReadPropertyCollection(criterion.Properties, ReadCollectionElement(Elements.Properties, criterionElement, false)); criteriaCollection.Add(criterion); } }
public static Bitmap GetImage(AdequacyCriterionType value) { switch (value) { case AdequacyCriterionType.UserDefined: return(new Bitmap(0, 0)); case AdequacyCriterionType.DifferenceInSquare: return(new Bitmap(Properties.Resources.DifferenceInSquare)); case AdequacyCriterionType.AbsoluteDifference: return(new Bitmap(Properties.Resources.AbsoluteDifference)); case AdequacyCriterionType.AbsoluteDifferenceNormalized: return(new Bitmap(Properties.Resources.AbsoluteDifferenceNormalized)); default: throw new ArgumentException("Unknown value: " + value.ToString()); } }
// TODO: resources public static string GetFriendlyName(AdequacyCriterionType value) { // In case of localization replace literals with resources switch (value) { case AdequacyCriterionType.UserDefined: return(""); case AdequacyCriterionType.DifferenceInSquare: return("Разница в квадрате"); case AdequacyCriterionType.AbsoluteDifference: return("Разница по модулю"); case AdequacyCriterionType.AbsoluteDifferenceNormalized: return("Нормализованная разница по модулю"); default: throw new ArgumentException("Unknown value: " + value.ToString()); } }