private int GetFitnessForSolutionPair(ISolutionPair pair, List<ISolutionPair> solutionPairs)
        {
            WorkerMan workerMan = pair.WorkerMan;
            WorkToDo workToDo = pair.WorkToDo;
            return (workerMan.WorkingTimeByComplexity(workToDo.Complexity) / workerMan.Quality); // idő/minőség = fitnessz

        }
Beispiel #2
0
        public ISolution CrossOver(IEnumerable <ISolution> parents)
        {
            List <ISolutionPair> solutionPairs = new List <ISolutionPair>();
            int numberOfJobs = parents.FirstOrDefault().GetSolutionPairs().Count;

            int[] numberOfOccurance = new int[this.workerMens.Length];


            for (int i = 0; i < numberOfJobs; i++)
            {
                WorkToDo workToDo = this.workToDos[i];

                foreach (var item in parents)
                {
                    var current = item.GetSolutionPairs().Where(x => x.WorkToDo == workToDo).FirstOrDefault();
                    var man     = current.WorkerMan;

                    var index = 0;
                    for (int k = 0; k < this.workerMens.Length; k++)
                    {
                        if (this.workerMens[k] == man)
                        {
                            index = k;
                            k     = this.workerMens.Length + 2;
                        }
                    }

                    numberOfOccurance[index]++;
                }

                int maximum  = numberOfOccurance.Where(x => x == numberOfOccurance.Max()).FirstOrDefault();
                int maxIndex = 0;
                for (int o = 0; o < numberOfOccurance.Length; o++)
                {
                    if (numberOfOccurance[o] == maximum)
                    {
                        maxIndex = o;
                        o        = numberOfOccurance.Length + 2;
                    }
                }


                WorkerMan manCurrent = this.workerMens[maxIndex];

                solutionPairs.Add(new SolutionPair()
                {
                    WorkerMan = manCurrent, WorkToDo = workToDo
                });
            }

            return(new Solution()
            {
                SolutionPairs = solutionPairs
            });
        }
        private int GetOverWorkAllTimeForWorker(WorkerMan worker, List<ISolutionPair> solutionPairs)
        {
            int all = 0;
            foreach (var item in solutionPairs)
            {
                if (item.WorkerMan == worker)
                {
                    all += worker.WorkingTimeByComplexity(item.WorkToDo.Complexity);
                }
            }

            if (worker.WorkingMinutes < all)
            {
                return all - worker.WorkingMinutes;
            }

            return 0;
        }