コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter number of elements: ");
            int num = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter size of population: ");
            int pop = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter set id: ");
            string setID = Convert.ToString(Console.ReadLine());

            Console.WriteLine("Enter end time in seconds: ");
            int timmy = Convert.ToInt32(Console.ReadLine());
            //Console.WriteLine("Enter smooth parameter: ");
            //double smooth = Convert.ToDouble(Console.ReadLine());
            //Console.WriteLine("Enter evaporate parameter: ");
            //double eva = Convert.ToDouble(Console.ReadLine());
            AcoMaster aco = new AcoMaster();

            aco.endVar = new TimeSpan(0, 0, timmy);
            Console.WriteLine(setID);
            aco.setID = (setID);
            aco.SetData(num);
            aco.Init(num, pop, 6.5, 0.05);
            Console.WriteLine("Click any key to continue..");
            Console.ReadLine();
        }
コード例 #2
0
        public void TransferWithRoulette(InstationGenerator tmp, AcoMaster tmr)
        {
            ArrayList trs = new ArrayList();

            foreach (Entity el in elements)
            {
                Entity a = (Entity)el.Clone();
                trs.Add(a);
            }
            tmp.CreateNewInstantion(trs, maintances, true, tmr);
        }
コード例 #3
0
 private void FillSecondMachine(ArrayList secondMachineTasks, ArrayList secondMachineTempMaintance, Machine secondMachine, ArrayList firstMachineTasks, bool usingTable, int tableEl, AcoMaster ACO)
 {
     if (usingTable == true)
     {
         Random rnd = new Random();
         while (secondMachineTasks.Count > 0)
         {
             TimeSpan span      = new TimeSpan(0, 0, 0);
             TimeSpan perc      = (span = DateTime.Now - MyTimer.Start);
             double   ft        = span.Seconds;
             double   sc        = ACO.endVar.Seconds + (60 * ACO.endVar.Minutes);
             int      holder    = (int)((ft / sc) * 100);
             int      roultette = rnd.Next(0, 100);
             int      pos       = 0;
             if (roultette < holder)
             {
                 int a    = secondMachine.GetLastElementID();
                 int take = WhichElementIShouldTake(ACO.arrx2, a);
                 if (IsPossibleToTakeFromList(secondMachineTasks, take) == true)
                 {
                     pos = GetPositionAtList(take, secondMachineTasks);
                 }
                 else
                 {
                     take = WhichElementIShouldTake(ACO.arrx2, a);
                     if (IsPossibleToTakeFromList(secondMachineTasks, take) == true)
                     {
                         pos = GetPositionAtList(take, secondMachineTasks);
                     }
                     else
                     {
                         pos = 0;
                     }
                 }
             }
             else
             {
                 pos = 0;
             }
             Entity element = (Entity)secondMachineTasks[pos];
             bool   added   = false;
             while (!added)
             {
                 if (GetEndTimeOfPair(firstMachine.getMachineList(), element.GetOperationID()) < secondMachine.GetLastEndTime())
                 {
                     if (secondMachineTempMaintance.Count != 0 && getTimeOfNextMaintance(secondMachineTempMaintance) <= (secondMachine.GetLastEndTime() + element.GetTime()))
                     {
                         Entity maint = (Entity)secondMachineTempMaintance[0];
                         if (maint.GetStartTime() > secondMachine.GetLastEndTime())
                         {
                             Entity idle = new Entity(2, 0, 0, 1, 0, 0, 0);
                             idle.SetStartTime(secondMachine.GetLastEndTime() + 1);
                             idle.SetTime(maint.GetStartTime() - secondMachine.GetLastEndTime());
                             idle.SetEndTime(idle.GetStartTime() + idle.GetTime());
                             secondMachine.AddElement(idle);
                         }
                         secondMachine.AddElement(maint);
                         secondMachineTempMaintance.Remove(maint);
                     }
                     else
                     {
                         element.SetStartTime(secondMachine.GetLastEndTime() + 1);
                         element.SetEndTime(element.GetStartTime() + element.GetTime());
                         secondMachine.AddElement(element);
                         secondMachineTasks.Remove(element);
                         added = true;
                     }
                 }
                 else
                 {
                     if (secondMachineTempMaintance.Count != 0 &&
                         getTimeOfNextMaintance(secondMachineTempMaintance) < (element.GetTime() + GetEndTimeOfPair(firstMachine.getMachineList(), element.GetOperationID())))
                     {
                         Entity maint = (Entity)secondMachineTempMaintance[0];
                         if (maint.GetStartTime() > secondMachine.GetLastEndTime())
                         {
                             Entity idle = new Entity(2, 0, 0, 1, 0, 0, 0);
                             idle.SetStartTime(secondMachine.GetLastEndTime() + 1);
                             idle.SetTime(maint.GetStartTime() - secondMachine.GetLastEndTime());
                             idle.SetEndTime(idle.GetStartTime() + idle.GetTime());
                             secondMachine.AddElement(idle);
                         }
                         element.SetStartTime(secondMachine.GetLastEndTime() + 1);
                         element.SetEndTime(element.GetStartTime() + element.GetTime());
                         secondMachine.AddElement(maint);
                         secondMachineTempMaintance.Remove(maint);
                     }
                     else
                     {
                         if (GetEndTimeOfPair(firstMachine.getMachineList(), element.GetOperationID()) > secondMachine.GetLastEndTime())
                         {
                             Entity idle = new Entity(2, 0, 0, 1, 0, 0, 0);
                             idle.SetStartTime(secondMachine.GetLastEndTime() + 1);
                             idle.SetTime(GetEndTimeOfPair(firstMachine.getMachineList(), element.GetOperationID()) - secondMachine.GetLastEndTime());
                             idle.SetEndTime(idle.GetStartTime() + idle.GetTime());
                             secondMachine.AddElement(idle);
                         }
                         element.SetStartTime(secondMachine.GetLastEndTime() + 1);
                         element.SetEndTime(element.GetStartTime() + element.GetTime());
                         secondMachine.AddElement(element);
                         secondMachineTempMaintance.Remove(element);
                         added = true;
                     }
                 }
             }
         }
     }
     else
     {
     }
 }
コード例 #4
0
        public void CreateNewInstantion(ArrayList fullList, ArrayList maintances, bool roulette, AcoMaster ACO)
        {
            firstMachine = new Machine();
            firstMachine.SetMachineNumber(0);
            firstMachine.SetNumberOfElements(size);
            secondMachine = new Machine();
            ArrayList firstMachineTemp           = new ArrayList();
            ArrayList secondMachineTemp          = new ArrayList();
            ArrayList firstMachineTempMaintance  = new ArrayList();
            ArrayList secondMachineTempMaintance = new ArrayList();
            Random    r           = new Random();
            int       randomIndex = 0;

            foreach (Entity element in fullList)
            {
                if (element.GetMachine() == 0)
                {
                    firstMachineTemp.Add(element);
                }
                else
                {
                    secondMachineTemp.Add(element);
                }
            }
            foreach (Entity element in maintances)
            {
                if (element.GetMachine() == 0)
                {
                    firstMachineTempMaintance.Add(element);
                }
                else
                {
                    secondMachineTempMaintance.Add(element);
                }
            }
            while (firstMachineTemp.Count > 0)
            {
                randomIndex = r.Next(0, firstMachineTemp.Count);      //Choose a random object in the list
                firstMachineTasks.Add(firstMachineTemp[randomIndex]); //add it to the new, random list
                firstMachineTemp.RemoveAt(randomIndex);               //remove to avoid duplicates
            }
            while (secondMachineTemp.Count > 0)
            {
                randomIndex = r.Next(0, secondMachineTemp.Count);       //Choose a random object in the list
                secondMachineTasks.Add(secondMachineTemp[randomIndex]); //add it to the new, random list
                secondMachineTemp.RemoveAt(randomIndex);                //remove to avoid duplicates
            }
            //Console.WriteLine("SHUFFLE DONE!");
            if (roulette == false)
            {
                FillFirstMachine(firstMachineTasks, firstMachineTempMaintance, firstMachine, false, 0, ACO);
                FillSecondMachine(secondMachineTasks, secondMachineTempMaintance, secondMachine, firstMachineTasks, false, 0, ACO);
            }
            else if (roulette == true)
            {
                FillFirstMachine(firstMachineTasks, firstMachineTempMaintance, firstMachine, true, 0, ACO);
                FillSecondMachine(secondMachineTasks, secondMachineTempMaintance, secondMachine, firstMachineTasks, true, 0, ACO);
            }
            //Console.WriteLine("FILLING DONE!");
            //PrintFirstMachine();

            //PrintSecondMachine();
        }