private void ProcessExperiment(IdentificationExperiment experiment) { experiment.MathematicalCriterionValues.Clear(); experiment.ConstraintValues.Clear(); mathcadWrapper.RefreshWorksheet(); foreach (KeyValuePair <TId, double> parameter in experiment.IdentificationParameterValues) { string parameterVariableIdentifier = model.IdentificationParameters[parameter.Key].VariableIdentifier; mathcadWrapper.SetValue(parameterVariableIdentifier, parameter.Value); } mathcadWrapper.Recalculate(); foreach (Criterion criterion in model.Criteria.Values) { double value = mathcadWrapper.GetValue(criterion.VariableIdentifier); experiment.MathematicalCriterionValues.Add(criterion.Id, value); } foreach (Constraint constraint in model.FunctionalConstraints.Values) { double value = mathcadWrapper.GetValue(constraint.VariableIdentifier); experiment.ConstraintValues.Add(constraint.Id, value); } }
private void CalculateExperiment(IdentificationExperiment experiment) { // Read parameters double alpha1 = experiment.IdentificationParameterValues[0]; double alpha2 = experiment.IdentificationParameterValues[1]; double alpha3 = experiment.IdentificationParameterValues[2]; double x1 = model.RealExperiments[experiment.RealExperimentId].ParameterValues[0]; double x2 = model.RealExperiments[experiment.RealExperimentId].ParameterValues[1]; double x3 = model.RealExperiments[experiment.RealExperimentId].ParameterValues[2]; // Calculate criteria double c1 = alpha1 + alpha3 - (x1 * x2); double c2 = alpha2 + x3 / (alpha1 + x2); double c3 = alpha1 - x1 * (x2 / alpha3); experiment.MathematicalCriterionValues[0] = c1; experiment.MathematicalCriterionValues[1] = c2; experiment.MathematicalCriterionValues[2] = c3; // Calculate functional constraints double fc1 = alpha1 + x2 / (alpha3 + x1); double fc2 = alpha2 + alpha1 - (x2 * x3); double fc3 = alpha2 - x2 * (x3 / alpha1); experiment.ConstraintValues[0] = fc1; experiment.ConstraintValues[1] = fc2; experiment.ConstraintValues[2] = fc3; }
private void CreateExperimentStubs() { ModelStorage.Instance.Model.IdentificationExperiments.Clear(); int experimentCount = Convert.ToInt32(numericNumberOfExperiments.Value); int experimentNumberOffset = 0; foreach (Experiment realExperiment in ModelStorage.Instance.Model.RealExperiments.Values) { for (int i = 0; i < experimentCount; i++) { IdentificationExperiment newExperiment = new IdentificationExperiment( ModelStorage.Instance.Model.IdentificationExperiments.GetFreeConsequentId(), experimentNumberOffset + i + 1, realExperiment.Id); ModelStorage.Instance.Model.IdentificationExperiments.Add(newExperiment); } experimentNumberOffset += experimentCount; } }
/// <summary> /// Reads a collection of <see cref="IdentificationExperiment"/> from XML /// </summary> /// <param name="experimentCollection">A collection to be read from XML</param> /// <param name="experimentsCollectionElement"><see cref="XElement"/> to read a collection from</param> private static void ReadIdentificationExperiments(IdentificationExperimentCollection experimentCollection, XElement experimentsCollectionElement) { IEnumerable <XElement> experimentElements = experimentsCollectionElement.Descendants(Elements.IdentificationExperiment); foreach (XElement experimentElement in experimentElements) { TId id = TId.Parse(experimentElement.Attribute(Attributes.Id).Value); int number = Convert.ToInt32(experimentElement.Attribute(Attributes.Number).Value); TId realExperimentId = TId.Parse(experimentElement.Attribute(Attributes.RealExperimentId).Value); IdentificationExperiment experiment = new IdentificationExperiment(id, number, realExperimentId); ReadValueCollection(experiment.IdentificationParameterValues, Elements.IdentificationParameterValues, Elements.IdentificationParameterValue, experimentElement); ReadValueCollection(experiment.MathematicalCriterionValues, Elements.MathematicalCriterionValues, Elements.MathematicalCriterionValue, experimentElement); ReadValueCollection(experiment.AdequacyCriterionValues, Elements.AdequacyCriterionValues, Elements.AdequacyCriterionValue, experimentElement); ReadValueCollection(experiment.ConstraintValues, Elements.FunctionalConstraintValues, Elements.FunctionalConstraintValue, experimentElement); ReadPropertyCollection(experiment.Properties, ReadCollectionElement(Elements.Properties, experimentElement, false)); experimentCollection.Add(experiment); } }