Example #1
0
        // Returns the AID of the first found service provider
        public static AID FindService(string serviceName, Agent myAgent, int timeOut)
        {
            AID providerAID = null;
            bool found = false;

            double t1 = PerformanceCounter.GetValue();
            while (!found)
            {
                if (PerformanceCounter.GetValue() - t1 > timeOut)
                    break;

                Application.DoEvents();

                // search for a provider
                DFAgentDescription template = new DFAgentDescription();
                ServiceDescription sd = new ServiceDescription();
                sd.setType(serviceName);
                template.addServices(sd);

                DFAgentDescription[] result = DFService.search(myAgent, template);
                if (result != null && result.Length > 0)
                {
                    providerAID = result[0].getName();
                    found = true;
                }
            }

            return providerAID;
        }
        //TODO - Refactor to support list of service names
        public static List <AID> Find(string serviceName, Agent myAgent)
        {
            var providers = new List <AID>();
            var found     = false;

            while (!found)
            {
                var template = new DFAgentDescription();
                var sd       = new ServiceDescription();
                sd.setType(serviceName);
                template.addServices(sd);

                DFAgentDescription[] result = DFService.search(myAgent, template);

                if (result == null || result.Length <= 0)
                {
                    continue;
                }

                foreach (var t in result)
                {
                    providers.Add(t.getName());
                    found = true;
                }
            }

            return(providers);
        }
Example #3
0
    private bool canAgentBeRequested(DFAgentDescription agentDescription)
    {
        var acceptableStatuses = new ScheduledJob.Status[] { ScheduledJob.Status.Requested, ScheduledJob.Status.Confirmed }.ToList();
        List <ScheduledJob> jobsOfGivenAgent = coordinatorAgent.ScheduledJobs.FindAll(job => job.AgentId.Equals(agentDescription.AgentId));
        List <ScheduledJob> activeJobs       = jobsOfGivenAgent.FindAll(job => acceptableStatuses.Contains(job.JobStatus));

        return(activeJobs.Count == 0);
    }
Example #4
0
 // Registers a service on behalf of an agent
 public static void RegisterService(string serviceName, Agent myAgent)
 {
     DFAgentDescription dfd = new DFAgentDescription();
     dfd.setName(myAgent.getAID());
     ServiceDescription sd = new ServiceDescription();
     sd.setType(serviceName);
     sd.setName(serviceName);
     dfd.addServices(sd);
     DFService.register(myAgent, dfd);
 }
        public static void Register(string serviceName, Agent myAgent)
        {
            var dfd = new DFAgentDescription();

            dfd.setName(myAgent.getAID());
            var sd = new ServiceDescription();

            sd.setType(serviceName);
            sd.setName(serviceName);
            dfd.addServices(sd);
            DFService.register(myAgent, dfd);
        }
Example #6
0
        // -----------------------

        private void registerChaseService()
        {
            DFAgentDescription dfAgentDescription = new DFAgentDescription();

            dfAgentDescription.AgentId = AId;
            DFServiceDescription serviceDescription = new DFServiceDescription();

            serviceDescription.Type = ChaseVocabulary.CHASE_TYPE;
            serviceDescription.Name = ChaseVocabulary.CHASE_SERVICE;
            dfAgentDescription.AddService(serviceDescription);
            DFService.RegisterService(this, dfAgentDescription);
        }
    protected override void Action()
    {
        DFAgentDescription dfAgentDescription = new DFAgentDescription();

        dfAgentDescription.AgentId = Agent.AId;
        DFServiceDescription collectWoodServiceDescription = new DFServiceDescription();

        collectWoodServiceDescription.Type = WorkVocabulary.WORK;
        collectWoodServiceDescription.Name = WorkVocabulary.COLLECT_WOOD_SERVICE;
        DFServiceDescription collectStoneServiceDescription = new DFServiceDescription();

        collectStoneServiceDescription.Type = WorkVocabulary.WORK;
        collectStoneServiceDescription.Name = WorkVocabulary.COLLECT_STONE_SERVICE;
        dfAgentDescription.AddService(collectStoneServiceDescription);
        dfAgentDescription.AddService(collectWoodServiceDescription);
        DFService.RegisterService(Agent, dfAgentDescription);
    }
Example #8
0
    override protected void Action()
    {
        DFAgentDescription   dfAgentDescription = new DFAgentDescription();
        DFServiceDescription serviceDescription = new DFServiceDescription();

        serviceDescription.Type = WorkVocabulary.WORK;
        serviceDescription.Name = WorkVocabulary.COLLECT_STONE_SERVICE;
        dfAgentDescription.AddService(serviceDescription);
        Action <AgentDescriptionListConcept> action = delegate(AgentDescriptionListConcept concept) {
            List <DFAgentDescription> agents = concept.AgentDescriptions.FindAll(agentDescription => canAgentBeRequested(agentDescription));

            if (agents.Count != 0)
            {
                requestCollectingStone(agents.First().AgentId);
            }
        };

        DFService.RequestSearch(coordinatorAgent, dfAgentDescription, action);
    }
Example #9
0
        override protected void Action()
        {
            DFAgentDescription   dfAgentDescription = new DFAgentDescription();
            DFServiceDescription serviceDescription = new DFServiceDescription();

            serviceDescription.Type = ChaseVocabulary.CHASE_TYPE;
            serviceDescription.Name = ChaseVocabulary.CHASE_SERVICE;
            dfAgentDescription.AddService(serviceDescription);
            Action <AgentDescriptionListConcept> action = delegate(AgentDescriptionListConcept concept) {
                foreach (DFAgentDescription agentDescription in concept.AgentDescriptions)
                {
                    AgentMessage message = new AgentMessage(AgentMessage.PerformativeType.INFORM);
                    message.Receiver = agentDescription.AgentId;
                    message.Ontology = ChaseVocabulary.CHASE_ONTOLOGY;
                    message.Content  = new PlayerPositionConcept(position);
                    Agent.Send(message);
                }
            };

            DFService.RequestSearch(Agent, dfAgentDescription, action);
        }
Example #10
0
 public RegisterServiceAction(DFAgentDescription agentDescription)
 {
     this.AgentDescription = agentDescription;
 }
 public SearchForServiceAction(AgentId agentId, DFAgentDescription agentDescription)
 {
     this.AgentDescription = agentDescription;
     this.AgentId          = agentId;
 }