Exemplo n.º 1
0
        }     //end

        public void fillsimulationtable()
        {
            Random rand_num = new Random();

            for (int i = 0; i < this.NumOfRecords; i++)
            {
                SimulationCase obj = new SimulationCase();
                obj.DayNo             = i + 1;
                obj.RandomNewsDayType = int.Parse(rand_num.Next(1, 100).ToString());
                obj.NewsDayType       = gettypeofnewsdays(obj.RandomNewsDayType);
                obj.RandomDemand      = int.Parse(rand_num.Next(1, 100).ToString());
                obj.Demand            = getdemand(obj.RandomDemand, obj.NewsDayType);
                if (obj.Demand == 0)
                {
                    obj.Demand = 100;
                }
                obj.DailyCost   = this.NumOfNewspapers * this.PurchasePrice;
                obj.LostProfit  = 0;
                obj.ScrapProfit = 0;
                if (obj.Demand > this.NumOfNewspapers)
                {
                    obj.LostProfit  = (obj.Demand - this.NumOfNewspapers) * this.UnitProfit;
                    obj.SalesProfit = this.NumOfNewspapers * SellingPrice;
                }
                else if (obj.Demand <= this.NumOfNewspapers)
                {
                    obj.ScrapProfit = (this.NumOfNewspapers - obj.Demand) * this.ScrapPrice;
                    obj.SalesProfit = obj.Demand * SellingPrice;
                }
                obj.DailyNetProfit = obj.SalesProfit - obj.DailyCost - obj.LostProfit + obj.ScrapProfit;
                this.SimulationCases.Add(obj);
            } //endforloop
        }     //end
Exemplo n.º 2
0
        public void Calculate_SimulationTable(ref SimulationSystem s)
        {
            s.PerformanceMeasures.TotalSalesProfit     = 0;
            s.PerformanceMeasures.TotalLostProfit      = 0;
            s.PerformanceMeasures.TotalScrapProfit     = 0;
            s.PerformanceMeasures.TotalNetProfit       = 0;
            s.PerformanceMeasures.DaysWithUnsoldPapers = 0;
            s.PerformanceMeasures.DaysWithMoreDemand   = 0;
            s.PerformanceMeasures.TotalCost            = s.NumOfRecords * s.NumOfNewspapers * s.PurchasePrice;
            s.UnitProfit = s.SellingPrice - s.PurchasePrice;
            int index = 0;

            for (int i = 0; i < s.NumOfRecords; i++)
            {
                SimulationCase SC = new SimulationCase();
                SC.DayNo             = i + 1;
                SC.DailyCost         = s.NumOfNewspapers * s.PurchasePrice;
                SC.RandomNewsDayType = rnd.Next(1, 100);
                for (int j = 0; j < s.DayTypeDistributions.Count; j++)
                {
                    if (SC.RandomNewsDayType >= s.DayTypeDistributions[j].MinRange && SC.RandomNewsDayType <= s.DayTypeDistributions[j].MaxRange)
                    {
                        SC.NewsDayType = s.DayTypeDistributions[j].DayType;
                    }
                }
                SC.RandomDemand = rnd.Next(1, 100);
                index           = (int)SC.NewsDayType;
                for (int j = 0; j < s.DemandDistributions.Count; j++)
                {
                    if (SC.RandomDemand >= s.DemandDistributions[j].DayTypeDistributions[index].MinRange && SC.RandomDemand <= s.DemandDistributions[j].DayTypeDistributions[index].MaxRange)
                    {
                        SC.Demand = s.DemandDistributions[j].Demand;
                    }
                }

                if (SC.Demand > s.NumOfNewspapers)
                {
                    SC.SalesProfit = s.SellingPrice * s.NumOfNewspapers;
                    SC.LostProfit  = (SC.Demand - s.NumOfNewspapers) * s.UnitProfit;
                    SC.ScrapProfit = 0;
                    s.PerformanceMeasures.DaysWithMoreDemand += 1;
                }
                else
                {
                    SC.SalesProfit = s.SellingPrice * SC.Demand;
                    SC.LostProfit  = 0;
                    SC.ScrapProfit = (s.NumOfNewspapers - SC.Demand) * s.ScrapPrice;
                }
                if (SC.Demand < s.NumOfNewspapers)
                {
                    s.PerformanceMeasures.DaysWithUnsoldPapers += 1;
                }
                SC.DailyNetProfit = SC.SalesProfit - SC.DailyCost - SC.LostProfit + SC.ScrapProfit;
                s.PerformanceMeasures.TotalSalesProfit += SC.SalesProfit;
                s.PerformanceMeasures.TotalLostProfit  += SC.LostProfit;
                s.PerformanceMeasures.TotalScrapProfit += SC.ScrapProfit;
                s.PerformanceMeasures.TotalNetProfit   += SC.DailyNetProfit;
                s.SimulationTable.Add(SC);
            }
        }
        public void BuildSimulationTable()
        {
            var rand = new Random();

            for (int i = 0; i < NumOfRecords; i++)
            {
                var simulationCase = new SimulationCase
                {
                    DayNo             = i + 1,
                    RandomNewsDayType = rand.Next(1, 101),
                    RandomDemand      = rand.Next(1, 101)
                };

                simulationCase.NewsDayType = GetDayType(simulationCase.RandomNewsDayType);
                simulationCase.Demand      = GetDemand(simulationCase.RandomDemand, simulationCase.NewsDayType);
                simulationCase.DailyCost   = NumOfNewspapers * PurchasePrice;
                simulationCase.SalesProfit = Math.Min(NumOfNewspapers, simulationCase.Demand) * SellingPrice;
                var diffrence = simulationCase.Demand - NumOfNewspapers;
                simulationCase.LostProfit     = ((diffrence > 0) ? diffrence * UnitProfit : 0);
                simulationCase.ScrapProfit    = ((diffrence < 0) ? Math.Abs(diffrence) * ScrapPrice : 0);
                simulationCase.DailyNetProfit = simulationCase.SalesProfit - simulationCase.DailyCost - simulationCase.LostProfit + simulationCase.ScrapProfit;

                SimulationTable.Add(simulationCase);
            }
        }
        public void simulate(string fnam)
        {
            readfile(fnam);
            Random day    = new Random();
            Random demand = new Random();

            for (int i = 1; i <= NumOfRecords; i++)
            {
                SimulationCase sc = new SimulationCase();
                sc.DayNo             = i;
                sc.RandomNewsDayType = day.Next(1, 100);
                for (int h = 0; h < DayTypeDistributions.Count; h++)
                {
                    if (DayTypeDistributions[h].MinRange <= sc.RandomNewsDayType && DayTypeDistributions[h].MaxRange >= sc.RandomNewsDayType)
                    {
                        sc.NewsDayType = DayTypeDistributions[h].DayType;
                        break;
                    }
                }
                sc.RandomDemand = demand.Next(1, 100);
                sc.Demand       = get_demand(sc.RandomDemand, sc.NewsDayType);
                sc.DailyCost    = NumOfNewspapers * PurchasePrice;
                sc.SalesProfit  = Math.Min(sc.Demand, NumOfNewspapers) * SellingPrice;

                if (sc.Demand < NumOfNewspapers)
                {
                    sc.ScrapProfit    = (NumOfNewspapers - sc.Demand) * ScrapPrice;
                    sc.DailyNetProfit = sc.SalesProfit + sc.ScrapProfit - sc.DailyCost;
                }
                else if (sc.Demand > NumOfNewspapers)
                {
                    sc.LostProfit     = (sc.Demand - NumOfNewspapers) * UnitProfit;
                    sc.DailyNetProfit = sc.SalesProfit - sc.LostProfit - sc.DailyCost;
                }
                else
                {
                    sc.DailyNetProfit = sc.SalesProfit - sc.DailyCost;
                }

                if (sc.ScrapProfit != 0)
                {
                    PerformanceMeasures.DaysWithUnsoldPapers += 1;
                }
                if (sc.LostProfit != 0)
                {
                    PerformanceMeasures.DaysWithMoreDemand += 1;
                }
                PerformanceMeasures.TotalLostProfit  += sc.LostProfit;
                PerformanceMeasures.TotalScrapProfit += sc.ScrapProfit;
                PerformanceMeasures.TotalCost        += sc.DailyCost;
                PerformanceMeasures.TotalNetProfit   += sc.DailyNetProfit;
                PerformanceMeasures.TotalSalesProfit += sc.SalesProfit;

                SimulationTable.Add(sc);
            }
        }
        public void Simulate()
        {
            PerformanceMeasures.DaysWithMoreDemand   = 0;
            PerformanceMeasures.DaysWithUnsoldPapers = 0;
            PerformanceMeasures.TotalCost            = 0;
            PerformanceMeasures.TotalLostProfit      = 0;
            PerformanceMeasures.TotalNetProfit       = 0;
            PerformanceMeasures.TotalSalesProfit     = 0;
            PerformanceMeasures.TotalScrapProfit     = 0;

            for (int i = 1; i <= NumOfRecords; i++)
            {
                SimulationCase sc = new SimulationCase();
                sc.DayNo = i;

                sc.RandomNewsDayType = rnd.Next(1, 101);
                foreach (DayTypeDistribution DTD in DayTypeDistributions)
                {
                    if (sc.RandomNewsDayType >= DTD.MinRange && sc.RandomNewsDayType <= DTD.MaxRange)
                    {
                        sc.NewsDayType = DTD.DayType;
                    }
                }

                sc.RandomDemand = rnd.Next(1, 101);
                foreach (DemandDistribution DD in DemandDistributions)
                {
                    if (sc.RandomDemand >= DD.DayTypeDistributions[(int)sc.NewsDayType].MinRange && sc.RandomDemand <= DD.DayTypeDistributions[(int)sc.NewsDayType].MaxRange)
                    {
                        sc.Demand = DD.Demand;
                    }
                }

                sc.SalesProfit = Math.Min(NumOfNewspapers, sc.Demand) * SellingPrice;
                PerformanceMeasures.TotalSalesProfit += sc.SalesProfit;

                sc.ScrapProfit = Math.Max(0, NumOfNewspapers - sc.Demand) * ScrapPrice;
                PerformanceMeasures.TotalScrapProfit     += sc.ScrapProfit;
                PerformanceMeasures.DaysWithUnsoldPapers += (sc.ScrapProfit > 0)? 1: 0;

                sc.LostProfit = Math.Max(0, sc.Demand - NumOfNewspapers) * UnitProfit;
                PerformanceMeasures.TotalLostProfit    += sc.LostProfit;
                PerformanceMeasures.DaysWithMoreDemand += (sc.LostProfit > 0) ? 1 : 0;

                sc.DailyCost = NumOfNewspapers * PurchasePrice;
                PerformanceMeasures.TotalCost += sc.DailyCost;

                sc.DailyNetProfit = sc.SalesProfit - sc.DailyCost - sc.LostProfit + sc.ScrapProfit;
                PerformanceMeasures.TotalNetProfit += sc.DailyNetProfit;

                SimulationTable.Add(sc);
            }
        }
 public void fillSimulationTable()
 {
     for (int i = 1; i <= NumOfRecords; i++)
     {
         SimulationCase tempCase = new SimulationCase();
         tempCase.DayNo = i;
         tempCase.setNewsDayType(DayTypeDistributions);
         tempCase.setDemand(DemandDistributions);
         tempCase.fill(NumOfNewspapers, PurchasePrice, SellingPrice, ScrapPrice, UnitProfit);
         SimulationTable.Add(tempCase);
     }
 }
        public void startSimulation()
        {
            for (int i = 1; i <= system.NumOfRecords; i++)
            {
                //{ key, value}
                KeyValuePair <Enums.DayType, int> randomDayType = generateRandomDayType();
                //{dayetype, random }
                KeyValuePair <int, int> randomDemond = generateRandomDemond((int)randomDayType.Key);
                //{ customers, random}
                SimulationCase simcase = new SimulationCase();

                simcase.DayNo             = i;
                simcase.RandomNewsDayType = randomDayType.Value;
                simcase.NewsDayType       = randomDayType.Key;

                simcase.RandomDemand = randomDemond.Value;
                simcase.Demand       = randomDemond.Key;

                simcase.SalesProfit = (decimal)Math.Min(simcase.Demand, system.NumOfNewspapers) * system.SellingPrice;
                simcase.LostProfit  = (decimal)Math.Max(0, simcase.Demand - system.NumOfNewspapers) * (system.SellingPrice - system.PurchasePrice);

                simcase.ScrapProfit = (decimal)Math.Max(0, system.NumOfNewspapers - simcase.Demand) * system.ScrapPrice;
                simcase.DailyCost   = (decimal)system.PurchasePrice * (decimal)system.NumOfNewspapers;

                simcase.DailyNetProfit = simcase.SalesProfit - simcase.DailyCost - simcase.LostProfit + simcase.ScrapProfit;
                system.SimulationTable.Add(simcase);

                if (simcase.ScrapProfit > 0)
                {
                    system.PerformanceMeasures.DaysWithUnsoldPapers++;
                }
                if (simcase.LostProfit > 0)
                {
                    system.PerformanceMeasures.DaysWithMoreDemand++;
                }

                system.PerformanceMeasures.TotalLostProfit += simcase.LostProfit;

                system.PerformanceMeasures.TotalScrapProfit += simcase.ScrapProfit;
                system.PerformanceMeasures.TotalSalesProfit += simcase.SalesProfit;

                system.PerformanceMeasures.TotalCost      += (decimal)system.NumOfNewspapers * system.PurchasePrice;
                system.PerformanceMeasures.TotalNetProfit += simcase.DailyNetProfit;
            }
        }
        ////////////////////////////////

        void runSimulation()
        {
            Random random = new Random();

            for (int i = 0; i < NumOfRecords; i++)
            {
                SimulationCase simCase = new SimulationCase();
                simCase.DayNo             = i + 1;
                simCase.RandomNewsDayType = random.Next(1, 100);
                simCase.NewsDayType       = getDayType(simCase.RandomNewsDayType);
                simCase.RandomDemand      = random.Next(1, 100);
                simCase.Demand            = getDemand(simCase.NewsDayType, simCase.RandomDemand);
                simCase.DailyCost         = CalcDaiyCost();
                simCase.SalesProfit       = calcDailyProfit(simCase.Demand);
                simCase.LostProfit        = calcLostProfit(simCase.Demand);
                simCase.ScrapProfit       = calcSalvageFromSaleOfScrap(simCase.Demand);
                simCase.DailyNetProfit    = calcDailyNetProfit(simCase.SalesProfit, simCase.DailyCost, simCase.LostProfit, simCase.ScrapProfit);
                SimulationTable.Add(simCase);
            }
        }
        public void Start_Process()
        {
            int            c    = 0;
            Random         rand = new Random();
            SimulationCase row;

            while (c < NumOfRecords)
            {
                row = new SimulationCase();

                row.DayNo             = c + 1;
                row.RandomNewsDayType = rand.Next(1, 101);
                row.NewsDayType       = Get_Day_Type(DayTypeDistributions, row.RandomNewsDayType);
                row.RandomDemand      = rand.Next(1, 101);
                row.Demand            = Get_Demand(DemandDistributions, row.RandomDemand, row.NewsDayType.ToString());
                row.DailyCost         = Cost;
                row.SalesProfit       = row.Demand * SellingPrice;
                if (row.Demand > NumOfNewspapers)
                {
                    row.SalesProfit = NumOfNewspapers * SellingPrice;
                    row.LostProfit  = (row.Demand - NumOfNewspapers) * (SellingPrice - PurchasePrice);
                    PerformanceMeasures.DaysWithMoreDemand++;
                }
                if (row.Demand < NumOfNewspapers)
                {
                    row.ScrapProfit = (NumOfNewspapers - row.Demand) * ScrapPrice;
                    PerformanceMeasures.DaysWithUnsoldPapers++;
                }
                row.DailyNetProfit = row.SalesProfit - row.DailyCost - row.LostProfit + row.ScrapProfit;

                // rest of performance calculations
                PerformanceMeasures.TotalCost        += row.DailyCost;
                PerformanceMeasures.TotalSalesProfit += row.SalesProfit;
                PerformanceMeasures.TotalScrapProfit += row.ScrapProfit;
                PerformanceMeasures.TotalLostProfit  += row.LostProfit;
                PerformanceMeasures.TotalNetProfit   += row.DailyNetProfit;

                SimulationTable.Add(row);
                c++;
            }
        }
Exemplo n.º 10
0
        public void BeginSimulation()
        {
            Random R = new Random();

            for (int i = 0; i < NumOfRecords; i++)
            {
                SimulationCase SC = new SimulationCase();
                SC.DayNo             = i + 1;
                SC.RandomNewsDayType = R.Next(1, 100);
                SC.NewsDayType       = GetDayType(SC.RandomNewsDayType);
                SC.RandomDemand      = R.Next(1, 100);
                SC.Demand            = GetDemand(SC.RandomDemand, SC.NewsDayType);


                SC.DailyCost   = NumOfNewspapers * PurchasePrice;
                SC.SalesProfit = NumOfNewspapers * SellingPrice;
                decimal ProfitPerPiece = SellingPrice - PurchasePrice;

                if (SC.Demand > NumOfNewspapers)
                {
                    SC.LostProfit  = (SC.Demand - NumOfNewspapers) * ProfitPerPiece;
                    SC.ScrapProfit = 0;
                }
                else if (SC.Demand < NumOfNewspapers)
                {
                    SC.ScrapProfit     = (NumOfNewspapers - SC.Demand) * ScrapPrice;
                    SC.SalesProfit    -= (NumOfNewspapers - SC.Demand) * SellingPrice;
                    SC.DailyNetProfit += SC.ScrapProfit;
                    SC.LostProfit      = 0;
                }
                else
                {
                    SC.ScrapProfit = 0;
                    SC.LostProfit  = 0;
                }
                SC.DailyNetProfit = SC.SalesProfit - SC.DailyCost - SC.LostProfit + SC.ScrapProfit;
                SimulationTable.Add(SC);
            }
            Resas();
        }
Exemplo n.º 11
0
        ///////////// SimulationTable ////////////////
        public void fillTable()
        {
            Random rand = new Random();

            for (int i = 1; i <= NumOfRecords; i++)
            {
                SimulationCase sc = new SimulationCase();
                sc.DayNo = i;

                sc.RandomNewsDayType = rand.Next(1, 101);
                sc.RandomDemand      = rand.Next(1, 101);

                if (sc.RandomNewsDayType >= DayTypeDistributions.ElementAt(0).MinRange&& sc.RandomNewsDayType <= DayTypeDistributions.ElementAt(0).MaxRange)
                {
                    sc.NewsDayType = Enums.DayType.Good;
                }
                else if (sc.RandomNewsDayType >= DayTypeDistributions.ElementAt(1).MinRange&& sc.RandomNewsDayType <= DayTypeDistributions.ElementAt(1).MaxRange)
                {
                    sc.NewsDayType = Enums.DayType.Fair;
                }
                else
                {
                    sc.NewsDayType = Enums.DayType.Poor;
                }


                if (sc.NewsDayType == Enums.DayType.Good)
                {
                    for (int j = 0; j < DemandDistributions.Count; j++)
                    {
                        if (sc.RandomDemand >= DemandDistributions.ElementAt(j).DayTypeDistributions.ElementAt(0).MinRange&& sc.RandomDemand <= DemandDistributions.ElementAt(j).DayTypeDistributions.ElementAt(0).MaxRange)
                        {
                            sc.Demand = DemandDistributions.ElementAt(j).Demand;
                        }
                    }
                }



                else if (sc.NewsDayType == Enums.DayType.Fair)
                {
                    for (int j = 0; j < DemandDistributions.Count; j++)
                    {
                        if (sc.RandomDemand >= DemandDistributions.ElementAt(j).DayTypeDistributions.ElementAt(1).MinRange&& sc.RandomDemand <= DemandDistributions.ElementAt(j).DayTypeDistributions.ElementAt(1).MaxRange)
                        {
                            sc.Demand = DemandDistributions.ElementAt(j).Demand;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < DemandDistributions.Count; j++)
                    {
                        if (sc.RandomDemand >= DemandDistributions.ElementAt(j).DayTypeDistributions.ElementAt(2).MinRange&& sc.RandomDemand <= DemandDistributions.ElementAt(j).DayTypeDistributions.ElementAt(2).MaxRange)
                        {
                            sc.Demand = DemandDistributions.ElementAt(j).Demand;
                        }
                    }
                }



                sc.DailyCost = NumOfNewspapers * PurchasePrice;
                if (sc.Demand >= NumOfNewspapers)
                {
                    sc.SalesProfit = NumOfNewspapers * SellingPrice;
                    sc.LostProfit  = (sc.Demand - NumOfNewspapers) * (SellingPrice - PurchasePrice);
                    sc.ScrapProfit = 0;
                }

                else if (NumOfNewspapers > sc.Demand)
                {
                    sc.SalesProfit = sc.Demand * SellingPrice;
                    sc.ScrapProfit = (NumOfNewspapers - sc.Demand) * ScrapPrice;
                    sc.LostProfit  = 0;
                }
                sc.DailyNetProfit = sc.SalesProfit - sc.DailyCost - sc.LostProfit + sc.ScrapProfit;
                SimulationTable.Add(sc);
            }
        }