public CalucationData(int seqNo, double tSumAll, double tEachSumPowEach, int iteration, List <Maintainance> schedules)
        {
            this.SeqNo           = seqNo;
            this.T               = tSumAll;
            this.TT              = tEachSumPowEach;
            this.Iteration       = iteration;
            this.K               = ComputationUnit.GetK(SigmaT.Value);
            this.TZero           = Program.UserTZero;
            this.AlphaExpoential = Program.UserAlphaExponential;
            this.Gramma          = Program.UserGramma;

            this.Schedules = schedules;
        }
        public void StartCalculation(double previouTSumAll)
        {
            this.PreviouseT = previouTSumAll;
            this.DeltaT     = this.PreviouseT.Value - T;

            //For exponentials
            this.Exponential = ComputationUnit.Exponential(TZero.Value, AlphaExpoential.Value, K.Value);
            this.Logarithmic = ComputationUnit.Logarithmic(TZero.Value, Iteration.Value);
            this.Linear      = ComputationUnit.Linear(TZero.Value, AlphaExpoential.Value, Iteration.Value);
            this.Geometric   = ComputationUnit.Geometric(AlphaExpoential.Value, Iteration.Value, TZero.Value);

            //For temparatures
            this.Adaptive1 = ComputationUnit.Adaptive1(this.PreviouseT.Value, SigmaT.Value);
            this.Adaptive2 = ComputationUnit.Adaptive2(this.PreviouseT.Value);
            this.Adaptive3 = ComputationUnit.Adaptive3(this.PreviouseT.Value, SigmaT.Value, this.Gramma.Value);
            this.Adaptive4 = ComputationUnit.Adaptive4(this.PreviouseT.Value, 0, this.SigmaT.Value);
        }
Esempio n. 3
0
        public static CalucationData Simulate(string name, int iteration, List <CalucationData> cCalculation, params Air[] airs)
        {
            CalucationData       prevCalculation = cCalculation.LastOrDefault();
            List <MatrixCompare> checkList       = new List <MatrixCompare>();
            //Init matrix.
            List <Maintainance> cMaintain = null;
            CalucationData      cal       = null;

            if (iteration == 0)
            {
                Program.Reset();
                Program.TestNo = DateTime.Now.ToString("ddMMyyyy_hhmmss");

                List <Air> cAir      = new List <Air>(airs);
                int        countTick = 0;
                while ((_EndTime - Program.CurrentTime).TotalMinutes > -1)
                {
                    cAir.ForEach(f =>
                    {
                        if (f.DepartureTime >= Program.CurrentTime &&
                            f.Status != AirStatus.M
                            )
                        {
                            f.UpdateStatus();
                        }
                    });
                    Program.CurrentTime = Program.CurrentTime.AddMinutes(_Tick);

                    countTick++;
                }
                cMaintain = Matrix.Fixation(Matrix.MaintainanceCollection);
                cal       = ComputationUnit.GetRawCalculationData(iteration, cMaintain);
                cal.StartCalculation(0);
                cCalculation.Add(cal);



                FileHelper.AppendText(name.Replace(".", iteration + "."), "First Matrix", cal, checkList);
            }
            else
            {
                cMaintain = Program.Clone(prevCalculation.Schedules);

                int count = 0;
                foreach (var i in cMaintain)
                {
                    for (int j = 0; j < Program.MAX_AIR; j++)
                    {
                        if (i.Slot[j] != null)
                        {
                            checkList.Add(new MatrixCompare()
                            {
                                Before   = i.Slot[j].WaitingDurationLog,
                                Position = string.Format("({0},{1})", count, j)
                            });
                        }
                    }
                    count++;
                }


                List <ColumnRank> cPoorRank = Matrix.GetRankedColumns((cMaintain));
                //cMaintain = Matrix.FixPoorRank(cMaintain, cPoorRank);

                count = 0;
                foreach (var i in cMaintain)
                {
                    for (int j = 0; j < Program.MAX_AIR; j++)
                    {
                        if (i.Slot[j] != null)
                        {
                            MatrixCompare iCompare = checkList.Find(f => f.Position == string.Format("({0},{1})", count, j));
                            if (iCompare != null)
                            {
                                iCompare.After = i.Slot[j].WaitingDurationLog;
                            }
                        }
                    }

                    count++;
                }
                Console.WriteLine("========================================");
                Console.WriteLine("Iteration No.{0}", iteration);
                foreach (var i in checkList.Where(f => f.Changed))
                {
                    Console.WriteLine(string.Format(
                                          "{3}\r\nBefore = {0}, After = {1}, Changed = {2}",
                                          i.Before,
                                          i.After,
                                          i.Changed,
                                          i.Position
                                          ));
                }
                cal = ComputationUnit.GetRawCalculationData(iteration, cMaintain);
                string msg = "";
                if (prevCalculation.TotalWatingTime < cal.TotalWatingTime)
                {
                    cal = prevCalculation;
                }
                else
                {
                    msg = "New matrix was better!";
                    Console.WriteLine(msg);
                }

                cal.StartCalculation(prevCalculation.SigmaT.Value);
                cCalculation.Add(cal);

                FileHelper.AppendText(name.Replace(".", iteration + "."), msg, cal, checkList);
            }

            return(cal);
        }