/// <summary>
        /// Reads a collection of real <see cref="Experiment"/> 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 ReadRealExperiments(ExperimentCollection experimentCollection, XElement experimentsCollectionElement)
        {
            IEnumerable <XElement> experimentElements = experimentsCollectionElement.Descendants(Elements.RealExperiment);

            foreach (XElement experimentElement in experimentElements)
            {
                TId id     = TId.Parse(experimentElement.Attribute(Attributes.Id).Value);
                int number = Convert.ToInt32(experimentElement.Attribute(Attributes.Number).Value);

                Experiment experiment = new Experiment(id, number);

                ReadValueCollection(experiment.ParameterValues, Elements.OptimizationParameterValues, Elements.OptimizationParameterValue, experimentElement);
                ReadValueCollection(experiment.CriterionValues, Elements.RealCriterionValues, Elements.RealCriterionValue, experimentElement);
                ReadValueCollection(experiment.ConstraintValues, Elements.FunctionalConstraintValues, Elements.FunctionalConstraintValue, experimentElement);
                ReadPropertyCollection(experiment.Properties, ReadCollectionElement(Elements.Properties, experimentElement, false));

                experimentCollection.Add(experiment);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates <see cref="Model"/>'s experiments (<see cref="Experiment"/>) based on the <see cref="IdentificationExperiment"/>
        /// stored in the <paramref name="identificationModel"/> and puts them to the <paramref name="destination"/> collection
        /// </summary>
        /// <param name="identificationModel"><see cref="IdentificationModel"/> instance to take experiments from</param>
        /// <param name="destination">Destination collection (save experiments to)</param>
        /// <param name="identificationParameterIdMap">IDs map for parameters (<see cref="ModelsConverter.CopyParameters"/></param>
        private static void CreateExperiments(IdentificationModel identificationModel, ExperimentCollection destination, IDictionary <TId, TId> identificationParameterIdMap)
        {
            destination.Clear();
            foreach (IdentificationExperiment experiment in identificationModel.IdentificationExperiments.Values)
            {
                // Here we are leaving Custom Properties behind, but that should be fine for now
                Experiment toAdd = new Experiment(experiment.Id, experiment.Number);

                foreach (Parameter identificationParameter in identificationModel.IdentificationParameters.Values)
                {
                    TId parameterId = identificationParameterIdMap[identificationParameter.Id];
                    if (experiment.IdentificationParameterValues.ContainsKey(identificationParameter.Id))
                    {
                        toAdd.ParameterValues.Add(parameterId, experiment.IdentificationParameterValues[identificationParameter.Id]);
                    }
                }

                foreach (AdequacyCriterion criterion in identificationModel.Criteria.Values)
                {
                    if (experiment.AdequacyCriterionValues.ContainsKey(criterion.Id))
                    {
                        toAdd.CriterionValues.Add(criterion.Id, experiment.AdequacyCriterionValues[criterion.Id]);
                    }
                }

                foreach (Constraint constraint in identificationModel.FunctionalConstraints.Values)
                {
                    if (experiment.ConstraintValues.ContainsKey(constraint.Id))
                    {
                        toAdd.ConstraintValues.Add(constraint.Id, experiment.ConstraintValues[constraint.Id]);
                    }
                }

                destination.Add(toAdd);
            }
        }