예제 #1
0
        private static void SwapPoorWatingSlot(ref Maintainance schedule, List <ColumnRank> improveColumns, ref bool isChanged)
        {
            foreach (var i in improveColumns.Where(f => f.IsPoor.Value == true))            //Take poor ranks
            {
                                #if true
                int countPoor = improveColumns.Count(f => f.IsPoor.Value == true);
                                #endif


                List <ColumnRank> destCols = improveColumns.FindAll(f => f.ColumnIndex != i.ColumnIndex && f.IsPoor.Value == true);
                if (destCols.Count > 0)
                {
                    int selectedPoorIndex = new Random(Guid.NewGuid().GetHashCode()).Next(0, destCols.Count - 1);
                    if (destCols.Count == 2)
                    {
                        selectedPoorIndex = Convert.ToInt32(Math.Abs(Guid.NewGuid().GetHashCode() % 2));
                    }

                    ColumnRank swapCol = destCols.ElementAt(selectedPoorIndex);

                    if (schedule.Slot[swapCol.ColumnIndex] != null && schedule.Slot[i.ColumnIndex] != null)
                    {
                        //Swap objects
                        Program.SwapRef(ref schedule.Slot[swapCol.ColumnIndex], ref schedule.Slot[i.ColumnIndex]);
                        isChanged = true;
                        i.IsPoor  = false;
                        break;
                    }
                }
                else
                {
                    Trace.WriteLine("Poor column were not found!");
                }
            }
        }
예제 #2
0
        public void UpdateStatus()
        {
            if (this.DepartureTime >= Program.CurrentTime && this.Status != AirStatus.A)
            {
                int reachedTime = Convert.ToInt32((this.ArrivalTime - this.DepartureTime).TotalMinutes);
                if (reachedTime == this.AccumulateTime)
                {
                    this.AccumulateTimeLog = this.AccumulateTime;
                    this.AccumulateTime    = 0;
                    this.Status            = AirStatus.A;

                    //Try to add air to maintaince
                    Maintainance m = Matrix.AddAirToMaintain(this);
                    if (m != null)
                    {
                        this.WaitingDuration = Convert.ToInt32((m.MaintainanceStartedTime - this.ArrivalTime).TotalMinutes);
                        this.Schedule        = m.MaintainanceStartedTime;
                    }
                }
                else
                {
                    this.AccumulateTime++;
                }
            }
            if (this.Status == AirStatus.A && this.Schedule != null)
            {
                this.Status             = AirStatus.M;
                this.WaitingDurationLog = this.WaitingDuration;
                this.WaitingDuration    = 0;
            }
        }
예제 #3
0
        public static List <Maintainance> FixPoorRank(List <Maintainance> schedules, List <ColumnRank> ranks)
        {
            List <ColumnRank> cImproved = GetRankedColumns(schedules).Where(f => f.IsPoor.Value).ToList();

            for (int i = 0; i < schedules.Count; i++)
            {
                List <ColumnRank> iColRank = GetRankedColumns(schedules);
                bool iChanged = false;

                Maintainance iSwap   = schedules[i];
                Maintainance iBefore = Program.Clone(iSwap);


                SwapPoorWatingSlot(
                    ref iSwap,
                    cImproved.Where(f => f.IsPoor.Value == true).ToList(),
                    ref iChanged
                    );

                if (iChanged)
                {
                }
            }

                        #if true
            int countFixedPoor = cImproved.Count(f => f.IsPoor.Value);
                        #endif

            Maintainance[] output = new Maintainance[schedules.Count];
            schedules.CopyTo(output);
            return(output.ToList());
        }
예제 #4
0
        private void AllocateSlot(Air air, Maintainance nearestSchedule)
        {
            int airInSchedule = nearestSchedule.Slot.Where(f => f != null).Count();
            int nextIndex     = Matrix.MaintainanceCollection.LastIndexOf(nearestSchedule);

            Trace.WriteLine("airInSchedule " + airInSchedule);
            if (airInSchedule < 5)
            {
                while (true)
                {
                    int random = new Random().Next(nearestSchedule.Slot.Length - 1);
                    //Trace.WriteLine("Random " + random);
                    if (nearestSchedule.Slot[random] == null)
                    {
                        nearestSchedule.Slot[random] = air;
                        break;
                    }
                }
                Trace.WriteLine("Maintainance Start Time : " + nearestSchedule.MaintainanceStartedTime);
                Trace.WriteLine("Slot Capacity : " + nearestSchedule.Slot.Where(f => f != null).Count());
            }
            else if (nextIndex + 1 != Matrix.MaintainanceCollection.Count)
            {
                AllocateSlot(air, Matrix.MaintainanceCollection[nextIndex + 1]);
                Trace.WriteLine("Maintainance Start Time : " + Matrix.MaintainanceCollection[nextIndex + 1].MaintainanceStartedTime);
                Trace.WriteLine("Slot Capacity : " + Matrix.MaintainanceCollection[nextIndex + 1].Slot.Where(f => f != null).Count());
            }
        }
예제 #5
0
        public static Maintainance AddAirToMaintain(Air air)
        {
            Maintainance m = NearestSchedule(air);
            Maintainance alcocatedSchdule = null;

            try
            {
                alcocatedSchdule = m.AddAir(air);
            }
            catch (Exception)
            {            /*An exception will be occured when it's run to latest maintaince.*/
            }
            return(alcocatedSchdule);
        }
예제 #6
0
        public Maintainance AddAir(Air air)
        {
            Maintainance nearestSchedule = Matrix.NearestSchedule(air);

            if (nearestSchedule == null)
            {
                return(null);
            }
            else
            {
                //Try first nearest schedule.
                this.AllocateSlot(air, nearestSchedule);
            }

            return(nearestSchedule);
        }
예제 #7
0
        public static CalucationData GetRawCalculationData(int iteration, List <Maintainance> maintainances)
        {
            int            countCal = Program.CalculationSeq++;
            CalucationData calData  = null;
            double         t        = 0;
            double         tt       = 0;



            for (int i = 0; i < maintainances.Count; i++)
            {
                Maintainance iM = maintainances[i];
                for (int j = 0; j < Program.MAX_AIR; j++)
                {
                    if (iM.Slot[j] != null)
                    {
                        ++t;
                    }
                }
            }


            for (int i = 0; i < Program.MAX_AIR; i++)
            {
                double iSlot = 0;
                for (int j = 0; j < maintainances.Count; j++)
                {
                    if (maintainances[j].Slot[i] != null)
                    {
                        ++iSlot;
                    }
                }
                tt += Math.Pow(iSlot, 2);
            }


            calData = new CalucationData(
                countCal,
                t,
                tt,
                iteration,
                maintainances
                );

            return(calData);
        }
예제 #8
0
        private static Maintainance SwapSlot(Maintainance schedule, List <ColumnRank> improveColumns, List <ColumnRank> allRankedColumns)
        {
            foreach (var i in improveColumns)
            {
                List <ColumnRank> destCols = allRankedColumns.FindAll(f => {
                    return(!improveColumns.Exists(g => g.ColumnIndex == f.ColumnIndex));
                });



                if (destCols.Count > 0)
                {
                    int selectedPoorIndex = new Random(Guid.NewGuid().GetHashCode()).Next(0, destCols.Count - 1);
                    if (destCols.Count == 2)
                    {
                        selectedPoorIndex = Convert.ToInt32(Math.Abs(Guid.NewGuid().GetHashCode() % 2));
                    }
                    else if (destCols.Count == 1)
                    {
                    }
                    ColumnRank swapCol = destCols.ElementAt(selectedPoorIndex);


                    Air iDestAir = schedule.Slot[swapCol.ColumnIndex];
                    if (iDestAir != null)
                    {
                        //Clone Air object from destination array then remove it.
                        Air sourceAir = schedule.Slot[swapCol.ColumnIndex];
                        schedule.Slot[swapCol.ColumnIndex] = null;

                        //Assign cloning object to improve index.
                        schedule.Slot[i.ColumnIndex] = sourceAir;
                    }
                }
                else
                {
                    Trace.WriteLine("Poor column were not found!");
                }
            }


            return(schedule);
        }