Exemple #1
0
 public spPSO(int nPar, int nIter, int nNB, double dwmax, double dwmin, double dcp, double dcg, double dcl, double dcn, int dim, JSPdata jd, int sRi, int Rii, int sLS, int LSi) :
     base(nIter, nNB, dwmax, dwmin, dcp, dcg, dcl, dcn, dim, sRi, Rii, sLS, LSi)
 {
     base.SetDimension(nPar, dim);
     JD = new JSPdata(jd.NoJob, jd.NoMc, jd.NoOp, jd.Job, jd.NoOpPerMc, jd.Machine);
 }
        public static double[] InterExchangeCirticalPath(int NoJob, int NoMc, int[] NoOp, int[] NoOpPerMc,
                                                         int Dimension, double[] Position, double FitValue, machine[] Machine, job[] Job, ref Random RandomNum, ref JSPdata JD)
        {
            ArrayList Pair1   = new ArrayList(); //forward
            ArrayList Pair2   = new ArrayList();
            ArrayList Pair1BW = new ArrayList(); //backward
            ArrayList Pair2BW = new ArrayList();

            FitValue = FitnessValue.FitnessValueScheduleGJSP(NoJob, NoMc, NoOp, Position, Job, Dimension, NoOpPerMc, Machine, JD);
            CirticalPath(NoJob, NoMc, NoOp, NoOpPerMc, Machine, Job, ref Pair1, ref Pair2, ref Pair1BW, ref Pair2BW, ref RandomNum); //get possible pairs by defining a path (blocks)

            double[] AdjPosition    = new double[Dimension];
            double[] MinAdjPosition = new double[Dimension];
            double   AdjFitValue    = 0;
            double   MinAdjFitValue = FitValue;

            for (int i = 0; i < Dimension; i++)
            {
                MinAdjPosition[i] = Position[i];
            }

            int NoPair = Pair1.Count; //forward

            for (int l = 0; l < NoPair; l++)
            {
                int Locate1 = (int)Pair1[l];
                int Locate2 = (int)Pair2[l];
                if (Locate1 < Locate2) //"Locate1>Locate2" means leaps frogging Locate1 over Locate2 (Active Schedule)//
                {
                    for (int i = 0; i < Dimension; i++)
                    {
                        AdjPosition[i] = Position[i];
                    }
                    InterExchangeAPair(Dimension, ref AdjPosition, Locate1, Locate2);//InterExchange one pair to the position
                    AdjFitValue = FitnessValue.FitnessValueScheduleGJSP(NoJob, NoMc, NoOp, AdjPosition, Job, Dimension, NoOpPerMc, Machine, JD);

                    if (AdjFitValue < MinAdjFitValue)
                    {
                        MinAdjFitValue = AdjFitValue;
                        for (int i = 0; i < Dimension; i++)
                        {
                            MinAdjPosition[i] = AdjPosition[i];
                        }
                    }
                }
            }

            int NoPairBW = Pair1BW.Count; //backward

            for (int l = 0; l < NoPairBW; l++)
            {
                int Locate1 = (int)Pair1BW[l];
                int Locate2 = (int)Pair2BW[l];
                if (Locate1 < Locate2) //"Locate1>Locate2" means leaps frogging Locate1 over Locate2 (Active Schedule)//
                {
                    for (int i = 0; i < Dimension; i++)
                    {
                        AdjPosition[i] = Position[i];
                    }
                    InterExchangeAPairBW(Dimension, ref AdjPosition, Locate1, Locate2);//InterExchange one pair to the position
                    AdjFitValue = FitnessValue.FitnessValueScheduleGJSP(NoJob, NoMc, NoOp, AdjPosition, Job, Dimension, NoOpPerMc, Machine, JD);

                    if (AdjFitValue < MinAdjFitValue)
                    {
                        MinAdjFitValue = AdjFitValue;
                        for (int i = 0; i < Dimension; i++)
                        {
                            MinAdjPosition[i] = AdjPosition[i];
                        }
                    }
                }
            }

            return(MinAdjPosition);
        }
Exemple #3
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();
        }
Exemple #4
0
        //Evaluate Multi Objective Function
        public static double FitnessValueScheduleGJSP(int NoJob, int NoMc, int[] NoOp, double[] rPosition, job[] Job, int Dimension, int[] NoOpPerMc, machine[] Machine, JSPdata JD)
        {
            double[] Position = new double[Dimension];
            for (int i = 0; i < Dimension; i++)
            {
                Position[i] = rPosition[i];
            }
            int[] DimensionArray = new int[Dimension];  //Create Dimension Array to be sorted.
            PositionAdjust.SortingListRuleOnPosition(JD.NoJob, JD.NoOp, Dimension, ref Position, ref DimensionArray);
            //rescale position
            for (int i = 0; i < Dimension; i++)
            {
                rPosition[DimensionArray[i]] = (double)i * (1 / (double)Dimension);
            }
            //end rescale
            DecodeActiveSchedule.OprBasedDecodeActiveSchd(NoJob, NoMc, Position, Job, Dimension, NoOpPerMc, Machine);
            double ObjFn  = 0;
            double ObjFn2 = 0;
            double ObjFn3 = 0;
            double ObjFn4 = 0;

            ObjFn  = Cmax2(NoMc, NoOpPerMc, Machine);
            ObjFn2 = MaxWeightTardiness(NoJob, NoOp, Job);
            ObjFn3 = MaxWeightEarliness(NoJob, NoOp, Job);
            ObjFn4 = 0.4 * ObjFn + 0.3 * ObjFn2 + 0.3 * ObjFn3;
            return(ObjFn);
            //ObjFn2;
            //ObjFn3;
            //ObjFn4;
        }