Exemple #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
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            #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 set PSO's parameters
            int    noPar  = 50;
            int    noIter = 1000;
            int    noNB   = 5;
            double wMax   = 0.9;
            double wMin   = 0.4;
            double cP     = 1.6;
            double cG     = 0;
            double cL     = 1.6;
            double cN     = 0;

            string oFile = "MyPSO.xls";

            double MigrateProp = 0.1;
            bool   multiSwarm  = false;
            int    noSwarm     = 5;

            int startReinit   = 1000000;
            int ReInitIterval = 1000;
            int startLS       = 100000;
            int LSinterval    = 100;
            #endregion

            //Number of replication
            int noRep = 30;
            // starting time and finish time using DateTime datatype
            DateTime start, finish;
            // elapsed time using TimeSpan datatype

            TimeSpan elapsed;
            #region createoutputFile
            // opening output file
            TextWriter tw = new StreamWriter(oFile);
            tw.WriteLine("{0} Number of Particle  ", noPar);
            tw.WriteLine("{0} Number of Iteration ", noIter);
            tw.WriteLine("{0} Number of Neighbor  ", noNB);
            tw.WriteLine("{0} Parameter wmax      ", wMax);
            tw.WriteLine("{0} Parameter wmin      ", wMin);
            tw.WriteLine("{0} Parameter cp        ", cP);
            tw.WriteLine("{0} Parameter cg        ", cG);
            tw.WriteLine("{0} Parameter cl        ", cL);
            tw.WriteLine("{0} Parameter cn        ", cN);
            tw.WriteLine("{0} Output File Name    ", oFile);
            tw.WriteLine("");
            #endregion

            for (int i = 0; i < noRep; i++)
            {
                tw.WriteLine("Replication {0}", i + 1);
                // get the starting time from CPU clock
                start = DateTime.Now;

                // main program ...
                PSO[] subSwarm = new PSO[noSwarm - 1];
                #region Activate sub-swarms
                if (multiSwarm)
                {
                    for (int s = 0; s < noSwarm - 1; s++)
                    {
                        Console.WriteLine("Start swarm {0}", s);
                        subSwarm[s] = new spPSO(noPar, noIter, noNB, wMax, wMin, cP, cG, cL, cN, Dimension, JD, startReinit, ReInitIterval, startLS, LSinterval);
                        if (s != 0)
                        {
                            subSwarm[s].Migrate(subSwarm[s - 1].sSwarm, subSwarm[s].sSwarm, MigrateProp);
                        }
                        subSwarm[s].Run(tw, true);

                        subSwarm[s].DisplayResult(tw);
                        Console.WriteLine("Obj {0} ", subSwarm[s].sSwarm.pParticle[subSwarm[s].sSwarm.posBest].ObjectiveP);
                    }
                }
                #endregion
                PSO globalSwarm = new spPSO(noPar, noIter, noNB, wMax, wMin, cP, cG, cL, cN, Dimension, JD, startReinit, ReInitIterval, startLS, LSinterval);
                Console.WriteLine("Start final swarm");
                Console.WriteLine("Replication {0}", i + 1);
                if (multiSwarm)
                {
                    for (int s = 0; s < noSwarm - 1; s++)
                    {
                        globalSwarm.MigrateBest(subSwarm[s].sSwarm, globalSwarm.sSwarm, 1 / ((double)noSwarm - 1));
                    }
                }
                globalSwarm.Run(tw, true);

                globalSwarm.DisplayResult(tw);
                Console.WriteLine("Obj {0} ", globalSwarm.sSwarm.pParticle[globalSwarm.sSwarm.posBest].ObjectiveP);
                // get the finishing time from CPU clock
                #region createreport
                finish  = DateTime.Now;
                elapsed = finish - start;

                // display the elapsed time in hh:mm:ss.milli
                tw.WriteLine("{0} is the computational time", elapsed.Duration());
                Console.WriteLine("{0} is the computational time", elapsed.Duration());
                tw.WriteLine("");
                #endregion
            }
            Console.ReadKey();
            tw.Close();
        }