コード例 #1
0
ファイル: Gen.cs プロジェクト: jonaRdrgz/Proyecto_IA_2
        public void Mutation(List <RequestedService> pRequestedServiceList)
        {
            int lengthGen = Gen1.Count;

            for (int i = 0; i < lengthGen; i++)
            {
                if (random.Next(100) <= MutationProbability)
                {
                    Service service = GetServiceValues(pRequestedServiceList.ElementAt(i).ServiceCode);

                    Agent agentToReplace = Gen1.ElementAt(i);
                    Agent newAgent       = AgentesByServiceDictionary[service.Code].ElementAt(random.Next(AgentesByServiceDictionary[service.Code].Count));

                    agentToReplace.JobCounter       -= 1;
                    agentToReplace.WorkTime         -= service.Time;
                    agentToReplace.EarnedCommission -= service.Commission;
                    agentToReplace.IsBusy            = agentToReplace.JobCounter == 0 ? false : true;

                    newAgent.JobCounter       += 1;
                    newAgent.WorkTime         += service.Time;
                    newAgent.EarnedCommission += service.Commission;
                    newAgent.IsBusy            = true;

                    Gen1[i] = newAgent;
                }
            }
        }
コード例 #2
0
ファイル: Gen.cs プロジェクト: jonaRdrgz/Proyecto_IA_2
        //mutacion por si algún agente queda sin trabajito :(
        public void ManipulatedMutation(List <RequestedService> pRequestedServiceList)
        {
            List <Agent> agentIsNotBusy = (from agent in AgentList
                                           where agent.JobCounter < 1
                                           select agent).ToList();

            foreach (Agent agent in agentIsNotBusy.AsEnumerable())
            {
                Agent agentToReplace = (from ag in Gen1
                                        where ag.ServiceList.Intersect(agent.ServiceList).Any() && ag.JobCounter > 1
                                        select ag).OrderByDescending(x => x.JobCounter).FirstOrDefault();

                for (int i = 0; i < pRequestedServiceList.Count; i++)
                {
                    if (Gen1.ElementAt(i).ID == agentToReplace.ID && agent.ServiceList.Contains(pRequestedServiceList.ElementAt(i).ServiceCode))
                    {
                        Service service = GetServiceValues(pRequestedServiceList.ElementAt(i).ServiceCode);

                        agentToReplace.JobCounter       -= 1;
                        agentToReplace.WorkTime         -= service.Time;
                        agentToReplace.EarnedCommission -= service.Commission;
                        agentToReplace.IsBusy            = agentToReplace.JobCounter == 0 ? false : true;

                        agent.JobCounter       += 1;
                        agent.WorkTime         += service.Time;
                        agent.EarnedCommission += service.Commission;
                        agent.IsBusy            = true;

                        //Swap
                        Gen1[i] = agent;
                    }
                }
            }
        }