Ejemplo n.º 1
0
        /// <summary>
        /// 能力差距计算函数
        /// </summary>
        /// <returns>返回能力差距</returns>
        public ablity coaRequireCheck(List <CoaMembers> coaGroup)
        {
            float x, y;

            x = y = 0;
            ablity a;

            a = new ablity();

            for (int i = 0; i < coaGroup.Count; i++)
            {
                x += coaGroup[i].agent.abilityA.ablityX;
                y += coaGroup[i].agent.abilityA.ablityY;
            }
            if (x < requirement.ablityX || y < requirement.ablityY)
            {
                a.ablityX = requirement.ablityX - x;
                a.ablityY = requirement.ablityY - y;
            }
            else
            {
                a.ablityX = 0;
                a.ablityY = 0;
            }
            return(a);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 联盟组队优化选择
        /// 考虑移动成本和到达时间进行选择
        /// </summary>
        public bool CoalitionOptimization(Task task, int step)
        {
            bool       flag = false;
            CoaMembers newCoalitionAgent = new CoaMembers();

            coaMembers = new List <CoaMembers>(0);
            //当备选智能体
            if (CoaAbilityCheck(task.pre_members))
            {
                do
                {
                    //获取新添加的智能体的ID
                    newCoalitionAgent = AddAgent(coaMembers, task.pre_members);
                    if (newCoalitionAgent == null)
                    {
                        return(false);
                    }
                    if (newCoalitionAgent.agent == null)
                    {
                        return(false);
                    }
                    if (!IsAgentInCoalition(coaMembers, newCoalitionAgent.agent))
                    {
                        newCoalitionAgent.agent.taskTaken = task;
                        coaMembers.Add(newCoalitionAgent);
                        pre_members.Remove(newCoalitionAgent);
                        flag = CoaAbilityCheck(coaMembers);
                        //如果联盟能力超过了要求,则进行联盟分解
                        if (!flag)
                        {
                            ablity ab = coaRequireCheck(coaMembers);
                            if (pre_members.Count != 0 && (ab.ablityX > requirement.ablityX || ab.ablityY > requirement.ablityY))
                            {
                                newCoalitionAgent = Split(coaMembers);
                                coaMembers.Remove(newCoalitionAgent);
                            }
                            //else
                            //    start_time = step + period_time;
                        }
                    }
                } while (!flag);
            }
            else
            {
                call_time = step + 1;
            }
            return(true);
        }