Esempio n. 1
0
        public Experiment(XmlNode configNode, string baseDirectory, LoadOptions loadOptions)
        {
            XmlAttributeCollection attrs = configNode.Attributes;

            if (attrs != null)
            {
                if (attrs.GetNamedItem(XMLTags.nameAttribute) != null)
                {
                    Name = attrs[XMLTags.nameAttribute].Value;
                }
            }

            foreach (XmlNode child in configNode.ChildNodes)
            {
                switch (child.Name)
                {
                case XMLTags.forkTag:
                    Fork newFork = new Fork(child);
                    Forks.Add(newFork);
                    break;

                case XmlTags.Version:
                    AppVersion appVersion = new AppVersion(child);
                    AppVersions.Add(appVersion);
                    break;

                case XMLTags.ExperimentalUnitNodeTag:
                    if (loadOptions.Selection == LoadOptions.ExpUnitSelection.All ||
                        (ExperimentalUnit.LogFileExists(child.Attributes[XMLTags.pathAttribute].Value, baseDirectory)
                         == (loadOptions.Selection == LoadOptions.ExpUnitSelection.OnlyFinished)))
                    {
                        ExperimentalUnit newExpUnit = new ExperimentalUnit(child, baseDirectory, loadOptions);
                        if (loadOptions.LoadVariablesInLog)
                        {
                            //We load the list of variables from the log descriptor and add them to the global list
                            Log.Descriptor logDescriptor = new Log.Descriptor(newExpUnit.LogDescriptorFileName);
                            newExpUnit.Variables.AddRange(logDescriptor.StateVariables);
                            newExpUnit.Variables.AddRange(logDescriptor.ActionVariables);
                            newExpUnit.Variables.AddRange(logDescriptor.RewardVariables);
                            newExpUnit.Variables.AddRange(logDescriptor.StatVariables);
                            //these two must be added manually
                            newExpUnit.Variables.Add(Log.Data.EpisodeRealTimeVariable);
                            newExpUnit.Variables.Add(Log.Data.ExperimentRealTimeVariable);
                            foreach (string variable in newExpUnit.Variables)
                            {
                                AddVariable(variable);
                            }
                        }
                        ExperimentalUnits.Add(newExpUnit);
                    }
                    break;
                }
            }

            //set the children's AppVersions
            foreach (ExperimentalUnit expUnit in ExperimentalUnits)
            {
                expUnit.AppVersions = AppVersions;
            }

            //update progress
            loadOptions.OnExpLoaded?.Invoke(this);
        }