Пример #1
0
        public override void action()
        {
            ACLMessage m = myAgent.receive();

            if (m != null)
            {
                string received = m.getContent();

                if (received.Contains("registered"))
                {
                    //manager registered me for the auction
                    myAgent.windowsForm.AddTextLine("Successfully registered for auction");
                }

                if(received.Contains("current_price"))
                {
                    // received new call from managerAgent

                    //the highest current price is:
                    int currentPrice = Convert.ToInt32(received.Remove(0, 13));
                    myAgent.windowsForm.AddTextLine("Received current price: " + currentPrice);

                    // probability to make offer decreases with each price increase
                    myAgent.probabilityToBid *= myAgent.probabilityDecreaseFactor;

                    ACLMessage toSend = new ACLMessage(ACLMessage.INFORM);
                    toSend.addReceiver(m.getSender());
                    //use agent name to generate unique seed for random numbers
                    int seed = 1234 * Convert.ToInt32(myAgent.getLocalName().Remove(0, 5));
                    //decide if to send new offer or retreat
                    if (myAgent.probabilityToBid > new Random(seed).NextDouble())
                    {
                        //make an offer which is higher than the current price
                        seed = 4321 * Convert.ToInt32(myAgent.getLocalName().Remove(0, 5));
                        int newPrice = currentPrice + new Random(seed).Next(1, myAgent.maxOfferIncrease);
                        toSend.setContent("offer" + newPrice);
                        myAgent.windowsForm.AddTextLine("Sent new offer: " + newPrice);
                    }
                    else
                    {
                        //price is too high, retreat from auction
                        toSend.setContent("retreat");
                        myAgent.windowsForm.AddTextLine("Retreated from auction.");
                    }
                    myAgent.send(toSend);
                }
            }
            else
                block();
        }
Пример #2
0
        public override void action()
        {
            ACLMessage aCLMessage = new ACLMessage(ACLMessage.INFORM);

            AID aID = null;

            if (args != null && args.Length == 1)
            {
                string name = args[0] as string;
                aID = new AID(name, AID.ISLOCALNAME);
            }
            else if (args != null && args.Length == 2)
            {
                string name = args[0] as string;
                string host = args[1] as string;
                aID = new AID(name+"@"+host+":1099/JADE", AID.ISGUID);
                aID.addAddresses("http://"+host+":7778/acc");
            }
            else
                aID = new AID("dummyReceiver", AID.ISLOCALNAME);

            aCLMessage.addReceiver(aID);
            aCLMessage.setSender(myAgent.getAID());
            aCLMessage.setContent("Prova contenuto");
            myAgent.send(aCLMessage);
            Console.WriteLine("AID is "+aID.getName());
            Console.WriteLine("Message sent");
            myAgent.doDelete();
        }
Пример #3
0
        public override void onTick()
        {
            int nParticipants = myAgent.participantList.Count;

            if (nParticipants > 1) // still more than 1 agent making offers
            {
                /* New auction round:
                 * send calls to the participants
                   inform them on current auction price
                   ask them to send new offers
                 */
                ACLMessage toSend = new ACLMessage(ACLMessage.INFORM);
                toSend.setContent("current_price" + myAgent.currentPrice);

                foreach (AID a in myAgent.participantList)
                    toSend.addReceiver(a);

                myAgent.send(toSend);

                myAgent.windowsForm.AddTextLine(Environment.NewLine + "New Round: current price is " + myAgent.currentPrice);
            }
            else if (nParticipants == 1) //only one agent left, the winner
            {
                AID winner = myAgent.currentWinner;
                myAgent.windowsForm.AddTextLine(Environment.NewLine + "Auction over. Winner is " + winner.getLocalName() + " with price: " + myAgent.currentPrice);
                this.stop();
            }
            else // no participants left
            {
                myAgent.windowsForm.AddTextLine(Environment.NewLine + "Auction over. All participants retreated.");
                this.stop();
            }
        }
Пример #4
0
        public override void action()
        {
            ACLMessage aCLMessage = new ACLMessage(ACLMessage.INFORM);

            AID aID = null;

            if (args != null && args.Length == 1)
            {
                string name = args[0] as string;
                aID = new AID(name, AID.ISLOCALNAME);
            }
            else if (args != null && args.Length == 2)
            {
                string name = args[0] as string;
                string host = args[1] as string;
                aID = new AID(name + "@" + host + ":1099/JADE", AID.ISGUID);
                aID.addAddresses("http://" + host + ":7778/acc");
            }
            else
            {
                aID = new AID("dummyReceiver", AID.ISLOCALNAME);
            }

            aCLMessage.addReceiver(aID);
            aCLMessage.setSender(myAgent.getAID());
            aCLMessage.setContent("Prova contenuto");
            myAgent.send(aCLMessage);
            Console.WriteLine("AID is " + aID.getName());
            Console.WriteLine("Message sent");
            myAgent.doDelete();
        }
Пример #5
0
        public override void action()
        {
            if (procAgent.needHelp == true)
            {
                ACLMessage messageToSend = new ACLMessage(ACLMessage.REQUEST);

                String content1 = String.Empty;
                String content2 = String.Empty;
                for (int index = 0; index < procAgent.matrix1ArrayRemained.Count; index++)
                {
                    content1 += procAgent.matrix1ArrayRemained[index] + " ";
                    content2 += procAgent.matrix2ArrayRemained[index] + " ";
                }
                content1 = content1 + "|" + content2;

                messageToSend.setContent(content1);
                messageToSend.addReceiver(Constants.dispAid);
                procAgent.send(messageToSend);
                // procAgent.needHelp = false;
            }
            if (Constants.helpersNeeded.ContainsKey(procAgent.getName()) && Constants.helpersNeeded[procAgent.getName()] == procAgent.helpersResults.Count() &&
                String.IsNullOrEmpty(procAgent.processorResult) == false && !procAgent.messageSent)
            {
                procAgent.JoinResults();

                procAgent.messageSent = true;
                ACLMessage messageToSend = new ACLMessage(ACLMessage.REQUEST);
                messageToSend.setContent(procAgent.messageForDistributor);
                messageToSend.addReceiver(Constants.distrAid);
                procAgent.send(messageToSend);
            }
        }
Пример #6
0
        public void SendMessage(AID to, object info, int type = ACLMessage.REQUEST)
        {
            var reply       = new ACLMessage(type);
            var receiverAid = new AID(to.getLocalName(), AID.ISLOCALNAME);

            reply.addReceiver(receiverAid);

            reply.setContent(JsonConvert.SerializeObject(info));
            send(reply);
        }
Пример #7
0
 public override void action()
 {
     if (dispAgent.messagesToSend.Count > 0)
     {
         ACLMessage messageToSend = new ACLMessage(ACLMessage.REQUEST);
         messageToSend.setContent(dispAgent.messagesToSend.First().Value);
         messageToSend.addReceiver(dispAgent.messagesToSend.First().Key);
         dispAgent.messagesToSend.Remove(dispAgent.messagesToSend.First().Key);
         dispAgent.send(messageToSend);
     }
 }
 public override void action()
 {
     if (helpAgent.messageForProc.Count() > 0) //&& !helpAgent.messageSent)
     {
         helpAgent.messageSent = true;
         ACLMessage messageToSend = new ACLMessage(ACLMessage.REQUEST);
         messageToSend.setContent(helpAgent.messageForProc.First().Value);
         messageToSend.addReceiver(helpAgent.messageForProc.First().Key);
         helpAgent.messageForProc.Remove(helpAgent.messageForProc.First().Key);
         helpAgent.send(messageToSend);
     }
 }
Пример #9
0
        public override void action()
        {
            //inform managerAgent that I want to register for the auction

            ACLMessage m = new ACLMessage(ACLMessage.INFORM);

            AID receiverAID = new AID("managerAgent", AID.ISLOCALNAME);
            m.addReceiver(receiverAID);
            m.setContent("registering");
            myAgent.send(m);

            myAgent.windowsForm.AddTextLine("Registering for auction ...");
        }
Пример #10
0
        public override void action()
        {
            ACLMessage m = myAgent.receive();

            if (m != null)
            {
                string received = m.getContent();
                AID sender = m.getSender();

                if(received.Contains("registering"))
                {
                    //sender wants to register for auction
                    myAgent.participantList.Add(sender);

                    //reply to sender that registration was successful
                    ACLMessage reply = new ACLMessage(ACLMessage.INFORM);
                    reply.setContent("registered");
                    reply.addReceiver(sender);
                    myAgent.send(reply);

                    myAgent.windowsForm.AddTextLine("New participant: " + sender.getLocalName());
                }

                if (received.Contains("offer"))
                {
                    //received new offer from agent
                    int receivedPrice = Convert.ToInt32(received.Remove(0, 5));

                    myAgent.windowsForm.AddTextLine("Received from " + sender.getLocalName() + " offer: " + receivedPrice);

                    if (receivedPrice > myAgent.currentPrice)
                    {
                        myAgent.currentPrice = receivedPrice;
                        myAgent.currentWinner = sender;
                    }
                }

                if (received.Contains("retreat"))
                {
                    //agent retreated
                    myAgent.participantList.Remove(sender);
                    myAgent.windowsForm.AddTextLine(sender.getLocalName() + " retreated.");
                }
            }
            else
                block();
        }
        void Send(int startIndex, int lastIndex, AID agentId)
        {
            ACLMessage toSendFirstArray  = new ACLMessage(ACLMessage.REQUEST);
            ACLMessage toSendSecondArray = new ACLMessage(ACLMessage.REQUEST);

            String content1 = "FirstSubset ";
            String content2 = "SecondSubset ";

            for (int index = startIndex; index < lastIndex; index++)
            {
                content1 += matrix1[(index / Constants.MatrixSize), index % Constants.MatrixSize] + " ";
                content2 += matrix2[(index / Constants.MatrixSize), index % Constants.MatrixSize] + " ";
            }

            toSendFirstArray.setContent(content1);
            toSendFirstArray.addReceiver(agentId);
            this.send(toSendFirstArray);

            toSendSecondArray.setContent(content2);
            toSendSecondArray.addReceiver(agentId);
            this.send(toSendSecondArray);
        }