예제 #1
0
 /// <summary>
 /// Constructor for the parameters of simulation.
 /// </summary>
 /// <param name="steppers">the list of stepper.</param>
 /// <param name="initialConditions">the dictionary of the initial parameters.</param>
 /// <param name="loggerPolicy">the logging policy.</param>
 /// <param name="id">the simulation ID.</param>
 public SimulationParameter(List<EcellObject> steppers,
     Dictionary<string, Dictionary<string, double>> initialConditions,
     LoggerPolicy loggerPolicy,
     string id)
 {
     m_steppers = steppers;
     m_initialConditions = initialConditions;
     m_loggerPolicy = loggerPolicy;
     m_id = id;
 }
예제 #2
0
파일: Project.cs 프로젝트: ecell/ecell3-ide
        /// <summary>
        /// Loads the eml formatted file and returns the model ID.
        /// </summary>
        public void LoadModel()
        {
            WrappedSimulator simulator = null;
            try
            {
                foreach (string filename in m_info.Models)
                {
                    simulator = CreateSimulatorInstance();
                    // Load model
                    string modelID = null;
                    EcellModel modelObj = null;
                    try
                    {
                        modelObj = EmlReader.Parse(filename, simulator);
                    }
                    catch (EcellException e)
                    {
                        throw new EcellException(string.Format(MessageResources.ErrLoadModel, filename), e);
                    }
                    catch (Exception e)
                    {
                        string msg = string.Format(MessageResources.ErrLoadModel, filename) + "\n" + e.Message;
                        Util.ShowErrorDialog(msg);
                        continue;
                    }

                    // If file is not Eml, return.
                    if (modelObj.Children == null || modelObj.Children.Count <= 0)
                        continue;
                    if (!string.IsNullOrEmpty(modelObj.ErrMsg) && m_env.PluginManager.DockPanel != null)
                    {
                        Util.ShowWarningDialog(MessageResources.WarnLoadDM);
                        m_env.Console.Write(modelObj.ErrMsg);
                        m_env.Console.Flush();
                    }

                    // If this project is template.
                    if (m_info.Type == ProjectType.Template)
                        modelObj.ModelID = m_info.Name;
                    modelID = modelObj.ModelID;

                    // Initialize
                    try
                    {
                        simulator.Initialize();
                    }
                    catch (Exception e)
                    {
                        // Error Message
                        // [VariableReference [S0] not found in this Process]
                        // MichaelisUniUniFluxprocess
                        // DecayFluxProcess
                        // [Only first or second order scheme is allowed]
                        // PingPongBiBiFluxProcess
                        // TauLeapProcess
                        if (m_env.PluginManager.DockPanel != null)
                            Util.ShowWarningDialog(MessageResources.WarnInvalidData + "\n" + e.Message);
                        Trace.WriteLine(e.ToString());
                    }

                    // Sets initial conditions.
                    InitializeModel(modelObj, simulator);

                    try
                    {
                        string leml = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar +
                            Path.GetFileNameWithoutExtension(filename) + Constants.FileExtLEML;
                        Leml.LoadLEML(m_env, modelObj, leml);
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(e.StackTrace);
                    }
                }

                // If this project has no model.
                if (m_modelList.Count <= 0)
                    throw new EcellException(string.Format(MessageResources.ErrNoSet, "Model"));

                // Stores the "LoggerPolicy"
                string simParam = m_info.SimulationParam;
                if (!m_loggerPolicyDic.ContainsKey(simParam))
                {
                    m_loggerPolicyDic[simParam] = new LoggerPolicy();
                }
            }
            catch (Exception ex)
            {
                throw new EcellException(string.Format(MessageResources.ErrLoadModel, ""), ex);
            }

            m_simulator = simulator;
        }
예제 #3
0
 /// <summary>
 /// Constructor to copy.
 /// </summary>
 /// <param name="rhs">the src object.</param>
 public LoggerPolicy(LoggerPolicy rhs)
 {
     this.m_reloadStepCount = rhs.m_reloadStepCount;
     this.m_reloadInterval = rhs.m_reloadInterval;
     this.m_diskFullAction = rhs.m_diskFullAction;
     this.m_maxDiskSpace = rhs.m_maxDiskSpace;
 }
예제 #4
0
        public void TestLoggerPolicy()
        {
            DiskFullAction expectedFullAction = DiskFullAction.Terminate;
            int expectedMaxDiskSpace = 120;
            double expectedReloadInterval = 0.1;
            int expectedReloadStepCount = 111;

            LoggerPolicy d = new LoggerPolicy();
            d.DiskFullAction = expectedFullAction;
            d.MaxDiskSpace = expectedMaxDiskSpace;
            d.ReloadInterval = expectedReloadInterval;
            d.ReloadStepCount = expectedReloadStepCount;

            Assert.AreEqual(d.DiskFullAction, expectedFullAction, "LoggerPolicy Accessor returned unexpected value.");
            Assert.AreEqual(d.MaxDiskSpace, expectedMaxDiskSpace, "LoggerPolicy Accessor returned unexpected value.");
            Assert.AreEqual(d.ReloadInterval, expectedReloadInterval, "LoggerPolicy Accessor returned unexpected value.");
            Assert.AreEqual(d.ReloadStepCount, expectedReloadStepCount, "LoggerPolicy Accessor returned unexpected value.");

            LoggerPolicy dclone = (LoggerPolicy)d.Clone();
            Assert.AreEqual(d.DiskFullAction, dclone.DiskFullAction, "LoggerPolicy clone execute unexpected action.");
            Assert.AreEqual(d.ReloadStepCount, dclone.ReloadStepCount, "LoggerPolicy clone execute unexpected action.");
            Assert.AreEqual(d.ReloadInterval, dclone.ReloadInterval, "LoggerPolicy clone execute unexpected action.");
            Assert.AreEqual(d.MaxDiskSpace, dclone.MaxDiskSpace, "LoggerPolicy clone execute unexpected action.");
        }
예제 #5
0
 /// <summary>
 /// Creates the logger policy with some parameters.
 /// </summary>
 /// <param name="savedStepCount">The saved step count</param>
 /// <param name="savedInterval">The saved interval</param>
 /// <param name="diskFullAction">The action if the HDD is full</param>
 /// <param name="maxDiskSpace">The limit of the usable HDD</param>
 public void CreateLoggerPolicy(
     int savedStepCount,
     double savedInterval,
     DiskFullAction diskFullAction,
     int maxDiskSpace)
 {
     LoggerPolicy loggerPolicy
             = new LoggerPolicy(savedStepCount, savedInterval, diskFullAction, maxDiskSpace);
     m_env.DataManager.SetLoggerPolicy(m_env.DataManager.GetCurrentSimulationParameterID(), loggerPolicy);
 }
예제 #6
0
 /// <summary>
 /// Sets the logger policy of the logger.
 /// </summary>
 /// <param name="savedStepCount">the saved step count</param>
 /// <param name="savedInterval">the saved interval</param>
 /// <param name="diskFullAction">the HDD full action</param>
 /// <param name="maxDiskSpace">the max HDD space</param>
 public void SetLoggerPolicy(
     int savedStepCount,
     double savedInterval,
     DiskFullAction diskFullAction,
     int maxDiskSpace)
 {
     LoggerPolicy loggerPolicy
             = new LoggerPolicy(savedStepCount, savedInterval, diskFullAction, maxDiskSpace);
     m_cManager.DataManager.SetLoggerPolicy(this.m_parameterID, loggerPolicy);
 }
예제 #7
0
 /// <summary>
 /// Delates the simulation parameter stub.
 /// </summary>
 public void Delete()
 {
     m_cManager.DataManager.DeleteSimulationParameter(this.m_parameterID);
     this.m_parameterID = null;
     this.m_loggerPolicy = new LoggerPolicy();
     this.m_stepperList = null;
     this.m_initialCondition = null;
 }
예제 #8
0
 /// <summary>
 /// Creates the simulation parameter ID.
 /// </summary>
 public void Create()
 {
     Debug.Assert(!string.IsNullOrEmpty(m_cManager.ModelID));
     //
     // Already get
     //
     if (this.m_stepperList != null)
     {
         return;
     }
     //
     // Searches the simulation parameter.
     //
     bool existFlag = false;
     foreach (string parameterID in m_cManager.GetSimulationParameterIDList())
     {
         if (this.m_parameterID.Equals(parameterID))
         {
             existFlag = true;
             break;
         }
     }
     if (!existFlag)
     {
         m_cManager.DataManager.CreateSimulationParameter(this.m_parameterID);
     }
     //
     // Searches the loaded "Stepper".
     //
     this.m_stepperList
             = m_cManager.DataManager.GetStepper(m_cManager.ModelID);
     //
     // Searches the loaded "LoggerPolicy".
     //
     this.m_loggerPolicy = m_cManager.DataManager.GetLoggerPolicy(this.m_parameterID);
     //
     // Searches the loaded "InitialCondition".
     //
     this.m_initialCondition
             = m_cManager.DataManager.GetInitialCondition(
                     this.m_parameterID, m_cManager.ModelID);
 }
예제 #9
0
        /// <summary>
        /// CreateLogger
        /// </summary>
        /// <param name="fullPathID">The FullPathID to set the logger.</param>
        /// <param name="isInitalize">The flag whether this logger is initialized.</param>
        /// <param name="sim">The current simulator.</param>
        /// <param name="loggerPolicy">The current logger policy.</param>
        private void CreateLogger(string fullPathID, bool isInitalize, WrappedSimulator sim, LoggerPolicy loggerPolicy)
        {
            if (m_loggerEntry.Contains(fullPathID))
                return;

            if (m_currentProject.SimulationStatus == SimulationStatus.Run ||
                m_currentProject.SimulationStatus == SimulationStatus.Suspended ||
                isInitalize)
            {
                sim.CreateLogger(fullPathID,
                    loggerPolicy.ReloadStepCount,
                    loggerPolicy.ReloadInterval,
                    Convert.ToBoolean((int)loggerPolicy.DiskFullAction),
                    loggerPolicy.MaxDiskSpace);
                m_currentProject.LogableEntityPathDic[fullPathID] = m_currentProject.Model.FullID;
            }
            m_loggerEntry.Add(fullPathID);
        }
예제 #10
0
 /// <summary>
 /// Sets the "LoggerPolicy".
 /// </summary>
 /// <param name="parameterID">The parameter ID</param>
 /// <param name="loggerPolicy">The "LoggerPolicy"</param>
 public void SetLoggerPolicy(string parameterID, LoggerPolicy loggerPolicy)
 {
     m_currentProject.LoggerPolicyDic[parameterID] = loggerPolicy;
 }
예제 #11
0
 /// <summary>
 /// Creates the "LoggerPolicy" elements.
 /// </summary>
 /// <param name="loggerPolicy">The "LoggerPolicy"</param>
 private void WriteLoggerPolicyElement(LoggerPolicy loggerPolicy)
 {
     m_tx.WriteStartElement(Constants.xpathLoggerPolicy.ToLower());
     m_tx.WriteElementString(
         Constants.xpathStep.ToLower(),
         null,
         System.Environment.NewLine + loggerPolicy.ReloadStepCount + System.Environment.NewLine
         );
     m_tx.WriteElementString(
         Constants.xpathInterval.ToLower(),
         null,
         System.Environment.NewLine + loggerPolicy.ReloadInterval + System.Environment.NewLine
         );
     m_tx.WriteElementString(
         Constants.xpathAction.ToLower(),
         null,
         System.Environment.NewLine + (loggerPolicy.DiskFullAction == DiskFullAction.Terminate? 0 : 1) + System.Environment.NewLine
         );
     m_tx.WriteElementString(
         Constants.xpathSpace.ToLower(),
         null,
         System.Environment.NewLine + loggerPolicy.MaxDiskSpace + System.Environment.NewLine
         );
     m_tx.WriteEndElement();
 }
예제 #12
0
        public void TestSetLoggerPolicy()
        {
            _unitUnderTest.LoadProject(TestConstant.Project_Drosophila);

            string l_parameterID = null;
            LoggerPolicy l_loggerPolicy = new LoggerPolicy();
            LoggerPolicy expectedl_loggerPolicy = new LoggerPolicy();
            try
            {
                _unitUnderTest.SetLoggerPolicy(l_parameterID, l_loggerPolicy);
                Assert.Fail();
            }
            catch (Exception)
            {
            }
            l_parameterID = "DefaultParameter";
            _unitUnderTest.SetLoggerPolicy(l_parameterID, l_loggerPolicy);
            Assert.IsNotNull(l_loggerPolicy, "l_loggerPolicy ref parameter has unexpected result.");
            Assert.AreNotEqual(expectedl_loggerPolicy, l_loggerPolicy, "l_loggerPolicy ref parameter has unexpected result.");
        }