Menu

new to AFME

AFME
jessie Wan
2008-08-30
2013-03-03
1 2 > >> (Page 1 of 2)
  • jessie Wan

    jessie Wan - 2008-08-30

    Hi ;
    i am new to AFME, and i got some problem when i try to create agents to communicate with each other:
    i create two agentplatforms for two agents called Alice and Bob,  and create two different interfaces for them, which are called aliceInterface and bobInterface,  the interfaces are extends service class,
    but when i run this application i got the message that
    "no modules or services associated with aliceInterface"
    "no modules or services associated with bobInterface"
    is there anybody can help me to fix this problem? 

    many many thanks

     
    • Conor

      Conor - 2008-09-01

      hi Jessie,

      you need to make sure that the name specified in the super call in the constructor of the services matches the name specified when calling the manager methods e.g. when creating a service, you should have something like super("aliceInterface"); in the constructor. Additionally, you need to make sure that the service is specified in the platform script. When the service is added to the script, it must be recompiled using the AFME compiler. Subsequently, refresh your IDE source folder and then compile and run the Java code.

      best regards,

      Conor

       
    • jessie Wan

      jessie Wan - 2008-09-01

      thanks a lot Conor;
      but i still got error, the services name was specified correctly in the super constructor,
      and i create one interface as a service for Bob agent named BobInterface and in the super constructor is super("bobInterface"),  another service called ChatService and the service is specified as super("chatservice"), there is no interface defined for Alice agent, since it doesnot need to input anything,
      in the Alice agent design file , i called the two services as:

        service ChatService;
        service BobInterface;

      and the Alice's perceptor is :
      FOS fos = pm.perManage("chatservice", 0);
          
           if(fos != null){
             String y = fos.toString();
           
              adoptBelief("someBelief("+y+")");
            
           }

      and the Alice's Actuator is :
        FOS arg = action.next();
              if(arg != null){
                   manager.actOn("bobInterface", 0, arg);
          }

      in bob's agent design file:
      gui netchat.BobInterface;

      platform Bobplat{
         
        // Number of threads in operation on the platform
        scheduler 2;
      service ChatService;

      and the bob's perceptor is :
         
            FOS fos = pm.perManage("bobInterface", 0);

      bob's actuator is :
      if(arg != null){
                   manager.actOn("chatservice", 0, arg);

      but when i compiler the files, there is an error in the automatically generated Aliceletagentplatform class:
      args=new String[0];
              new BobInterface(args,agentName,scheduler,this).register(services);
      the error is : cannot find constructor BobInterface;

      can you please take a look at it ?
      many thanks

       
      • Conor

        Conor - 2008-09-01

        hi Jessie,

        if there is no interface on Alice's platform why are you trying to access the bobinterface in Alice's actuator. the bobinterface is a gui service, so it must be specified using the gui keyword not service. this basically dictates what will be passed to the constructor in the generated code.

         
    • jessie Wan

      jessie Wan - 2008-09-01

      Thanks Conor;

      the reason for Alice agent access the bobInterface is that the Alice Agent will pass some message to the Bob agent and show the messge on the screen.  when bob send message to Alice, and Alice will respone to bob and send some message but not from input,  just automatically response message,  so Alice do not need input anything,  that's why i think Alice may does not need a graphical interface.
      If Alice agent can not access bobInterface, how does it pass message to bob?

      many thanks

       
      • Conor

        Conor - 2008-09-01

        hi Jessie,

        i am assuming that you want Alice and Bob to be on the same platform, so in that case you should only have on platform script that creates both Bob and Alice. In that case, you should create the bob interface using the gui key would and the chatter service using the service keyword. that is, you should only have one platform script rather than two. you will have two different agent design files though. in any case, Alice can send a message to Bob using the request and inform actuators.

         
    • jessie Wan

      jessie Wan - 2008-09-01

      thanks a lot Conor,
      but if they are in the same platform, they will have the same interface,   how to specify the different interface for the two agents? or just one agent has the graphical interface?

       
    • jessie Wan

      jessie Wan - 2008-09-01

      hi Conor

      please ignore the previous message.

       
    • jessie Wan

      jessie Wan - 2008-09-02

      Hello Conor;

      if the two agents are in the same platform, i write an bobinterface class extends service, which is only accessd by bob agent, and another service named chatservice, which is accessed both by bob and alice, i create two actuators for bob to actOn each services, is this all right?

      thanks a lot

       
      • Conor

        Conor - 2008-09-03

        hi Jessie,

        yeah, that's fine. you could implement bob's interface as a module as it is only accessed by bob if you like. but it will work the way it is anyway.

         
    • jessie Wan

      jessie Wan - 2008-09-04

      thanks Conor for your reply.
      that's works good.  but i still have the problem that the messages always keep sending, is there any chance that control the message just sent once?  the retractBelief() method seems doesnot work, cos when i use it, i got the nullPointerException and the ArrayOutofBoundaryException in the next message.
      is there any other methods to control this?

      many thanks.

       
      • Conor

        Conor - 2008-09-04

        hi Jessie,

        i think that you are having a Java problem rather than an AFME problem. the first time you adopt the belief you should set a boolean to true and then check if the boolean has been set. In you code you could have something like the following:

        boolean b=false;

        ...

        if(!b){
        b=true;
        adoptBelief(...);

        }

        an alternative approach would be to wipe the string or whatever it is you are monitoring;
        eg.

        if(st!=null){

        adoptBelief
        st=null; // this will reset it so as that it is not adopted again
        }
        }

         
    • jessie Wan

      jessie Wan - 2008-09-04

      Hi Conor, thanks a lot, but that's what i tried already, but it seems doesn't work.

       
      • Conor

        Conor - 2008-09-05

        hi Jessie,

        make sure it's not an always belief that you are adopting. an always belief will remain until you retract it.

         
    • jessie Wan

      jessie Wan - 2008-09-05

      thanks Conor, the commitment rules are something like:

      someBelief(?x), someAgent(?an) > par(chat(data(?an, ?x)),inform(?an,?x));

      the someAgent() belief is an always belief, but the someBelief() belief  is adopted in the perceptor,

      i set it as null after the belief is adopted, but it still keep sending, is there any other solutions for this? 

      thanks Conor, and are u in college today, can we meet today in your convinent time?

      jessie

       
      • Conor

        Conor - 2008-09-08

        hi jessie,

        can you post the code for the perceptor so that i can see what is going on

         
    • jessie Wan

      jessie Wan - 2008-09-05

      and i have another problem, that when i create the agent without GUI/MIDlet, after compiler it, how to run it and how to communicate with the standard AFME agent?
      if i want the agent talk to the database , how to realize this?

      thanks a lot

       
      • Conor

        Conor - 2008-09-08

        to execute the a platform without GUI/MIDlet, you need to invoke the main method of the platform class from the command line

         
    • jessie Wan

      jessie Wan - 2008-09-08

      Thanks for you reply Conor;

      what i want to do between two agents(Alice and bob) is that bob input his id, password and queryitem etc and send to alice, and alice analysis these information and response to bob, the alice perceptor is :
      public class AlicePerceptor extends Perceptor{
         

      // AgentName an;
        PerceptionManager pm ;

        String user, query,timeS,timeE,note;
       
        long ts,te,tL;
        String s;
         
        String resp;
        int count;
       
        String hour,minute,second;
        String y;
       
      // boolean belf = false;
        
        public AlicePerceptor(PerceptionManager manager){
          super(manager);
          pm = manager;
        
          }
         
        public void perceive(){
          
           // FOS args ;
           FOS fos = pm.perManage("chatservice", 0);
          
           count = 0;
           if(fos != null){
              // if(!belf){
                //   belf = true;
             y = fos.toString();
            
            System.out.println("Bob said : "+ y);
           
            if(y.endsWith("id")){
               
             if(y.equalsIgnoreCase("one123id")){
                 resp = "Correct"; 
                 adoptBelief("correctID("+resp+")");
                 user = y.substring(0, 3);
                 //fos = null;
             }
             else{
                 resp = "Invalid";
                 adoptBelief("messInvalid("+resp+")");  
                 //fos = null;
             }
            }
            
             else if(y.equalsIgnoreCase("respirationrateqi") || y.equalsIgnoreCase("heartrateqi") || y.equalsIgnoreCase("activity levelqi")){
                 resp = "specifyTime";
               
                 adoptBelief("queryTime("+resp+")");
                 query = y.substring(0, y.length()-2);
                 //fos = null;
             }
           
             else if(y.equalsIgnoreCase("tryagain")){
                 if(count <= 3){
                   resp = "enteryourid";
                 
                   adoptBelief("tryAgain("+resp+")");
                    count++;
                   // fos = null;
                 }
                 else{
                     resp = "fail";
                     adoptBelief("fail("+resp+")");
                 }
             }
           fos = null;
            y = null;
          //}
        }
          // fos = null;
           ///time notification.
          
           long current = System.currentTimeMillis();
          // DateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
           Date resultdate = new Date(current);
          //System.out.println("current time : "+resultdate);
           String ct = resultdate.toString();
          // System.out.println("current time : "+ct);
           //System.out.println("current hour : "+ct.substring(11, 13));
           //System.out.println("current minute : "+ct.substring(14, 16));
           //System.out.println("current second : "+ct.substring(17, 19));
           hour = ct.substring(11,13);
           minute = ct.substring(14,16);
           second = ct.substring(17,19);
          
           if((hour.equals("18")) && (minute.equals("00")) && (second.equals("00"))){
                note = "nf"+"check your goal";
               adoptBelief("notification("+note+")");
              
           }
          
           ////end
          
          
           FOS foss = pm.perManage("chatservice2", 0);
          
           if(foss != null){
               //System.out.println("message from chatservice2 : "+foss.toString());
               String time = foss.toString();
               int l = time.length();
               timeS = time.substring(0,(int)(l-4)/2);
               timeE = time.substring((int)(l/2),l-2);
              // System.out.println(time);
               //System.out.println(timeS+" , "+timeE);
              
              ts = Long.parseLong(timeS);
              te = Long.parseLong(timeE);
              if(ts <= te){
                  tL = te - ts;
                 
                  System.out.println(ts +" to "+te);
                  s = "  Please waiting...";
                  adoptBelief("waitRequest("+s+")");
                  System.out.println("Alice's new belief : "+s);
              }
           
           }
           
      }
      }

      and the bob's perceptor is :

      public class BobPerceptor extends Perceptor{

        PerceptionManager pm ;

        String showmess;
        String x,xx;
       
        static String s,e;

      // boolean bel;
        public BobPerceptor(PerceptionManager manager){
          super(manager);
          pm = manager;
        //  bel = false;
          }
         
        public void perceive(){

            FOS fos = pm.perManage("bobInterface", 0);
            //adoptBelief("start");  
            if(fos != null){
              
               // if(!bel){
                 //   bel = true;
                x = fos.toString();
        
                  if(x.endsWith("id")){
                    
                     adoptBelief("someBelief("+x+")");
                     //fos = null;
                  }
              
                  if(x.endsWith("qi")){
                   
                      adoptBelief("wantQuery("+x+")");
                      //fos = null;
                  }
                  if(x.equalsIgnoreCase("tryagain")){
                    
                      adoptBelief("wantTry("+x+")");
                      //fos = null;
                  }
                 if(x.endsWith("st")){
                     s = x;
                    // adoptBelief("startTime("+s+")");
                 }
                if(x.endsWith("et")){
                     e = x;
                     //adoptBelief("endTime("+e+")");
                }
                if((s != null) && (e != null)){
                    adoptBelief("queryTime("+s+","+e+")");
                }
               
                // System.out.println("bob's belief : "+x);
                  fos = null;
                  x = null;
               // }
            }
            //fos = null;
            FOS foss = pm.perManage("chatservice", 0);
            if(foss != null){
                xx = foss.toString();
                showmess = xx;
                adoptBelief("messFromAlice("+showmess+")");
                xx = null;
                foss = null;
            }
           
            FOS foos = pm.perManage("chatservice2", 0);
             if(foos != null){
                
                 System.out.println("mess from chatservice2 for bob : "+foos.toString());
             }
          
          
        }

      }

      could you please take a look it?

       
      • Conor

        Conor - 2008-09-09

        hi jessie,

        i think the problem is with whatever is triggering the process in the service. make sure that the service only returns a first order structure (FOS) once when something occurs in the interface eg option selected etc. if nothing is selected null should be returned from the service so as that the process will not be repeated

        C.

         
  • jessie Wan

    jessie Wan - 2009-09-18

    i have a MAS application done , which use the AFME compiler for creating the MIDlet and platfrom, and if i want integrate the application with J2ME POLISH or LWUIT, is it possible just rewrite the interface agent in java directly, without changing other agents code?

     
  • Conor

    Conor - 2009-09-18

    yes, you can create agents directly in Java. It just means that you will have to add all actuators, perceptors, rules etc. manually in Java rather than using an agent design file (a .sh file) and a template. Alternatively, you could create a template for automatically generating the code. In this way, you could use the design file. check out the section on creating agents directly in Java in the programmers' guide

     
  • jessie Wan

    jessie Wan - 2009-09-18

    Hi Conor,
    thanks a lot for ur reply, but i mean i have a MAS system done already, which has few agents living on the same platform, which are created by agentd design file.  one of the agent takes care of the user interface, now, i want get a better look,  if i just want write the interface agent in java directly, and leave the other agents using agent design file ? i means i do not want change all the agents code.  i am not sure if i have expressed properly,  is it possible to have one agent create in java directly and few other agents created by agent design file , let them living in the same platform and communicate with each other ?

     
  • Conor

    Conor - 2009-09-19

    hi Jessie,

    Take a look at the code in the generated midlet for you preexisting application. Add the required lines to the midlet created with POLISH or LWUIT. That is, create the agent platform in the polish/ LWUIT application. Delete the generated midlet and the com/agentfactory/cldc/compiler/MIDlet.template ApplicationNamelet from the template specifier in the agent platform script

    C

     
  • jessie Wan

    jessie Wan - 2009-09-21

    HI Conor;
    thanks a lot for ur reply,
    the agent platform is still created by the agent design file, i just need rewrite a midlet ? right ?

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Auth0 Logo