Example #1
0
        void TryNextMonth2(Company company, int kind)
        {
            if (decisionsList.Count >= 1) return;

            //var cs = CloneCompanyState(company);
            int i = company.MonthID;
            i++;
            Debug.WriteLine(String.Format("-------------------- MonthID = {0:D}, {1:S}", i, "Real Mode"));
            company.iMonth = i;
            if (kind > -1) company.CreateNewProduct((ProductKind)kind);

            currentDecisions[i] = kind;
            try
            {
                company.NextMonth();
            }
            catch (MyException)
            {
                //result.Balance = 0;
                //iResult = -1;
                return;
            }

            if (i >= nMonthsToRun - 1)
            {
                RecordCurrentDecisions();
                //var result = new Result(nMonthsToRun, cs.Accounting.Balance);
                //result.Balance = cs.Accounting.Balance;
                //result.Balance = company.Accounting.Balance;
                //resultList.Add(result);
                return;
            }
            else
            {
                var snapshot = CompanySaveState(company);

                for (int k = (int)ProductKind.Large; k >= -1; k--)
                {
                    if (k == (int)ProductKind.Classic || k == (int)ProductKind.Free) continue;
                    // Using suggestions
                    int suggestion = GetSuggestion(i);
                    if (suggestion >= -1 && suggestion != k) continue;
                    // Do not create new product at the end of the test period
                    if (nMonthsToRun - i < 6) k = -1;

                    Company cs;
                    if (company == null)
                    {
                        cs = CompanyRestoreState(snapshot);
                    }
                    else
                    {
                        cs = company;
                        company = null;
                    }
                    TryNextMonth2(cs, k);
                }
            }
        }
Example #2
0
        public void Run2()
        {
            Company company = new Company();
            company.SafeMode = false;

            decisionsList = new List<int[]>();
            currentDecisions = new int[nMonthsToRun];
            TryNextMonth2(company, 1);

            var stateSequenceList = new List<Company[]>();
            int iMaxBalance = 0;
            float maxBalance = 0;
            for (int j = 0; j < decisionsList.Count; j++)
            {
                var d = decisionsList[j];
                Company[] stateSequence = new Company[nMonthsToRun];
                Company c = new Company();
                for (int i = 0; i < nMonthsToRun; i++)
                {
                    c.iMonth = i;
                    c.CreateNewProduct((ProductKind)d[i]);
                    c.NextMonth();
                    stateSequence[i] = CompanyRestoreState(CompanySaveState(c));
                }
                if (c.Accounting.Balance > maxBalance)
                {
                    maxBalance = c.Accounting.Balance;
                    iMaxBalance = j;
                }
                stateSequenceList.Add(stateSequence);
            }
            for (int i = 0; i < nMonthsToRun; i++)
            {
                NotifyMonthDone(i, (int)decisionsList[iMaxBalance][i], stateSequenceList[iMaxBalance][i]);
            }
        }