Exemplo n.º 1
0
        public Bee CreateBee(int employeesNumber)
        {
            var sorted = _factory.EmployeesList.OrderBy(o => o.Abilities).ToList();
            Bee bee    = new Bee();

            for (int i = 0; i < employeesNumber; i++)
            {
                var       tempList         = new List <int>();
                var       tempMachinesList = new List <Machines>();
                Employees employee         = sorted[i];
                for (int u = 0; u < employee.VectorOfAbilities.Length; u++)
                {
                    if (employee.VectorOfAbilities[u] == '1')
                    {
                        tempList.Add(u);
                        tempMachinesList.Add(_factory.MachinesList[u]);
                    }
                }
                tempMachinesList.RemoveAll(item => bee.Trail.Keys.ToList().Contains(item));
                if (tempMachinesList.Count != 0)
                {
                    bee.Trail.Add(tempMachinesList[_randomNumber.Next(tempMachinesList.Count)], employee);
                }
                else
                {
                    bee = CreateBee(employeesNumber);
                }
            }
            bee.Profit = bee.Profit = ObjectiveFunctionCounter_1.CountValueOfTheFunction(bee, 11, 2);

            return(bee);
        }
Exemplo n.º 2
0
        public Bee SearchBetterTrail(Bee bee)
        {
            Bee newBee           = new Bee(bee.Trail);
            int counter          = 0;
            var trailList        = bee.Trail.ToList();
            int k1               = _randomNumber.Next(trailList.Count);
            var machine_1_Number = _factory.MachinesList.IndexOf(trailList[k1].Key);
            var employeesListAbleToWorkOnMachine_1 = _factory.EmployeesList.FindAll(
                s => s.VectorOfAbilities[machine_1_Number] == '1' && s.EmployeeID != trailList[k1].Value.EmployeeID);
            int k2               = _randomNumber.Next(employeesListAbleToWorkOnMachine_1.Count);
            var machine_2        = trailList.Find(s => s.Value.EmployeeID == employeesListAbleToWorkOnMachine_1[k2].EmployeeID).Key;
            int machine_2_Number = _factory.MachinesList.IndexOf(machine_2);

            while (trailList[k1].Value.VectorOfAbilities[machine_2_Number] != '1' && counter < employeesListAbleToWorkOnMachine_1.Count)
            {
                k2 = _randomNumber.Next(employeesListAbleToWorkOnMachine_1.Count);
                while (k1 == k2)
                {
                    k2 = _randomNumber.Next(employeesListAbleToWorkOnMachine_1.Count);
                }
                machine_2        = trailList.Find(s => s.Value.EmployeeID == employeesListAbleToWorkOnMachine_1[k2].EmployeeID).Key;
                machine_2_Number = _factory.MachinesList.IndexOf(machine_2);
                counter++;
            }
            if (counter != employeesListAbleToWorkOnMachine_1.Count)
            {
                newBee.Trail.Remove(trailList[k1].Key);
                newBee.Trail.Remove(machine_2);
                newBee.Trail.Add(trailList[k1].Key, employeesListAbleToWorkOnMachine_1[k2]);
                newBee.Trail.Add(machine_2, trailList[k1].Value);
                var Trail_1 = newBee.Trail.ToList();
                Trail_1.OrderBy(o => o.Value.Abilities);
                var c = newBee.Trail.OrderBy(o => o.Value.Abilities);
                newBee.Trail  = c.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
                newBee.Profit = ObjectiveFunctionCounter_1.CountValueOfTheFunction(newBee, 11, 3);
            }

            return(newBee.Profit > bee.Profit ? newBee : bee);
        }