コード例 #1
0
        public void sim()
        {
            int    ncycle      = NumberOfDays / ReviewPeriod;
            int    da          = 1;
            Random rnd         = new Random();
            Random rndd        = new Random();
            int    startshortq = 0;

            for (int i = 1; i <= ncycle; i++)
            {
                for (int j = 1; j <= ReviewPeriod; j++)
                {
                    if (j == (StartLeadDays + 1))
                    {
                        StartInventoryQuantity += StartOrderQuantity;
                    }
                    SimulationCase c = new SimulationCase();
                    c.Day = da;
                    da++;
                    c.Cycle              = i;
                    c.DayWithinCycle     = j;
                    c.BeginningInventory = StartInventoryQuantity;
                    c.RandomDemand       = rnd.Next(1, 101);
                    c.Demand             = get_dist(c.RandomDemand, DemandDistribution);
                    if (c.Demand + startshortq <= c.BeginningInventory)
                    {
                        c.EndingInventory      = c.BeginningInventory - c.Demand - startshortq;
                        startshortq            = 0;
                        StartInventoryQuantity = c.EndingInventory;
                    }
                    else if (c.Demand + startshortq > c.BeginningInventory)
                    {
                        c.EndingInventory      = 0;
                        StartInventoryQuantity = 0;
                        c.ShortageQuantity     = c.Demand - c.BeginningInventory + startshortq;
                        startshortq            = c.ShortageQuantity;
                    }
                    if (j == ReviewPeriod)
                    {
                        c.OrderQuantity    = OrderUpTo - c.EndingInventory + c.ShortageQuantity;
                        StartOrderQuantity = c.OrderQuantity;
                        c.RandomLeadDays   = rndd.Next(1, 101);
                        c.LeadDays         = get_dist(c.RandomLeadDays, LeadDaysDistribution);
                        StartLeadDays      = c.LeadDays;
                    }
                    PerformanceMeasures.EndingInventoryAverage  += c.EndingInventory;
                    PerformanceMeasures.ShortageQuantityAverage += c.ShortageQuantity;
                    SimulationTable.Add(c);
                }
            }
            PerformanceMeasures.EndingInventoryAverage  = (decimal)(PerformanceMeasures.EndingInventoryAverage / NumberOfDays);
            PerformanceMeasures.ShortageQuantityAverage = (decimal)(PerformanceMeasures.ShortageQuantityAverage / NumberOfDays);
        }
コード例 #2
0
        public Tuple <decimal, decimal> FillSimulationTable()
        {
            int     orderArrival = StartLeadDays + 1, orderQuantity = StartOrderQuantity;
            int     lastInventory = StartInventoryQuantity, lastShortage = 0;
            decimal totalEnding = 0, totalShortage = 0;

            for (int i = 0; i < NumberOfDays; i++)
            {
                SimulationCase Case = new SimulationCase();

                Case.Day = i + 1;

                decimal cycle = decimal.Divide(Case.Day, ReviewPeriod);
                Case.Cycle = Convert.ToInt32(Math.Ceiling(cycle));

                Case.DayWithinCycle = Case.Day % 5;
                if (Case.DayWithinCycle == 0)
                {
                    Case.DayWithinCycle = 5;
                }

                Case.BeginningInventory = lastInventory;
                if (Case.Day == orderArrival)
                {
                    Case.BeginningInventory += orderQuantity;
                }

                Tuple <int, int> demand = HelperFunctions.GetNumber("Demand", DemandDistribution);
                Case.RandomDemand = demand.Item1;
                Case.Demand       = demand.Item2;

                Case.EndingInventory = Case.BeginningInventory - Case.Demand;

                if (Case.Day == orderArrival)
                {
                    Case.EndingInventory -= lastShortage;
                    lastShortage          = 0;
                }

                Case.ShortageQuantity = lastShortage;
                if (Case.EndingInventory < 0)
                {
                    Case.ShortageQuantity -= Case.EndingInventory;
                    Case.EndingInventory   = 0;
                }

                if (Case.DayWithinCycle == 5)   // Review
                {
                    Tuple <int, int> leadDays = HelperFunctions.GetNumber("LeadDays", LeadDaysDistribution);
                    Case.RandomLeadDays = leadDays.Item1;
                    Case.LeadDays       = leadDays.Item2;
                    Case.OrderQuantity  = OrderUpTo - Case.EndingInventory + Case.ShortageQuantity;
                    if (Case.OrderQuantity > 0)   // Place order
                    {
                        orderArrival  = Case.Day + Case.LeadDays + 1;
                        orderQuantity = Case.OrderQuantity;
                    }
                }

                if (orderArrival >= Case.Day + 1)
                {
                    Case.DaysUntilOrderArrives = orderArrival - (Case.Day + 1);
                }

                SimulationTable.Add(Case);

                // Update data
                lastInventory  = Case.EndingInventory;
                lastShortage   = Case.ShortageQuantity;
                totalEnding   += Case.EndingInventory;
                totalShortage += Case.ShortageQuantity;
            }

            return(new Tuple <decimal, decimal>(totalEnding, totalShortage));
        }
コード例 #3
0
        public void simulate()
        {
            int            O_Quantity    = 0;
            int            temp_shortage = 0;
            SimulationCase temp          = new SimulationCase();

            temp.Day                = 1;
            temp.Cycle              = 1;
            temp.DayWithinCycle     = 1;
            temp.BeginningInventory = StartInventoryQuantity;
            temp.demand(DemandDistribution);
            temp.EndingInventory = temp.BeginningInventory - temp.Demand;
            temp.Daytillarr      = StartLeadDays - 1;
            if (temp.EndingInventory < 0)
            {
                temp.ShortageQuantity = -1 * temp.EndingInventory;
                temp.EndingInventory  = 0;
            }
            SimulationTable.Add(temp);
            O_Quantity = StartOrderQuantity;

            temp = new SimulationCase();
            SimulationTable.Add(temp);
            for (int i = 1; i < NumberOfDays; i++)
            {
                temp_shortage          = SimulationTable[i - 1].ShortageQuantity;
                SimulationTable[i].Day = SimulationTable[i - 1].Day + 1;
                SimulationTable[i].BeginningInventory = SimulationTable[i - 1].EndingInventory;

                if (SimulationTable[i - 1].DayWithinCycle == 5)
                {
                    SimulationTable[i].Cycle          = SimulationTable[i - 1].Cycle + 1;
                    SimulationTable[i].DayWithinCycle = 1;
                }
                else
                {
                    SimulationTable[i].Cycle          = SimulationTable[i - 1].Cycle;
                    SimulationTable[i].DayWithinCycle = SimulationTable[i - 1].DayWithinCycle + 1;
                }

                SimulationTable[i].demand(DemandDistribution);
                SimulationTable[i].EndingInventory = SimulationTable[i].BeginningInventory - SimulationTable[i].Demand;

                if (SimulationTable[i - 1].Daytillarr > 0)
                {
                    SimulationTable[i].Daytillarr = SimulationTable[i - 1].Daytillarr - 1;
                }
                else
                {
                    if (SimulationTable[i - 1].Daytillarr == 0 && SimulationTable[i - 2].Daytillarr == 1)
                    {
                        SimulationTable[i].BeginningInventory += O_Quantity;
                        SimulationTable[i].demand(DemandDistribution);
                        SimulationTable[i].EndingInventory = SimulationTable[i].BeginningInventory - SimulationTable[i].Demand - SimulationTable[i - 1].ShortageQuantity;
                        temp_shortage = 0;
                    }
                }

                if (SimulationTable[i].EndingInventory < 0)
                {
                    SimulationTable[i].ShortageQuantity = -1 * SimulationTable[i].EndingInventory + temp_shortage;
                    SimulationTable[i].EndingInventory  = 0;
                }
                else if (SimulationTable[i].EndingInventory == 0)
                {
                    SimulationTable[i].ShortageQuantity = SimulationTable[i - 1].ShortageQuantity;
                }

                if (SimulationTable[i].DayWithinCycle == ReviewPeriod)
                {
                    SimulationTable[i].order(LeadDaysDistribution, OrderUpTo);
                    O_Quantity = SimulationTable[i].OrderQuantity;
                }

                if (i != NumberOfDays - 1)
                {
                    temp = new SimulationCase();
                    SimulationTable.Add(temp);
                }
            }
        }
コード例 #4
0
        public void runSystem()
        {
            int  currentQuantity   = StartInventoryQuantity;
            int  currentShortage   = 0;
            int  nextOrderLeadDays = StartLeadDays - 1;
            int  nextOrderQuantity = StartOrderQuantity;
            bool flag = true;

            for (int i = 0; i < NumberOfDays; ++i)
            {
                SimulationCase nCase = new SimulationCase();
                nCase.Day = i + 1;

                if (nextOrderLeadDays == 0 && flag)
                {
                    currentQuantity         += nextOrderQuantity;
                    nCase.BeginningInventory = currentQuantity;
                    currentQuantity         -= currentShortage;
                    currentShortage          = 0;
                    flag = false;
                }
                else
                {
                    nCase.BeginningInventory = currentQuantity;
                }

                nCase.Cycle = nCase.Day / ReviewPeriod;
                if (nCase.Day % ReviewPeriod != 0)
                {
                    ++nCase.Cycle;
                }

                nCase.DayWithinCycle = nCase.Day % ReviewPeriod;
                if (nCase.DayWithinCycle == 0)
                {
                    nCase.DayWithinCycle = ReviewPeriod;
                }


                nCase.RandomDemand = randomNumber();
                for (int j = 0; j < DemandDistribution.Count; ++j)
                {
                    if (nCase.RandomDemand >= DemandDistribution[j].MinRange && nCase.RandomDemand <= DemandDistribution[j].MaxRange)
                    {
                        nCase.Demand = DemandDistribution[j].Value;
                    }
                }

                if (nCase.Demand <= currentQuantity)
                {
                    currentQuantity -= nCase.Demand;
                }
                else
                {
                    currentShortage += nCase.Demand - currentQuantity;
                    currentQuantity  = 0;
                }

                nCase.EndingInventory  = currentQuantity;
                nCase.ShortageQuantity = currentShortage;

                if (nCase.Day % ReviewPeriod == 0)
                {
                    nCase.OrderQuantity  = (OrderUpTo - currentQuantity) + currentShortage;
                    nextOrderQuantity    = nCase.OrderQuantity;
                    nCase.RandomLeadDays = randomNumber();
                    for (int j = 0; j < LeadDaysDistribution.Count; ++j)
                    {
                        if (nCase.RandomLeadDays >= LeadDaysDistribution[j].MinRange && nCase.RandomLeadDays <= LeadDaysDistribution[j].MaxRange)
                        {
                            nCase.LeadDays = LeadDaysDistribution[j].Value;
                        }
                    }
                    nextOrderLeadDays = nCase.LeadDays + 1;
                    flag = true;
                }
                else
                {
                    nCase.OrderQuantity = nCase.RandomLeadDays = nCase.LeadDays = 0;
                }


                if (nextOrderLeadDays > 0 && i != 0)
                {
                    --nextOrderLeadDays;
                }
                nCase.DaysUntilOrderArrives = nextOrderLeadDays;

                SimulationTable.Add(nCase);
            }
            PerformanceMeasures.calculatePerformanceMeasures(SimulationTable);
        }
コード例 #5
0
        public void Run(string path)
        {
            random = new Random();
            int cycle = 1, counter_day_in_cycle = 1, days_until_order_arrives = -10, next_order = 0;

            ReadFromFile(path);
            CompleteDemandAndLeadDaysDistribution(DemandDistribution);
            CompleteDemandAndLeadDaysDistribution(LeadDaysDistribution);

            SimulationCase simulationCase;

            for (int i = 0; i < NumberOfDays; ++i)
            {
                simulationCase                = new SimulationCase();
                simulationCase.Day            = i + 1;
                simulationCase.Cycle          = cycle;
                simulationCase.DayWithinCycle = counter_day_in_cycle;

                if (i == 0)
                {
                    simulationCase.BeginningInventory = StartInventoryQuantity;
                }
                else
                {
                    simulationCase.BeginningInventory = SimulationTable[i - 1].EndingInventory;
                }

                if (i == StartLeadDays)
                {
                    simulationCase.BeginningInventory += StartOrderQuantity;
                }

                if (days_until_order_arrives == -1)
                {
                    simulationCase.BeginningInventory += next_order;
                }

                simulationCase.RandomDemand = random.Next(1, 100);
                simulationCase.Demand       = getDistributionValueByRandomNumber(DemandDistribution, simulationCase.RandomDemand);

                int last_sortage = 0;
                if (i > 0)
                {
                    last_sortage = SimulationTable[i - 1].ShortageQuantity;
                }

                if (simulationCase.BeginningInventory >= simulationCase.Demand + last_sortage)
                {
                    simulationCase.EndingInventory  = simulationCase.BeginningInventory - (simulationCase.Demand + last_sortage);
                    simulationCase.ShortageQuantity = 0;
                }
                else
                {
                    simulationCase.EndingInventory  = 0;
                    simulationCase.ShortageQuantity = (simulationCase.Demand + last_sortage) - simulationCase.BeginningInventory;
                }

                if (ReviewPeriod == counter_day_in_cycle)
                {
                    cycle++;
                    counter_day_in_cycle         = 0;
                    simulationCase.OrderQuantity = OrderUpTo - simulationCase.EndingInventory + simulationCase.ShortageQuantity;
                    next_order = simulationCase.OrderQuantity;
                    simulationCase.RandomLeadDays = random.Next(1, 100);
                    simulationCase.LeadDays       = getDistributionValueByRandomNumber(LeadDaysDistribution, simulationCase.RandomLeadDays);
                    days_until_order_arrives      = simulationCase.LeadDays;
                }
                else
                {
                    simulationCase.OrderQuantity  = 0;
                    simulationCase.RandomLeadDays = 0;
                    simulationCase.LeadDays       = 0;
                }
                counter_day_in_cycle++;
                days_until_order_arrives--;

                SimulationTable.Add(simulationCase);
            }

            decimal count_end = 0, count_shortage = 0;

            for (int i = 0; i < SimulationTable.Count(); ++i)
            {
                count_end      += SimulationTable[i].EndingInventory;
                count_shortage += SimulationTable[i].ShortageQuantity;
            }

            PerformanceMeasures.EndingInventoryAverage  = count_end / NumberOfDays;
            PerformanceMeasures.ShortageQuantityAverage = count_shortage / NumberOfDays;
        }
コード例 #6
0
        public void Run()
        {
            Random DemandRandom   = new Random();
            Random LeadDaysRandom = new Random();
            int    cycle          = 1;
            int    day_in_cycle   = 1;
            int    total_shortage = 0;
            int    pre_end        = mysys.StartInventoryQuantity;

            int[]   orders               = new int[mysys.NumberOfDays + 100];
            decimal total_ending         = 0;
            decimal final_total_shortage = 0;

            orders[mysys.StartLeadDays + 1] = mysys.StartOrderQuantity;
            for (int day = 1; day <= mysys.NumberOfDays; day++)
            {
                SimulationCase one = new SimulationCase();
                one.Day                = day;
                one.Cycle              = cycle;
                one.DayWithinCycle     = day_in_cycle;
                one.BeginningInventory = pre_end + orders[day];
                one.RandomDemand       = DemandRandom.Next(1, 100);
                one.Demand             = get_val(one.RandomDemand, mysys.DemandDistribution);
                if (one.Demand > one.BeginningInventory)
                {
                    one.EndingInventory  = 0;
                    one.ShortageQuantity = one.Demand - one.BeginningInventory + total_shortage;
                    total_shortage       = one.ShortageQuantity;
                }
                else
                {
                    one.EndingInventory  = one.BeginningInventory - one.Demand;
                    one.ShortageQuantity = total_shortage;
                }
                if (day % mysys.ReviewPeriod == 0)
                {
                    if (one.EndingInventory < mysys.OrderUpTo)
                    {
                        one.RandomLeadDays             = LeadDaysRandom.Next(1, 100);
                        one.LeadDays                   = get_val(one.RandomLeadDays, mysys.LeadDaysDistribution);
                        one.OrderQuantity              = mysys.OrderUpTo - one.EndingInventory + total_shortage;
                        orders[day + one.LeadDays + 1] = one.OrderQuantity;
                    }
                    else
                    {
                        one.RandomLeadDays = 0;
                        one.LeadDays       = 0;
                        one.OrderQuantity  = 0;
                    }
                    cycle++;
                    day_in_cycle = 1;
                }
                else
                {
                    one.RandomLeadDays = 0;
                    one.LeadDays       = 0;
                    one.OrderQuantity  = 0;
                    day_in_cycle++;
                }
                if (orders[day] != 0)
                {
                    if (one.EndingInventory >= total_shortage)
                    {
                        one.EndingInventory -= total_shortage;
                        total_shortage       = 0;
                        one.ShortageQuantity = 0;
                    }
                    else
                    {
                        total_shortage      -= one.EndingInventory;
                        one.ShortageQuantity = total_shortage;
                        one.EndingInventory  = 0;
                    }
                }
                mysys.SimulationCases.Add(one);
                total_ending         += one.EndingInventory;
                final_total_shortage += one.ShortageQuantity;
                pre_end = one.EndingInventory;
            }
            decimal n = mysys.SimulationCases.Count();

            mysys.PerformanceMeasures.EndingInventoryAverage  = total_ending / n;
            mysys.PerformanceMeasures.ShortageQuantityAverage = final_total_shortage / n;
        }
コード例 #7
0
        public List <SimulationCase> get_table()
        {
            List <SimulationCase> ret = new List <SimulationCase>();

            int    cycle = 1, start_up = system.StartLeadDays + 1, inv_begin = system.StartInventoryQuantity, start_order = system.StartOrderQuantity, rand = 0;
            int    sh = 0, demand = 0;
            Random R = new Random();

            Dictionary <int, int> up_day = new Dictionary <int, int>();

            for (int i = 0; i < system.NumberOfDays; i++)
            {
                SimulationCase cs = new SimulationCase();
                cs.Day   = i + 1;
                cs.Cycle = cycle;

                cs.DayWithinCycle = (i + 1) % system.ReviewPeriod;
                if (cs.DayWithinCycle == 0)
                {
                    cs.DayWithinCycle = system.ReviewPeriod;
                    cycle++;
                }

                cs.BeginningInventory = inv_begin;
                if (i + 1 == start_up)
                {
                    cs.BeginningInventory += start_order;
                }
                try
                {
                    cs.BeginningInventory += up_day[i + 1];
                }
                catch (Exception q)
                {
                    cs.BeginningInventory += 0;
                }

                rand            = R.Next(1, 101);
                cs.RandomDemand = rand;
                for (int j = 0; j < system.DemandDistribution.Count; j++)
                {
                    if (system.DemandDistribution[j].MinRange <= rand && system.DemandDistribution[j].MaxRange >= rand)
                    {
                        cs.Demand = system.DemandDistribution[j].Value;
                        demand    = system.DemandDistribution[j].Value;
                        break;
                    }
                }

                demand            += sh;
                cs.EndingInventory = Math.Max(0, cs.BeginningInventory - demand);

                if (cs.BeginningInventory >= demand)
                {
                    cs.ShortageQuantity = 0;
                }
                else
                {
                    cs.ShortageQuantity = demand - cs.BeginningInventory;
                }

                if (cs.DayWithinCycle == system.ReviewPeriod)
                {
                    cs.OrderQuantity  = system.OrderUpTo - cs.EndingInventory + cs.ShortageQuantity;
                    cs.RandomLeadDays = R.Next(1, 101);
                    for (int j = 0; j < system.LeadDaysDistribution.Count; j++)
                    {
                        if (system.LeadDaysDistribution[j].MinRange <= cs.RandomLeadDays && system.LeadDaysDistribution[j].MaxRange >= cs.RandomLeadDays)
                        {
                            cs.LeadDays = system.LeadDaysDistribution[j].Value;
                            break;
                        }
                    }

                    try
                    {
                        up_day[(i + 1) + cs.LeadDays + 1] += cs.OrderQuantity;
                    }
                    catch (Exception qq)
                    {
                        up_day[(i + 1) + cs.LeadDays + 1] = cs.OrderQuantity;
                    }
                }
                else
                {
                    cs.OrderQuantity  = 0;
                    cs.RandomLeadDays = 0;
                    cs.LeadDays       = 0;
                }

                sh            = cs.ShortageQuantity;
                inv_begin     = cs.EndingInventory;
                tot_end      += cs.EndingInventory;
                tot_shortage += cs.ShortageQuantity;

                ret.Add(cs);
            }

            return(ret);
        }