Ejemplo n.º 1
0
        /// <summary>
        /// Write an internal error to the log. Also prints stack trace along with the message
        /// </summary>
        /// <param name="msg">the message to write to the log</param>
        public void WriteExceptionToLog(String msg)
        {
            WriteToLog("ERROR: " + msg + OSEnvironment.getStackTrace(), true);

            //Product #178, Topic #61: beep on the client side only upon user errors (e.g. duplicate record), otherwise only if started from the studio (F7)
            if (ShouldBeep)
            {
                SoundBeep();
            }
        }
Ejemplo n.º 2
0
        /// <summary>Get temp folder on the system</summary>
        /// <returns></returns>
        private static String GetEnvTempFolder()
        {
            String tempFolder;

#if !PocketPC
            tempFolder = OSEnvironment.get("TEMP");
#else
            tempFolder = OSEnvironment.getTempFolder();
#endif
            return(tempFolder);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   CTOR
        /// </summary>
        private EnvControlsPersistencyPath()
        {
#if PocketPC
            _defaultPath = OSEnvironment.getAssemblyFolder();
#else
            //1.	If the path is not defined (default) then the files will be created in the (same folder as the form state persistency file.)
            //•	In xp: C:\Documents and Settings\<user>\Application Data\MSE\<APP GUI ID>\
            //•	In Win 7 and Win 8:  C:\Users\<user>\AppData\Roaming\MSE\<APP GUI ID>
            _defaultPath = OSEnvironment.get("APPDATA")
                           + Path.DirectorySeparatorChar
                           + (UtilStrByteMode.isLocaleDefLangJPN()
                          ? "MSJ"
                          : "MSE")
                           + Path.DirectorySeparatorChar;
#endif
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   CTOR
        /// </summary>
        private FormUserState()
        {
            IsDisabled = false;

#if PocketPC
            _dirPath = OSEnvironment.getAssemblyFolder();
#else
            _dirPath = OSEnvironment.get("APPDATA")
                       + Path.DirectorySeparatorChar
                       + (UtilStrByteMode.isLocaleDefLangJPN()
                          ? "MSJ"
                          : "MSE")
                       + Path.DirectorySeparatorChar
                       + Manager.Environment.GetGUID()
                       + Path.DirectorySeparatorChar;
#endif
        }
Ejemplo n.º 5
0
        /// <summary>Initialize StudioLauncher error log --> %TEMP%\RCLauncherError.log</summary>
        private void InitLogWriter()
        {
            String logTarget = OSEnvironment.get("TEMP") + @"\RCLauncherError.log";

            try
            {
                _logWriter = new StreamWriter(new FileStream(logTarget, FileMode.Append, FileAccess.Write, FileShare.Read));
            }
            catch (IOException)
            {
                // if the log file is in use, insert the current process ID into the name: *.pid.suffix
                logTarget = logTarget.Insert(logTarget.LastIndexOf('.'), "." + System.Diagnostics.Process.GetCurrentProcess().Id.ToString());
                try
                {
                    _logWriter = new StreamWriter(new FileStream(logTarget, FileMode.Append, FileAccess.Write, FileShare.Read));
                }
                catch { }
            }
            catch { }
            if (_logWriter != null)
            {
                _logWriter.AutoFlush = true;
            }
        }
Ejemplo n.º 6
0
        static void DoExperiment(
            int EXP_ID,
            string algoStr,
            string netStr,
            int size,
            double h_trg,
            int expd,
            int envSeed,    //環境のシード
            int linkNum,
            double cluster, //クラスタ係数
            string dirname
            )
        {
            //ディレクトリを作成
            L.gDirectory(dirname);

            //出力するファイルを宣言
            L.gDefine("roundacc,aveacc");

            //条件を表示
            {
                L.g("all").WriteLine("");
                L.g("all").Write("envSeed: " + envSeed);
                L.g("all").Write(" EXP_ID: " + EXP_ID); //実験IDを
                L.g("all").Write(" Algo: " + algoStr);  //アルゴリズムの名前を表示
                L.g("all").Write(" agentnum: " + size);
                L.g("all").Write(" linkNum: " + linkNum);
                L.g("all").Write(" cluster: " + cluster);//クラスタ係数
                L.g("all").Write(" h_trg: " + h_trg);
                L.g("all").Write(" expd: " + expd);

                L.g("roundacc").WriteLine("");
            }


            {                                               //実験一回し
                Experiment exp = new Experiment(150, 2000); //150ラウンド,2000ステップの実験

                exp.SetEnvsetSeed(envSeed);
                exp.SetFactSeed(0);

                NetworkGenerator generator = null;
                //環境を作る
                if (netStr == "WS")
                {
                    generator = new WSmodelNetworkGenerator(size, expd, 0.12);
                }
                else if (netStr == "BA")
                {
                    generator = new BAModelNetworkGenerator(size, 4, 2);
                }
                else if (netStr == "Random")
                {
                    generator = new RandomNetworkGenerator(size, 16);
                }
                //リーダーネットワークの導入 2014_0707追加
                else if (netStr == "Leader")
                {
                    generator = new LeaderNetworkGenerator(size, expd, 0.12, linkNum);
                }


                //シェルを作る
                generator.NodeCreate += () => new AgentIO();

                //generateしてくれる。
                OSEnvironment env = new OSEnvironment(generator, (int)(size * 0.05));

                //エージェントに脳みそをいれてやる
                foreach (AgentIO agentIO in env.Network.Nodes)
                {
                    agentIO.Algorithm = (AlgorithmFactory.CreateAlgorithm(algoStr, h_trg));
                }


                //ファイルにネットワークの情報を表示
                L.g("env").WriteLine("" + env);
                L.g("env").Flush();

                exp.Environment = env;

                //実験を実行
                var expResult = exp.Run();
            }



            //ファイルに書き込み
            L.Flush();
        }
Ejemplo n.º 7
0
        static void AutoExperiment()
        {
            //ディレクトリを作成
            L.gDirectory(DateTime.Now.ToString("yyyyMMdd_HHmmss"));
            L.gDefine("stepbelief,roundacc,aveacc,time,env");

            //集団規模のリスト

            //int[] sizeList = { 100, 250, 500, 750, 1000, 1500, 2000, 2500 };
            int[] sizeList = { 100, 1000 };

            //h_trgの種類
            double[] h_trgList = { 0.9, 0.94, 0.98, 1.0 };

            //expected d <d>
            double[] expdList = { 4, 6, 8, 10, 12 };


            //シードの種類の個数
            int envSeedNum = 10;

            var envSeedList = Enumerable.Range(0, envSeedNum);

            NodeCreaterCreater AATCC               = (double h_trg) => (() => new AAT(h_trg));
            NodeCreaterCreater DontReplyCC         = (double h_trg) => (() => new DontReply(h_trg));
            NodeCreaterCreater NoMoreBeliefCC      = (double h_trg) => (() => new NoMoreBelief(h_trg));
            NodeCreaterCreater EatingWordsCC       = (double h_trg) => (() => new EatingWords(h_trg));
            NodeCreaterCreater BelieveOnlySensorCC = (double h_trg) => (() => new BelieveOnlySensor(h_trg));

            Dictionary <string, NodeCreaterCreater> creatorList = new Dictionary <string, NodeCreaterCreater> {
                //{"AAT", AATCC },
                { "NewDontReply", DontReplyCC },
                //{"NoMoreBelief", NoMoreBeliefCC },
                //{"BelieveOnlySensor", BelieveOnlySensorCC},
                //{"EatingWords", EatingWordsCC },
            };


            //**************実験条件を表示***************
            {
                var logAll = L.g("all");
                logAll.WriteLine("////////////////////experimental condition ////////////////////");

                var    dt       = DateTime.Now;
                string routeDir = dt.ToString("yyyy/MM/dd HH:mm:ss\n");
                logAll.WriteLine("Date: " + routeDir);

                logAll.WriteLine("AgentNum");
                foreach (int size in sizeList)
                {
                    logAll.Write(size + ", ");
                }
                logAll.WriteLine("\n");

                logAll.WriteLine("h_trg");
                foreach (double h_trg in h_trgList)
                {
                    logAll.Write(h_trg + ", ");
                }
                logAll.WriteLine("\n");

                logAll.WriteLine("expd");
                foreach (int expd in expdList)
                {
                    logAll.Write(expd + ", ");
                }
                logAll.WriteLine("\n");


                logAll.WriteLine("algorithm");
                foreach (string creatorName in creatorList.Keys)
                {
                    logAll.Write(creatorName + ", ");
                }
                logAll.WriteLine("\n");

                logAll.WriteLine("envSeedNum: " + envSeedNum);
                logAll.WriteLine("\n");
            }


            //じっけんID
            int EXP_ID = 0;

            //時間をはかるよ
            DateTime prevTime  = DateTime.Now;
            DateTime startTime = DateTime.Now;


            //それぞれのアルゴリズムについて
            foreach (var creator in creatorList)
            {
                //それぞれのサイズについて
                foreach (int size in sizeList)
                {
                    //それぞれのh_trgについて
                    foreach (double h_trg in h_trgList)
                    {
                        //それぞれのdについて
                        foreach (int expd in expdList)
                        {
                            //条件を表示
                            {
                                L.g("all").WriteLine("");
                                L.g("all").Write(string.Format("EXP_ID: {0}", EXP_ID++)); //実験IDを
                                L.g("all").Write(" Algo: " + creator.Key);                //アルゴリズムの名前を表示

                                L.g("all").Write(" agentnum: " + size);
                                L.g("all").Write(" h_trg: " + h_trg);
                                L.g("all").Write(" expd: " + expd);
                                L.g("all").Write(" envSdN: " + envSeedNum);

                                L.g("all").WriteLine("");
                            }


                            //シードの平均をとるため
                            double[] aveSeedResult = new double[3];

                            foreach (int envSeed in envSeedList)//環境のシード
                            {
                                L.g("roundacc,time,console,stepbelief").Write("\nenvSeed: " + envSeed + " ");

                                RandomPool.Declare("setenv", envSeed);

                                {                                  //実験一回し
                                    RandomPool.Declare("fact", 0); //固定センサー値までばらつかせたら収集がつかんことを学習した。

                                    //環境を作る
                                    NetworkGenerator generator = new SmallworldRingNetworkGenerator(size, expd, 0.12);

                                    generator.NodeCreate += creator.Value(h_trg);

                                    OSEnvironment env = new OSEnvironment(generator, (int)(size * 0.05));

                                    //ファイルにネットワークの情報を表示
                                    L.g("env").WriteLine("" + env);
                                    L.g("env").Flush();

                                    Experiment exp = new Experiment(env);

                                    //実験を実行
                                    var expResult = exp.Run();

                                    {    //平均をとるために和を計算
                                        aveSeedResult[0] += expResult.Correct;
                                        aveSeedResult[1] += expResult.Incorrect;
                                        aveSeedResult[2] += expResult.Undeter;
                                    }
                                }

                                {     //時間を表示
                                    DateTime nowTime   = DateTime.Now;
                                    TimeSpan tp        = nowTime.Subtract(prevTime);
                                    TimeSpan fromStart = nowTime.Subtract(startTime);
                                    L.g("time,console").Write("<span: " + tp);                         // 処理時間を秒単位で表示
                                    L.g("time,console").WriteLine("  fromStart: " + fromStart + " >"); // 処理時間を秒単位で表示

                                    prevTime = nowTime;
                                }
                            }//forenvseed


                            { //平均をとる
                                aveSeedResult[0] /= envSeedNum;
                                aveSeedResult[1] /= envSeedNum;
                                aveSeedResult[2] /= envSeedNum;
                            }

                            L.g("aveacc,console").WriteLine(
                                string.Format("SeedAverage: correct: {0} incorrect: {1} undeter: {2}",
                                              aveSeedResult[0], aveSeedResult[1], aveSeedResult[2]));

                            //ファイルに書き込み
                            L.Flush();
                        } //for expd
                    }     //for h_trg
                }         //for size
            }             //
        }                 //method AutoExperiment
Ejemplo n.º 8
0
        private void initEnv(string generatorstr, int agentNum, int sensorNum, int expectedDegree, double pRewire, int seed)
        {
            StopAnimation();


            GeneratorCB.SelectedItem = generatorstr;
            AgentNumTB.Text          = agentNum.ToString();
            SensorNumTB.Text         = sensorNum.ToString();
            ExpectedDegreeTB.Text    = expectedDegree.ToString();
            PRewireTB.Text           = pRewire.ToString();
            SeedTB.Text = seed.ToString();

            //環境つくるためのシードをセット これは環境つくるためのメソッドなのでOK.
            exp.SetEnvsetSeed(seed);

            //新しいネットワークジェネレータで
            //NetworkGenerator generator = new WSmodelNetworkGenerator(agentNum, expectedDegree, pRewire);

            NetworkGenerator generator = new WSmodelNetworkGenerator(agentNum, expectedDegree, pRewire);

            if (generatorstr == "WS")
            {
                generator = new WSmodelNetworkGenerator(agentNum, expectedDegree, pRewire);
            }
            else if (generatorstr == "BA")
            {
                generator = new BAModelNetworkGenerator(agentNum, 10, expectedDegree);//, pRewire);
            }
            else if (generatorstr == "Random")
            {
                generator = new RandomNetworkGenerator(agentNum, expectedDegree);//, pRewire);
            }

            else if (generatorstr == "Leader")
            {
                generator = new LeaderNetworkGenerator(agentNum, expectedDegree, pRewire, 99);//, pRewire);
            }



            generator.NodeCreate += () => new AgentIO();

            //新たな環境を構築
            env = new OSEnvironment(generator, sensorNum);



            exp.Environment = env;

            //figurePanelネットワークのオブザーバ(まだ不完全)に環境を追加
            figurePanel.Environment = env;

            //エージェントのビューも更新
            figurePanel.calcAgentViews();

            //エージェント表示モジュールは状態表示モジュールを参照(選択の情報を受け渡す)
            figurePanel.AgentStatePanel = agentStatePanel;

            //ファイルにネットワークの情報を表示
            L.g("env").WriteLine("" + env);
            L.g("env").Flush();
        }