Ejemplo n.º 1
0
        public static void ReadfromFile(out int NoJob, out int NoMc, out int[] NoOp, out job[] Job)
        {
            //Reading input data from a file
            char[]       Dividers = { ',', ' ' };
            StreamReader InputSR;

            ReadInput.OpenFile(out InputSR);
            ReadInput.ReadFile1NoJobMc(InputSR, Dividers, out NoJob, out NoMc);
            NoOp = new int[NoJob];
            Job  = new job[NoJob];
            ReadInput.ReadFile2ProcessTimeMachineNo(InputSR, NoJob, ref NoOp, ref Job, Dividers);

            //For MaxWeightedTardiness & MaxWeightedEaeliness
            ReadInput.ReadFile3ReadyTime(InputSR, ref Job, Dividers);
            //For MaxWeightedTardiness & MaxWeightedEaeliness
            ReadInput.ReadFile4DueDate(InputSR, ref Job, Dividers, NoJob);
            //For MaxWeightedTardiness & MaxWeightedEaeliness
            ReadInput.ReadFile5WeightTardy1Line(InputSR, ref Job, Dividers, NoJob);
            InputSR.Close();
            //Ending for reading input data from a file
        }
Ejemplo n.º 2
0
        public static void DE(double[] DEparas, int strategy, bool aniEnable, out double[] index, out ArrayList Pareto, out ArrayList Ani, out ArrayList AniS, out ArrayList Average)
        {
            // modification = criterion to join unexplored group is the range > 0.01*maxrange (excel)
            // trap=100 steps
            #region Read input from file
            int   NoJob;
            int   NoMc;
            int[] NoOp;
            job[] Job;
            ReadInput.ReadfromFile(out NoJob, out NoMc, out NoOp, out Job);
            #endregion
            #region calculateDimension
            int[]     NoOpPerMc = new int[NoMc];
            machine[] Machine   = new machine[NoMc];
            ReadInput.MachineInfo(NoJob, NoOp, ref NoOpPerMc, Job);
            JSPdata JD        = new JSPdata(NoJob, NoMc, NoOp, Job, NoOpPerMc, Machine);
            int     Dimension = 0;
            //To calculate Dimension = Sum of all NoOp
            for (int j = 0; j < NoJob; j++)
            {
                Dimension += NoOp[j];
            }
            #endregion
            #region Animation Storage
            ArrayList   PFront;
            ArrayList   sAni;
            ArrayList   sAni2;
            ArrayList[] AvgVal;
            ArrayList   vMix  = new ArrayList();
            string      oFile = "MyDE_strategy" + strategy.ToString() + ".xls";

            PFront = new ArrayList();
            sAni   = new ArrayList();
            sAni2  = new ArrayList();
            #endregion
            #region set DE parameters
            //parameter setting
            int    noIter = Convert.ToInt32(DEparas[0]);
            int    noVec  = Convert.ToInt32(DEparas[1]);
            double FMin   = DEparas[2];
            double FMax   = DEparas[3];
            int    noNB   = Convert.ToInt32(DEparas[4]);
            double COx    = DEparas[5];
            double COn    = DEparas[6];
            double cL     = DEparas[7];
            double cN     = DEparas[8];

            int    maxE         = Convert.ToInt32(DEparas[9]);
            double TopEp        = DEparas[10] / 100;
            double BotEp        = DEparas[11] / 100;
            double GapUnexplore = DEparas[12] / 100;

            int moveStrategy = strategy;

            int rSeed = (int)DEparas[17];
            int noRep = (int)DEparas[18];
            // end parameter setting

            if (moveStrategy == 5)
            {
                vMix.Add(0); vMix.Add((double)DEparas[13] / 100);
                vMix.Add(1); vMix.Add((double)DEparas[14] / 100);
                vMix.Add(2); vMix.Add((double)DEparas[15] / 100);
                vMix.Add(3); vMix.Add((double)DEparas[16] / 100);
            }
            #endregion
            // starting time and finish time using DateTime datatype
            DateTime start, finish;
            // elapsed time using TimeSpan datatype
            TimeSpan elapsed;
            #region Write parameter to text
            // opening output file
            TextWriter tw = new StreamWriter(oFile);
            tw.WriteLine("{0} Number of Vectors  ", noVec);
            tw.WriteLine("{0} Number of Iteration ", noIter);
            tw.WriteLine("{0} Number of Neighbor  ", noNB);
            tw.WriteLine("{0} Parameter Fmax      ", FMax);
            tw.WriteLine("{0} Parameter Fmin      ", FMin);
            tw.WriteLine("{0} Parameter crox        ", COx);
            tw.WriteLine("{0} Parameter cron        ", COn);
            tw.WriteLine("{0} Parameter cl        ", cL);
            tw.WriteLine("{0} Parameter cn        ", cN);
            tw.WriteLine("{0} Output File Name    ", oFile);
            tw.WriteLine("Number of replications" + "\t" + "{0}", noRep);
            tw.WriteLine("");
            #endregion
            AvgVal = new ArrayList[noRep];

            for (int i = 0; i < noRep; i++)
            {
                rSeed++;
                AvgVal[i] = new ArrayList();
                Console.WriteLine("Replication {0}", i + 1);
                tw.WriteLine("Replication {0}", i + 1);
                // get the starting time from CPU clock
                start = DateTime.Now;
                // main program ...
                M2DE GlobalPop = new spM2DE(noVec, noIter, noNB, FMax, FMin, COx, COn, Dimension, JD, maxE, moveStrategy, vMix, TopEp, BotEp, GapUnexplore);
                GlobalPop.SetRSeed(rSeed);
                GlobalPop.Run(tw, true, aniEnable, AvgVal[i], out sAni, out sAni2);
                // get the finishing time from CPU clock
                finish  = DateTime.Now;
                elapsed = finish - start;
                // display the elapsed time in hh:mm:ss.milli
                tw.WriteLine("{0} is the computational time", elapsed.Duration());
                tw.WriteLine("");
                if (i == 0)
                {
                    PFront = GlobalPop.ElististP;
                }
            }
            tw.Close();
            #region Finalize animation data
            Average = new ArrayList();
            index   = new double[AvgVal[0].Count];
            for (int i = 0; i < AvgVal[0].Count; i++)
            {
                index[i] = (double)i;
            }
            for (int o = 0; o < ((double[])(AvgVal[0])[0]).Length; o++)
            {
                double[] Avg = new double[AvgVal[0].Count];
                for (int i = 0; i < AvgVal[0].Count; i++)
                {
                    Avg[i] = (double)(((double[])(AvgVal[0])[i])[o]);
                }
                Average.Add(Avg);
            }
            Pareto = PFront;
            Ani    = sAni;
            AniS   = sAni2;
            #endregion
        }