My plan is to use an external dominating simulator to synchronize the time advance of Brahms. With the codes shown below, I can create new BVM and VM controller in my JAVA application where the external simulator resides.
// Create new BVM
bvm brahmsVirtualMachine = new bvm();
// Generate list of bvm arguments
List<String> bvmArguments = new ArrayList<String>();
bvmArguments.add("-cf");
bvmArguments.add("./vm.cfg");
// Initialize bvm
int errorCode = brahmsVirtualMachine.initialize(bvmArguments.toArray(new String[0]));
// Create time sync hook
MyTimeSyncHook myTimeSyncHook = new MyTimeSyncHook();
// Get VMController for the BVM
VMController vmController = brahmsVirtualMachine.VMCONTROLLER;
// Load Brahms Model
vmController.loadModel("gov.nasa.arc.brahms.atm.AtmModel");
// Register time sync hook
vmController.registerTimeSyncHook(myTimeSyncHook);
// Start the vm controller
vmController.start();
But when I tried to generate new Brahms agents in my application using the codes as follows,
// Create array of agent groups
IGroup[] groups = new IGroup[1];
groups[0] = getModel().getGroup("gov.nasa.arc.brahms.atm.Student");
// Create agent that inherits from the defined groups, named Agent0
IAgent agent = AgentFactory.createAgent("Agent0", groups, getContext());
// Set belief for agent
agent.setBeliefAttributeBoolean(agent, "male", true, getContext());
I got the following exception:
java.lang.NullPointerException
at gov.nasa.arc.brahms.vm.api.jagt.AbstractExternalAgent$Context.getOwner(AbstractExternalAgent.java:2245)
at gov.nasa.arc.brahms.vm.japi.common.JAgent.createAgent(JAgent.java:150)
at gov.nasa.arc.brahms.vm.api.common.AgentFactory.createAgent(AgentFactory.java:40)
I have added the definition of the Brahms agent in my Brahms model as an external agent, and it works well if the Brahms engine is dominating and the Composer did all the initializations.
Hi Ruben,
Thanks for this solution! With it, I found the problem in my project and sort of solved it. What I did is: 1) start the external simulation; 2) start the Brahms engine; 3) use Brahms engine to create a Brahms agent 4) use external simulation to create Brahms agents and it works. So the ’Icontext’ can only be accessed if there is at least an existing Brahms agent created by Brahms engine.
Thanks for your help!
Best regards,
Mingxin