示例#1
0
        private void InitHouses()
        {
            RealEstatePortfolio = new RealEstatePortfolio();

            var random = new Random(42);

            for (var i = 0; i < InitialNumberOfHouses; i++)
            {
                var sustainability             = (int)(random.NextDouble() * 60) + 20;
                var monthlyRent                = 310.0 + random.NextDouble() * 180.0 + sustainability * 2;  // A typical rent is typically approximate 70% of the market rent.
                var monthlyMarketRent          = monthlyRent + random.NextDouble() * 180 + sustainability * 3;
                var monthlyMaintenanceExpenses = 200.0 + random.NextDouble() * 300.0;
                var value = 100000.0 + random.NextDouble() * 50000.0 + sustainability * 1000.0;
                var mutationProbability = 0.10;
                var lifeSpan            = (int)(random.NextDouble() * 50);

                RealEstatePortfolio.AddNewHouse(this, monthlyRent, monthlyMarketRent, monthlyMaintenanceExpenses, value, mutationProbability, lifeSpan, sustainability);
            }
        }
示例#2
0
        public void EndOfYear()
        {
            var expensesHouses = RealEstatePortfolio.EndOfYear();
            var earningsSales  = SellHouses();

            foreach (var newDevelopmentProjectType in NewDevelopmentProjectType.GetAll())
            {
                newDevelopmentProjectType.EndOfYear();
            }

            var expensesNewDevelopment = ExecuteNewDevelopmentProjects();

            foreach (var renovationProjectProjectType in RenovationProjectType.GetAll())
            {
                renovationProjectProjectType.EndOfYear();
            }

            var expensesRenovation = ExecuteRenovations();

            var expensesLoans = _loanPortfolio.EndOfYear();

            // If we have spent money we need to attract a new loan.
            var totalExpenses = expensesLoans + expensesHouses + AnnualCosts - _loanPortfolio.Cash - earningsSales + expensesNewDevelopment + expensesRenovation;

            if (totalExpenses > 0)
            {
                var previousDebt = _loanPortfolio.Debt;
                AttractLoan(totalExpenses);
                _loanPortfolio.Cash = 0;

                // Assert that a loan really has been attracted.
                Debug.Assert(Math.Abs(previousDebt + totalExpenses - _loanPortfolio.Debt) < 0.01);
            }
            else
            {
                _loanPortfolio.Cash = -totalExpenses;
            }

            CumulativeInflation *= Economy.Get(Series.PriceInflation) + 1;

            IsBankrupt |= SolvencyRatio < BankruptcyThreshold;
        }
示例#3
0
        private double SellHouses()
        {
            var gain = 0.0;

            foreach (var house in RealEstatePortfolio.Houses.ToList())
            {
                if (Policy.DetermineSell(house))
                {
                    if (house.CurrentTenantLeaves)
                    {
                        gain += house.MarketValue;
                    }
                    else
                    {
                        gain += house.MarketValue * 0.7;
                    }
                    RealEstatePortfolio.RemoveHouse(house);
                }
            }
            return(gain);
        }