Esempio n. 1
0
        /// <summary>
        /// Rerun jobs after the script is created.
        /// </summary>
        /// <param name="jobid">Job id</param>
        /// <param name="groupName">group name</param>
        /// <param name="topDir">the top directory</param>
        /// <param name="modelName">the model name</param>
        /// <param name="count">simulation time or simulation step.</param>
        /// <param                            name="isStep">the flag use simulation time or simulation step.</param>
        /// <param name="paramDic">the execution parameter.</param>
        public void ReRunSimParameterSet(int jobid, string groupName, string topDir, string modelName,
            double count, bool isStep, ExecuteParameter paramDic)
        {
            Project prj = m_env.DataManager.CurrentProject;
            ScriptWriter writer = new ScriptWriter(prj);
            List<EcellObject> sysList = m_groupDic[groupName].SystemObjectList;
            List<EcellObject> stepperList = m_groupDic[groupName].StepperObjectList;

            string dirName = topDir + "/" + jobid;
            string fileName = topDir + "/" + jobid + ".ess";
            string modelFileName = topDir + "/" + jobid + ".eml";

            //CreateLocalScript(topDir, dirName, fileName, writer,
            //    modelName, count, isStep, sysList, stepperList, paramDic.ParamDic);

            CreateLocalScript(jobid, topDir, dirName, fileName, modelFileName, writer,
                modelName, count, isStep, sysList, stepperList, paramDic.ParamDic);
        }
Esempio n. 2
0
        /// <summary>
        /// Create the execute parameters and get the simulation data at one step.
        /// </summary>
        /// <param name="varList">the variable list.</param>
        /// <param name="proList">the process list.</param>
        private void CreateExecuteParameter(Dictionary<EcellObject, int> varList,
            Dictionary<EcellObject, int> proList)
        {
            DataManager dManager = m_owner.DataManager;
            string tmpDir = m_owner.JobManager.TmpDir;
            double start = 0.0;
            double end = 0.0;
            int jobid = 0;
            List<string> valueList = new List<string>();

            dManager.Initialize(true);
            Dictionary<int, ExecuteParameter> execDict = new Dictionary<int, ExecuteParameter>();
            foreach (EcellObject obj in varList.Keys)
            {
                foreach (EcellData data in obj.Value)
                {
                    if (data.EntityPath.EndsWith(":Value"))
                    {
                        double dV = dManager.GetPropertyValue(data.EntityPath);

                        double pert = dV * m_param.RelativePerturbation + m_param.AbsolutePerturbation;
                        m_pertubateData.Add(data.EntityPath, pert);

                        dV = dV + pert;
                        Dictionary<string, double> tmpDic = new Dictionary<string, double>();
                        tmpDic.Add(data.EntityPath, dV);
                        ExecuteParameter param = new ExecuteParameter(tmpDic);
                        execDict.Add(jobid, param);
                        valueList.Add(data.EntityPath);
                        jobid++;
                    }
                }
            }

            foreach (EcellObject obj in proList.Keys)
            {
                foreach (EcellData data in obj.Value)
                {
                    if (data.EntityPath.EndsWith(":Activity"))
                    {
                        m_saveList.Add(new SaveLoggerProperty(data.EntityPath, start, end, tmpDir));
                    }
                }
            }

            m_activityList.Clear();
            m_valueList.Clear();
            m_valueBuffer.Clear();
            m_activityBuffer.Clear();
            //          dManager.SimulationStartKeepSetting(m_param.Step);
            dManager.StartStepSimulation(m_param.Step, true);
            foreach (SaveLoggerProperty p in m_saveList)
            {
                double dV = dManager.GetPropertyValue(p.FullPath);
                m_currentData.Add(p.FullPath, dV);
                m_activityBuffer.Add(dV);
                m_activityList.Add(p.FullPath);
            }
            foreach (string p in valueList)
            {
                double dV = dManager.GetPropertyValue(p);
                m_valueBuffer.Add(dV);
                m_valueList.Add(p);
            }
            double cTime = dManager.GetCurrentSimulationTime();
            dManager.SimulationStop();

            m_owner.JobManager.SetLoggerData(m_saveList);
            m_group.AnalysisParameter = GetAnalysisProperty();
            m_execParam = m_owner.JobManager.RunSimParameterSet(m_group.GroupName, tmpDir, m_model, cTime, false, execDict);
        }
Esempio n. 3
0
        /// <summary>
        /// Execute the simplex crossover in GA.
        /// </summary>
        private void SimplexCrossOver()
        {
            int M = m_param.Param.M;
            double upsilon = m_param.Param.Upsilon;
            Dictionary<int, ExecuteParameter> crossList = new Dictionary<int, ExecuteParameter>();
            crossList.Add(m_eliteNum, m_execParamList[m_eliteNum]);
            // ---------------------------------------------------------------------
            // [1] Choose m parents Pk (i=1,2,...,m) according to the generational
            //     model used and calculate their center of gravity G, see (5).
            // ---------------------------------------------------------------------
            int paramCount = m_execParamList[m_eliteNum].ParamDic.Count;
            double[] aG = new double[paramCount];
            List<ExecuteParameter> aParentList = new List<ExecuteParameter>();
            for (int i = 0; i < M; i++)
            {
                int r = hRandom.Next(m_param.Population - 1);
                int m = 0;
                foreach (int n in m_execParamList.Keys)
                {
                    if (m == r)
                    {
                        aParentList.Add(m_execParamList[n]);
                        m = 0;
                        foreach (string key in m_execParamList[n].ParamDic.Keys)
                        {
                            aG[m] += m_execParamList[n].ParamDic[key];
                            m++;
                        }
                        break;
                    }
                    m++;
                }
            }
            for (int i = 0; i < paramCount; i++)
            {
                aG[i] = aG[i] / (double)M;
            }

            // ---------------------------------------------------------------------
            // [2] Generate random number rk, see (6)
            // ---------------------------------------------------------------------
            double[] aR = new double[M - 1];
            for (int i = 0; i < M - 1; i++)
            {
                aR[i] = Math.Pow(hRandom.NextDouble(), 1.0 / (double)(i + 1));
            }

            // ---------------------------------------------------------------------
            // [3] Calculate xk, see (7)
            // ---------------------------------------------------------------------
            double[,] aX = new double[M, paramCount];
            for (int i = 0; i < M; i++)
            {
                int k = 0;
                foreach (string key in aParentList[i].ParamDic.Keys)
                {
                    aX[i, k] = aG[k] + upsilon *
                        (aParentList[i].ParamDic[key] - aG[k]);
                    k++;
                }
            }

            // ---------------------------------------------------------------------
            // [4] Calculate Ck, see (8)
            // ---------------------------------------------------------------------
            double[,] aC = new double[M, paramCount];
            for (int i = 0; i < paramCount; i++)
                aC[0, i] = 0.0;
            for (int i = 1; i < M; i++)
            {
                for (int k = 0; k < paramCount; k++)
                {
                    aC[i, k] = aR[i - 1] *
                        (aX[i - 1, k] - aX[i, k] + aC[i - 1, k]);
                }
            }

            // ---------------------------------------------------------------------
            // [5] Generate an offspring C, see (9)
            // ---------------------------------------------------------------------
            int iPos = 0;
            foreach (int pPos in m_execParamList.Keys)
            {
                if (pPos == m_eliteNum) continue;
                double[] aCk = new double[paramCount];
                for (int k = 0; k < paramCount; k++)
                {
                    aCk[k] = aX[iPos, k] + aC[iPos, k];
                }

                ExecuteParameter p = new ExecuteParameter();
                int pos = 0;
                foreach (string key in m_execParamList[m_eliteNum].ParamDic.Keys)
                {
                    p.ParamDic.Add(key, aCk[pos]);
                    foreach (EcellParameterData d in m_paramList)
                    {
                        if (d.Key.Equals(key))
                        {
                            if (d.Max < aCk[pos] || d.Min > aCk[pos])
                            {
                                double maxV = d.Max;
                                double minV = d.Min;
                                double V = (maxV - minV) * hRandom.NextDouble() + minV;
                                p.ParamDic[key] = V;
                            }
                            break;
                        }
                    }
                    pos++;
                }
                crossList.Add(pPos, p);
                iPos++;
                if (iPos >= M) break;
            }

            iPos = 0;
            m_execParamList.Clear();
            foreach (int key in crossList.Keys)
            {
                if (iPos < key) iPos = key;
                m_execParamList.Add(key, crossList[key]);
            }
            iPos++;

            while (m_execParamList.Count < m_param.Population)
            {
                ExecuteParameter p = m_owner.JobManager.CreateExecuteParameter();
                m_execParamList.Add(iPos, p);
                iPos++;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create the job entry when the analysis result is loaded.
        /// </summary>
        /// <param name="groupName">the group name,</param>
        /// <param name="param">the analysis parameter.</param>
        /// <returns>return jobid.</returns>
        public int CreateJobEntry(string groupName, ExecuteParameter param)
        {
            if (m_proxy == null)
                return -1;

            Job job = m_proxy.CreateJob();
            job.GroupName = groupName;
            job.Manager = this;
            job.Status = JobStatus.FINISHED;
            job.ExecParam = param;
            m_groupDic[groupName].Jobs.Add(job);
            OnJobUpdate(JobUpdateType.AddJob);

            return job.JobID;
        }
Esempio n. 5
0
 /// <summary>
 /// Find the elite sample in this generation.
 /// </summary>
 private void FindElite()
 {
     int elite = -1;
     double value = 0.0;
     foreach (int jobid in m_execParamList.Keys)
     {
         double tmp = Judgement(jobid);
         if (elite == -1)
         {
             elite = jobid;
             value = tmp;
             continue;
         }
         if (m_param.Type == EstimationFormulatorType.Max ||
             m_param.Type == EstimationFormulatorType.SumMax)
         {
             if (value < tmp)
             {
                 value = tmp;
                 elite = jobid;
             }
         }
         else if (m_param.Type == EstimationFormulatorType.Min ||
             m_param.Type == EstimationFormulatorType.SumMin)
         {
             if (value > tmp)
             {
                 value = tmp;
                 elite = jobid;
             }
         }
         else if (m_param.Type == EstimationFormulatorType.EqualZero ||
                 m_param.Type == EstimationFormulatorType.SumEqualZero)
         {
             if (value > Math.Abs(tmp))
             {
                 value = Math.Abs(tmp);
                 elite = jobid;
             }
         }
     }
     m_estimation.Add(m_generation, value);
     m_elite = m_execParamList[elite];
     m_eliteNum = elite;
 }
Esempio n. 6
0
 /// <summary>
 /// Load the analysis result file.
 /// </summary>
 /// <param name="resultFile">the result file.</param>
 private void LoadAnalysisResultFile(string resultFile)
 {
     int pos = 0;
     string line;
     string[] ele;
     StreamReader reader;
     Dictionary<string, double> param = new Dictionary<string, double>();
     reader = new StreamReader(resultFile, Encoding.ASCII);
     while ((line = reader.ReadLine()) != null)
     {
         if (line.StartsWith("#")) continue;
         if (line.Length <= 1)
         {
             pos++;
             continue;
         }
         ele = line.Split(new char[] { ',' });
         if (pos == 0)
         {
             int g = Int32.Parse(ele[0]);
             double d = double.Parse(ele[1]);
             m_estimation[g] = d;
         }
         else if (pos == 1)
         {
             string path = ele[0];
             double d = double.Parse(ele[1]);
             param[path] = d;
         }
     }
     m_elite = new ExecuteParameter(param);
     m_isExistResult = true;
     reader.Close();
 }
        /// <summary>
        /// Set the estimated parameter.
        /// </summary>
        /// <param name="param">the execution parameter.</param>
        /// <param name="result">the estimated value.</param>
        /// <param name="generation">the generation.</param>
        public void AddEstimateParameter(ExecuteParameter param, double result, int generation)
        {
            dataGridView1.Rows.Clear();
            foreach (string key in param.ParamDic.Keys)
            {
                DataGridViewRow r = new DataGridViewRow();

                DataGridViewTextBoxCell c1 = new DataGridViewTextBoxCell();
                c1.Value = Convert.ToString(key);
                r.Cells.Add(c1);

                DataGridViewTextBoxCell c2 = new DataGridViewTextBoxCell();
                c2.Value = Convert.ToString(param.ParamDic[key]);
                r.Cells.Add(c2);

                dataGridView1.Rows.Add(r);
            }
            textBox2.Text = Convert.ToString(result);
            textBox1.Text = Convert.ToString(generation);
        }
Esempio n. 8
0
 /// <summary>
 /// Set the estimated parameter.
 /// </summary>
 /// <param name="param">the execution parameter.</param>
 /// <param name="result">the estimated value.</param>
 /// <param name="generation">the generation.</param>
 public void AddEstimateParameter(ExecuteParameter param, double result, int generation)
 {
     if (m_rWin != null)
     {
         m_rWin.AddEstimateParameter(param, result, generation);
     }
 }
Esempio n. 9
0
 public void TestConstructorExecuteParameter()
 {
     ExecuteParameter testExecuteParameter = new ExecuteParameter();
     Assert.IsNotNull(testExecuteParameter, "Constructor of type, ExecuteParameter failed to create instance.");
     Assert.IsNotNull(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");
     Assert.IsEmpty(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");
 }
Esempio n. 10
0
        public void TestConstructorExecuteParameterData()
        {
            Dictionary<string, double> data = new Dictionary<string,double>();
            ExecuteParameter testExecuteParameter = new ExecuteParameter(data);
            Assert.IsNotNull(testExecuteParameter, "Constructor of type, ExecuteParameter failed to create instance.");
            Assert.IsNotNull(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");
            Assert.IsEmpty(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");

            data.Add("Variable:/:S:Value", 0.0);
            testExecuteParameter = new ExecuteParameter(data);
            Assert.IsNotNull(testExecuteParameter, "Constructor of type, ExecuteParameter failed to create instance.");
            Assert.IsNotNull(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");
            Assert.IsNotEmpty(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");

            testExecuteParameter = new ExecuteParameter();
            testExecuteParameter.ParamDic = data;
            Assert.IsNotNull(testExecuteParameter, "Constructor of type, ExecuteParameter failed to create instance.");
            Assert.IsNotNull(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");
            Assert.IsNotEmpty(testExecuteParameter.ParamDic, "ParamDic is unexpected value.");
        }
Esempio n. 11
0
 public void TearDown()
 {
     _unitUnderTest = null;
 }
Esempio n. 12
0
 public void SetUp()
 {
     _unitUnderTest = new ExecuteParameter();
 }
Esempio n. 13
0
        public void TestRunSimParameterSet()
        {
            _env.DataManager.LoadProject(TestConstant.Project_Drosophila);
            LocalJob.ClearJobID();
            string topDir = TestConstant.TestDirectory + "TestJob1";
            string analysisName = "AAAAAA";
            string modelName = "Drosophila";
            double count = 10;
            bool isStep = false;

            Dictionary<int, ExecuteParameter> setparam = new Dictionary<int, ExecuteParameter>();
            Dictionary<string, double> data = new Dictionary<string, double>();
            data.Add("Variable:/CELL/CYTOPLASM:P0:Value", 0.0);
            data.Add("System:/CELL:CYTOPLASM:Size", 1e-10);
            ExecuteParameter param = new ExecuteParameter(data);
            setparam.Add(0, param);

            JobGroup g = _unitUnderTest.CreateJobGroup(analysisName,
                _env.DataManager.CurrentProject.SystemDic[modelName],
                _env.DataManager.CurrentProject.StepperDic[modelName]);
            Dictionary<int, ExecuteParameter> expectedDictionary = new Dictionary<int, ExecuteParameter>();
            Dictionary<int, ExecuteParameter> resultDictionary = new Dictionary<int, ExecuteParameter>();
            resultDictionary = _unitUnderTest.RunSimParameterSet(g.GroupName, topDir, modelName, count, isStep, setparam);
            Assert.IsNotEmpty(resultDictionary, "RunSimParameterSet method returned unexpected result.");
            //
            SetLoggerData();
            isStep = true;
            resultDictionary = _unitUnderTest.RunSimParameterSet(g.GroupName, topDir, modelName, count, isStep, setparam);
            Assert.IsNotEmpty(resultDictionary, "RunSimParameterSet method returned unexpected result.");

            _unitUnderTest.GetJobDirectory(g.GroupName, 1);
            _unitUnderTest.GetStdout(g.GroupName, 1);
            _unitUnderTest.GetStderr(g.GroupName, 1);
            _unitUnderTest.GetSessionProxy(g.GroupName, 1);
            _unitUnderTest.GetSessionProxy(g.GroupName, -1);
            _unitUnderTest.Stop(g.GroupName, 0);

            if (Directory.Exists(topDir))
                Directory.Delete(topDir, true);
        }
Esempio n. 14
0
        public void TestCreateJobEntry()
        {
            JobManager manager = new JobManager(_env);
            LocalJob.ClearJobID();

            ExecuteParameter param = new ExecuteParameter();
            int expectedInt32 = 1;
            int resultInt32 = 0;

            JobGroup g = manager.CreateJobGroup("AAAA", new List<EcellObject>(), new List<Ecell.Objects.EcellObject>());
            resultInt32 = manager.CreateJobEntry(g.GroupName, param);
            Assert.AreEqual(expectedInt32, resultInt32, "CreateJobEntry method returned unexpected result.");

            manager.Proxy = null;
            expectedInt32 = -1;
            resultInt32 = manager.CreateJobEntry(g.GroupName, param);
            Assert.AreEqual(expectedInt32, resultInt32, "CreateJobEntry method returned unexpected result.");
        }
Esempio n. 15
0
 /// <summary>
 /// Set the estimated parameter.
 /// </summary>
 /// <param name="param">the execution parameter.</param>
 /// <param name="result">the estimated value.</param>
 /// <param name="generation">the generation.</param>
 public void AddEstimateParameter(ExecuteParameter param, double result, int generation)
 {
     m_paramResultWindow.AddEstimateParameter(param, result, generation);
 }