writing a simple agent

38 views
Skip to first unread message

Peter

unread,
Jul 17, 2012, 1:13:03 PM7/17/12
to jsoar...@googlegroups.com
Hi,

I have been experimenting with jsoar lately, and managed to run some simple models through the debugger, such as the towers of hanoi.  This works well, lots of activity in the trace window.

I would like to be able to control a jsoar agent from a java program.  Having typed in the 'simple agent' example from the user guide:

import org.jsoar.kernel.Agent;

import java.io.OutputStreamWriter;

public class SoarAgent {
  public static void main (String[] args) {
    Agent agent = new Agent();
    agent.setName("My Agent");
    agent.getPrinter().pushWriter(new OutputStreamWriter(System.out));
    agent.initialize();
    agent.runForever(); // Call blocks until agent interrupts or halts
  }
}

I can compile and run, and the output is:

17-Jul-2012 17:36:46 org.jsoar.kernel.smem.DefaultSemanticMemory smem_init_db
INFO: Opened database 'jdbc:sqlite::memory:' with SQLiteJDBC:native
17-Jul-2012 17:36:46 org.jsoar.kernel.smem.DefaultSemanticMemory applyDatabasePerformanceOptions
INFO: Applying performance settings from '/org/jsoar/kernel/smem/DefaultSemanticMemory/org.sqlite.JDBC.performance.sql'.

     0: ==>S: S1
     1:    ==>S: S3 (state no-change)
     2:       ==>S: S5 (state no-change)

and onwards till the stack overflows at depth 100.

I have tried to load a soar file, i.e. towers-of-hanoi.soar (with the GUI stuff removed), as follows:

import org.jsoar.kernel.Agent;
import org.jsoar.util.commands.SoarCommands;

import java.io.OutputStreamWriter;

public class SoarAgent {
  public static void main (String[] args) {
    Agent agent = new Agent();
    agent.setName("My Agent");
    agent.getPrinter().pushWriter(new OutputStreamWriter(System.out));
    try {
      SoarCommands.source(agent.getInterpreter(), "towers-of-hanoi.soar");
    } catch (org.jsoar.kernel.SoarException se) {
      System.out.println ("Exception " + se);
    }
    agent.initialize();
    agent.runForever(); // Call blocks until agent interrupts or halts
  }
}

This outputs:

17-Jul-2012 17:39:39 org.jsoar.util.commands.SoarCommands registerCustomCommands
INFO: Registering custom commands from class org.jsoar.kernel.smem.DefaultSemanticMemoryCommand$Provider
17-Jul-2012 17:39:39 org.jsoar.util.commands.SoarCommands registerCustomCommands
INFO: Registering custom commands from class org.jsoar.script.ScriptCommand$Provider
17-Jul-2012 17:39:39 org.jsoar.kernel.Agent getInterpreter
INFO: Current command interpreter is 'default' : 'class org.jsoar.util.commands.DefaultInterpreter'
17-Jul-2012 17:39:39 org.jsoar.kernel.smem.DefaultSemanticMemory smem_init_db
INFO: Opened database 'jdbc:sqlite::memory:' with SQLiteJDBC:native
17-Jul-2012 17:39:39 org.jsoar.kernel.smem.DefaultSemanticMemory applyDatabasePerformanceOptions
INFO: Applying performance settings from '/org/jsoar/kernel/smem/DefaultSemanticMemory/org.sqlite.JDBC.performance.sql'.
*******************
     0: ==>S: S1
     1:    O: O1 (initialize-toh)
     2:    ==>S: S3 (state no-change)
     3:       ==>S: S5 (state no-change)
     4:          ==>S: S7 (state no-change)
     5:             ==>S: S9 (state no-change)

and on until the stack overflows.  'state no-change' suggests to me the agent has not done anything.

I had been hoping to see the productions firing, messages of disks moved etc, as in the trace window of the debugger.  I have managed to print out the productions etc after loading them, but can't seem to make the agent step through its decision cycle.

Apart from diving into the jsoar source code, any tips on how to control an agent from Java?

  thanks,

     Peter.

Dave Ray

unread,
Jul 17, 2012, 10:54:24 PM7/17/12
to jsoar...@googlegroups.com
Hi Peter,

You aren't doing anything wrong as far as running the agent from Java
goes. The main issue is that the towers-of-hanoi.soar rules you're
loading assume that an I/O environment is provided. You'll note the
"load-plugin org.jsoar.demos.toh.TowersOfHanoi 3 11" line at the top
of the file. This not only displays the user interface, but also gives
agent feedback on the input-link and takes commands from the agent on
the output-link.

The easiest thing to do would be to pull in a "standalone" agent, i.e.
one that does all the work "in its head" and run that. You can get
sample agents and more information from the main Soar distribution
(http://sitemaker.umich.edu/soar/home).

Cheers,

Dave
> --
> You received this message because you are subscribed to the Google Groups
> "jsoar-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/jsoar-user/-/9qUoBCXMAGMJ.
> To post to this group, send email to jsoar...@googlegroups.com.
> To unsubscribe from this group, send email to
> jsoar-user+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jsoar-user?hl=en.

Nate Derbinsky

unread,
Jul 18, 2012, 3:31:52 AM7/18/12
to jsoar...@googlegroups.com
Hi Peter,

Just to add to what Dave said, change the "towers-of-hanoi.soar" path
for "https://soar.googlecode.com/svn/trunk/Agents/towers-of-hanoi-simple/towers-of-hanoi.soar"
and your program should now work as expected (with a short delay to
access the remote files). This swap takes advantage of JSoar's ability
to source agents via URL. Of course, as Dave said, you could also
download the Soar Tutorial v9.3.2
(https://code.google.com/p/soar/wiki/SoarTutorial) and use the same
agent file locally.

Nate

Peter

unread,
Jul 18, 2012, 10:15:24 AM7/18/12
to jsoar...@googlegroups.com
Hi Dave,

Thanks for getting back to me.  You are quite right.  I thought I had removed the IO parts from the towers-of-hanoi script, but I see now I left it incomplete!  I've succeeded in running some of the agents on the website you sent me, so  I can now explore further.

  cheers,

       Peter.

Peter

unread,
Jul 18, 2012, 10:19:58 AM7/18/12
to jsoar...@googlegroups.com
Hi Nate,

Thanks for the suggestion - this agent-via-url also worked. 

  cheers,

       Peter.
Reply all
Reply to author
Forward
0 new messages