How to develop Android based bdi agents

Michael Wu
2013-01-30
2013-06-12
  • Michael Wu

    Michael Wu - 2013-01-30

    I would like to develop a simple BDI agent which can run on Android systems.  I downloaded Jadex Android V2.2.1 but could not found any working examples.  (There are many examples included in the sources.zip of the non-Android version.)
    I did download the jadex-android-example-projects.zip file.  But, it does not demo the implementation of a bdi agent.  That is, no files implementing the plans, actions, beliefs, …, are shown.  I still have no idea about how to develop the Android based agent?

    Can anyone help?

    A working sample is most helpful for me at this point.
    (I can publish the code and the Android project file of my project if I finally work it out!)

     
  • Julian

    Julian - 2013-01-31

    If you want to develop bdi agents for Android, I recommend you to download the current nightly build from . It is named jadex-android-2.3-SNAPSHOT.zip.

    We have recently included an Android application (jadex-applications-android-demos), which shows how a BDI Agent is started and executes a Plan that interacts with the Android UI.

    For Service interaction, take a look at jadex-applications-android-chat, which implements the jadex chat for android and uses an Android service.

    The source for both applications is included in "sources.zip" inside the above mentioned nightly build.

    Julian

    http://www1.activecomponents.org/download/

     
  • Michael Wu

    Michael Wu - 2013-01-31

    I got it.  Thanks!

    I created an Android project to try it out.  The files can be compiled successfully.  However, once the Android application starts, nothing happen.  It seems that the platform is not started as expected.

    The following is the code snippet of my Android activity:

    ...
    package jadex.android.application.demo;
    import jadex.android.JadexAndroidActivity;
    import jadex.bridge.IComponentIdentifier;
    import jadex.bridge.IExternalAccess;
    import jadex.commons.future.DefaultResultListener;
    import jadex.commons.future.IResultListener;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.widget.Toast;
    import jadex.android.service.JadexPlatformManager;
    import jadex.bridge.service.types.cms.IComponentManagementService;
    public class JadexAndroidHelloWorldActivity extends JadexAndroidActivity {
        private TextView textView;
        public JadexAndroidHelloWorldActivity()
        {
            super();
            setPlatformAutostart(true);
            setPlatformKernels(JadexPlatformManager.KERNEL_MICRO,
                       JadexPlatformManager.KERNEL_COMPONENT, JadexPlatformManager.KERNEL_BDI);
            setPlatformName("bdiDemoPlatform");
        }
    
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            textView = (TextView) findViewById(R.id.infoTextView);
        }
        protected void onResume() {
            super.onResume();
        }
        public void onStop() {
            super.onStop();
        }
        public void onDestroy() {
            super.onStop();
        }
    
        @Override
        protected void onPlatformStarted(IExternalAccess result)
        {
            super.onPlatformStarted(result);
            startBDIAgent("HelloWorldAgent",
                    "atc/engtutor/agent/HelloWorld.agent.xml").addResultListener(bdiCreatedResultListener);
        }
        private IResultListener<IComponentIdentifier> bdiCreatedResultListener = new DefaultResultListener<IComponentIdentifier>()
        {
            public void resultAvailable(final IComponentIdentifier bdiId)
            {
                getCMS().addResultListener(new DefaultResultListener<IComponentManagementService>()
                {
                    @Override
                    public void resultAvailable(IComponentManagementService result)
                    {
                        runOnUiThread(new Runnable() {
                            public void run() {
                                Toast makeText = Toast.makeText(
                                        JadexAndroidHelloWorldActivity.this,
                                        "result available", Toast.LENGTH_SHORT);
                                makeText.show();
                            }
                        });
                    }
                });
            }
        };
    }
    

    I set a breakpoint inside the onPlatformStarted(IExternalAccess result) method.  But, it was never visited.

    The code is almost the same as the example's.

    Did I miss anything in the code?

     
  • Julian

    Julian - 2013-01-31

    The code looks right.
    When i run it, onPlatformStarted() is executed properly.

    Can you take a look at the DDMS LogCat view to check for exceptions?

     
  • Michael Wu

    Michael Wu - 2013-02-01

    Sorry, I am out of the office today.  I will post the LogCat data asap next Monday.

    As far as I remembered, it seemed that there were service connection exceptions after I stopped the Android agent application being debugged because onPlatformStarted() was not visited as expected.

    By the way, I put the folowing code in the constructor as the example code does:
    setPlatformAutostart(true);
    setPlatformKernels(JadexPlatformManager.KERNEL_MICRO,
       JadexPlatformManager.KERNEL_COMPONENT, JadexPlatformManager.KERNEL_BDI);
    setPlatformName("bdiDemoPlatform");

    Should I move them into the onCreate() method?

    When setPlatformAutostart(true) is called, what will happen normally?  Does it trigger the internal code of the JadexAndroidActivity to bring up the platform?

    Is the platform implemented as an Android service?  If it is the case, what configuration, if any, need to be done so that the platform service can be started successfully?

     
  • Michael Wu

    Michael Wu - 2013-02-04

    When the Android application run, there is actually no messages shown on the LogCat window.  I then pressed the Back button to terminate the application.    Then, the following is shown:

    02-04 14:43:44.470: I/System.out(2999): waiting for debugger to settle...
    02-04 14:43:44.670: I/System.out(2999): waiting for debugger to settle...
    02-04 14:43:44.870: I/System.out(2999): waiting for debugger to settle...
    02-04 14:43:45.070: I/System.out(2999): debugger has settled (1368)
    02-04 14:43:46.040: D/dalvikvm(2999): threadid=1: still suspended after undo (sc=1 dc=1)
    02-04 14:43:50.750: V/TLINE(2999): new: android.text.TextLine@407975c8
    02-04 14:46:16.860: E/ActivityThread(2999): Activity jadex.android.application.demo.JadexAndroidHelloWorldActivity has leaked ServiceConnection jadex.android.application.demo.JadexAndroidHelloWorldActivity@40788b18 that was originally bound here
    02-04 14:46:16.860: E/ActivityThread(2999): android.app.ServiceConnectionLeaked: Activity jadex.android.application.demo.JadexAndroidHelloWorldActivity has leaked ServiceConnection jadex.android.application.demo.JadexAndroidHelloWorldActivity@40788b18 that was originally bound here
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:923)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:818)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.ContextImpl.bindService(ContextImpl.java:1071)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    02-04 14:46:16.860: E/ActivityThread(2999):     at jadex.android.JadexAndroidActivity.onCreate(JadexAndroidActivity.java:80)
    02-04 14:46:16.860: E/ActivityThread(2999):     at jadex.android.application.demo.JadexAndroidHelloWorldActivity.onCreate(JadexAndroidHelloWorldActivity.java:28)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.ActivityThread.access$1500(ActivityThread.java:122)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.os.Handler.dispatchMessage(Handler.java:99)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.os.Looper.loop(Looper.java:132)
    02-04 14:46:16.860: E/ActivityThread(2999):     at android.app.ActivityThread.main(ActivityThread.java:4025)
    02-04 14:46:16.860: E/ActivityThread(2999):     at java.lang.reflect.Method.invokeNative(Native Method)
    02-04 14:46:16.860: E/ActivityThread(2999):     at java.lang.reflect.Method.invoke(Method.java:491)
    02-04 14:46:16.860: E/ActivityThread(2999):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    02-04 14:46:16.860: E/ActivityThread(2999):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    02-04 14:46:16.860: E/ActivityThread(2999):     at dalvik.system.NativeStart.main(Native Method)
    02-04 14:46:26.890: D/dalvikvm(2999): GC_EXPLICIT freed 104K, 5% free 6291K/6595K, paused 7ms+2ms
    

    Can anyone help?

     
  • Michael Wu

    Michael Wu - 2013-02-04

    To narrow down the problem by bypassing the setPlatformAutostart(true) call, I re-coded the application by using the example project which supports manual starting the Jadex platform.

    With the new example application project, the Jadex platform can be started successfully.  Besides, a MicroAgent can be fired without problems.

    With the new example application project as the base, I added the following code to the button click listener for starting a SDI agent:

    startBDIAgent(\"SDI Agent \" + numSdiAgent,                           \"/jadex/android/exampleproject/HelloWorld.agent.xml\").addResultListener(bdiAgentCreatedResultListener);
    

    When the code executes, an exception occur:

    Exception occurred: jadex.android.exampleproject.HelloWorldActivity$3@4078ce40, jadex.bridge.ComponentCreationException: No factory found for: /jadex/android/exampleproject/HelloWorld.agent.xml
    

    It seems that some class or jar files are missing?!

    Can help one help?

     
  • Michael Wu

    Michael Wu - 2013-02-04

    I finally resolved the "No factory found for:" problem reported in my last post.

    JadexPlatformManager.KERNEL_BDI must be specified as the platform kernel.

    Hope the information can help a bit in the future if some ones run into the same problem as I did.

     
  • Anonymous - 2013-05-08

    I always gag when people say "simple" and JADEX in one sentance. 

    Simple bdi agents in android is more likely to mean http://jaca-android.sourceforge.net/.

    That is, writing in Jason on Android and not using agent libraries in java.  Don't you feel the the OO nature of Java obfuscates the agent-orientedness of the problem space?

     
  • Lars Braubach

    Lars Braubach - 2013-05-08

    Hi,

    first, it is somewhat strange to post recommendations for alternative solutions of a forum of a specific software product. Imagine what happens when you post use Linux at a Windows forum. Each of the software solutions has specific pros and cons but you should respect that they both exist and are used by people.

    Second, you should at least be so brave and post such a comment with a name so that we know which background you have. 

    Third, especially the combination of BDI with object oriented ideas results in an easy to use (because people know object orientation) and powerful paradigm. We have proven this recently with BDI V3 that makes BDI agents looks like normal Java classes.

    Kind regards
    Lars

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks