Esempio n. 1
0
        public ISolution Start()
        {
            List <ISolutionPosSpeed> population    = problem.InitializeStart();
            ISolutionPosSpeed        globalOptimum = population.FirstOrDefault().LocalOptimum;

            population = problem.Evaluation(population, ref globalOptimum);
            while (!problem.CanStop())
            {
                population = problem.CalcualteVelocy(population, globalOptimum);
                foreach (var item in population)
                {
                    item.Position = item.Position.AddVelocy(item.Speed);
                }
                population = problem.Evaluation(population, ref globalOptimum);
            }

            Console.WriteLine();

            var best = globalOptimum.GetSolution(this.problem);

            Console.WriteLine(best.ToString());
            best.ConsoleWrite();
            Console.WriteLine("Fitnesz: " + this.problem.Fitness(globalOptimum));

            return(best);
        }
        public int Fitness(ISolutionPosSpeed solutionIn)
        {
            
            ISolution solution = solutionIn.GetSolution(this);

            int fitnes = 0;
            foreach (var item in solution.GetSolutionPairs())
            {
                fitnes += GetFitnessForSolutionPair(item, solution.GetSolutionPairs());
            }

            var wms = solution.GetSolutionPairs().GroupBy(x => x.WorkerMan);
            int overWork = 0;
            foreach (var item in wms)
            {
                overWork += GetOverWorkAllTimeForWorker(item.Key, solution.GetSolutionPairs());
            }

            if (overWork > 0)
            {
                fitnes += overWork * 10;
            }

            return fitnes;
        }
Esempio n. 3
0
 public SolutionPosSpeed(int numberOfJobs, int numberOfWorkers, SolutionPosSpeed localOptimum)
 {
     Position     = new PositionPS(numberOfJobs, numberOfWorkers);
     Speed        = new Velocy(numberOfJobs, numberOfWorkers);
     LocalOptimum = localOptimum;
 }
        public List<ISolutionPosSpeed> Evaluation(List<ISolutionPosSpeed> population, ref ISolutionPosSpeed globalOptimum)
        {
            List<ISolutionPosSpeed> newPop = new List<ISolutionPosSpeed>(); 
            foreach (var item in population)
            {
                var temp = item;
                int fitnesItem = this.Fitness(temp);

                //TODO Megkérdezni, hogy erre miért van szükség, felesleg munka csupán!!!
                if (fitnesItem < this.Fitness(temp.LocalOptimum))
                {

                    temp.LocalOptimum = new SolutionPosSpeed(
                        new PositionPS((temp.Position as PositionPS).GetPosition(), this.workerMens.Length),
                        new Velocy(this.workerMens.Length, (temp.Speed as Velocy).GetVelocy())
                        );
                    Console.WriteLine("Fitnessz kisebb, mint a lokális optimumé, Round" + this.maxIterations);
                }

                if (fitnesItem < this.Fitness(globalOptimum))
                {
                    Console.WriteLine("Fitnessz kisebb, mint a GLOBÁLIS optimumé, Round: " + this.maxIterations);
                    globalOptimum = new SolutionPosSpeed(
                        new PositionPS((temp.Position as PositionPS).GetPosition(), this.workerMens.Length),
                        new Velocy(this.workerMens.Length, (temp.Speed as Velocy).GetVelocy())
                        );

                }

                newPop.Add(new SolutionPosSpeed(
    new PositionPS((temp.Position as PositionPS).GetPosition(), this.workerMens.Length),
    new Velocy(this.workerMens.Length, (temp.Speed as Velocy).GetVelocy()))
                { LocalOptimum = temp.LocalOptimum });
            }
            return newPop;
        }
        public List<ISolutionPosSpeed> CalcualteVelocy(List<ISolutionPosSpeed> population, ISolutionPosSpeed globalOptimum)
        {
            List<ISolutionPosSpeed> newPop = new List<ISolutionPosSpeed>();
            foreach (var item in population)
            {
                var rp = random.NextDouble() * 1001; //0...1
                var rg = random.NextDouble() *1001;

                double w = 4;
                double omegap = 5;
                double omegag = 4;

                var temp = item;
                temp.Speed = temp.Speed
                    .Multiple(w)
                    .Add(item.LocalOptimum.Position.Minus(item.Position).Multiple(omegap).Multiple(rp))
                    .Add(globalOptimum.Position.Minus(item.Position).Multiple(omegag).Multiple(rg));

                newPop.Add(new SolutionPosSpeed(
                    new PositionPS((temp.Position as PositionPS).GetPosition(), this.workerMens.Length),
                    new Velocy(this.workerMens.Length, (temp.Speed as Velocy).GetVelocy()))
                {  LocalOptimum = temp.LocalOptimum});
            }
            return newPop;
        }