Exemplo n.º 1
0
        public void Initialize(MyProjectRunner projectRunner)
        {
            try
            {
                projectRunner.OpenProject(BrainFileName, strict: true);

                List <MyNode> brainUnitNodes = projectRunner.Filter(node => (node.GetType().Name == "BrainUnitNode"));
                if (brainUnitNodes.Count != 1)
                {
                    throw new InvalidTestException("Exactly 1 occurrence of BrainUnitNode required.");  // TODO: allow more
                }
                m_brainUnitNode = brainUnitNodes[0];

                PropertyInfo maxStepCountProperty = m_brainUnitNode.GetType().GetProperty("MaxStepCount", typeof(int));
                MaxStepCount = (int)maxStepCountProperty.GetValue(m_brainUnitNode);

                PropertyInfo inspectIntervalProperty = m_brainUnitNode.GetType().GetProperty("InspectInterval", typeof(int));
                InspectInterval = (int)inspectIntervalProperty.GetValue(m_brainUnitNode);

                PropertyInfo expectedToFailProperty = m_brainUnitNode.GetType().GetProperty("ExpectedToFail", typeof(bool));
                ExpectedToFail = (bool)expectedToFailProperty.GetValue(m_brainUnitNode);
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine(
                    "Failed to instantiate test {0}: {1}", Path.GetFileName(BrainFileName), e.Message);
                throw;
            }
        }
        public static void Run(string[] args)
        {
            // -clusterid $(Cluster) -processid $(Process) -brain Breakout.brain -factor 0.5

            int       clusterId             = 0;
            int       processId             = 0;
            double    discountFactor        = 0.6;
            string    breakoutBrainFilePath = "";
            OptionSet options = new OptionSet()
                                .Add("clusterid=", v => clusterId         = Int32.Parse(v))
                                .Add("processid=", v => processId         = Int32.Parse(v))
                                .Add("factor=", v => discountFactor       = Double.Parse(v, CultureInfo.InvariantCulture))
                                .Add("brain=", v => breakoutBrainFilePath = Path.GetFullPath(v));

            try
            {
                options.Parse(Environment.GetCommandLineArgs().Skip(1));
            }
            catch (OptionException e)
            {
                MyLog.ERROR.WriteLine(e.Message);
            }

            MyProjectRunner runner = new MyProjectRunner(MyLogLevel.DEBUG);
            StringBuilder   result = new StringBuilder();

            runner.OpenProject(breakoutBrainFilePath);
            runner.DumpNodes();
            runner.SaveOnStop(23, true);
            for (int i = 0; i < 5; ++i)
            {
                runner.RunAndPause(1000, 100);
                float[] data = runner.GetValues(23, "Bias");
                MyLog.DEBUG.WriteLine(data[0]);
                MyLog.DEBUG.WriteLine(data[1]);
                result.AppendFormat("{0}: {1}, {2}", i, data[0], data[1]);
                runner.Set(23, typeof(MyQLearningTask), "DiscountFactor", discountFactor);
                runner.RunAndPause(1000, 300);
                data = runner.GetValues(23, "Bias");
                MyLog.DEBUG.WriteLine(data[0]);
                MyLog.DEBUG.WriteLine(data[1]);
                result.AppendFormat(" --- {0}, {1}", data[0], data[1]).AppendLine();
                runner.Reset();
            }

            string resultFilePath = @"res." + clusterId.ToString() + "." + processId.ToString() + ".txt";

            File.WriteAllText(resultFilePath, result.ToString());
            string brainzFilePath = @"state." + clusterId.ToString() + "." + processId.ToString() + ".brainz";

            runner.SaveProject(brainzFilePath);

            runner.Shutdown();
            return;
        }
Exemplo n.º 3
0
        private void OpenProject(BrainTest test, MyProjectRunner projectRunner)
        {
            var brainUnitNodeTest = test as BrainUnitNodeTest;

            if (brainUnitNodeTest != null)  // TODO: solve using polymorphism
            {
                brainUnitNodeTest.Initialize(projectRunner);
            }
            else
            {
                projectRunner.OpenProject(FindBrainFile(test));
            }
        }
        public void ReleaseDeserializationTest()
        {
            const string brainPath = @"Data\release-deserialization-test.brain";

            using (var runner = new MyProjectRunner())
            {
                runner.OpenProject(Path.GetFullPath(brainPath));

                // Must not fail.
                runner.RunAndPause(1);

                MyProject project = runner.Project;

                CheckDashboard(project);
            }
        }