io.github.agentsoz.abmjack.env.ActionList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abm-jack Show documentation
Show all versions of abm-jack Show documentation
Allows the use of JACK (aosgrp.com/products/jack) as the underlying BDI system
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
This code is generated by JAC version 5.6 by
Agent Oriented Software. http://www.agent-software.com.au
DO NOT ALTER THIS CODE AND DO NOT REMOVE THIS COMMENT
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
package io.github.agentsoz.abmjack.env;
/*
* #%L
* BDI-ABM Integration Package
* %%
* Copyright (C) 2014 - 2016 by its authors. See AUTHORS file.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import aos.jack.jak.core.Jak;
import aos.jack.jak.event.EventRecipient;
import aos.jack.jak.beliefset.ClosedWorld;
import aos.jack.jak.beliefset.ClosedWorldCursor;
import aos.jack.jak.beliefset.BeliefSetCursor;
import aos.jack.jak.beliefset.BeliefSetException;
import aos.jack.jak.beliefset.Tuple;
import aos.jack.jak.beliefset.BeliefSet;
import aos.jack.jak.logic.ChoicePoint;
import aos.jack.jak.logic.Variable;
import aos.jack.jak.cursor.Cursor;
import aos.jack.jak.cursor.BeliefState;
import aos.jack.plugin.view.rt.CleanupCursor;
import io.github.agentsoz.bdiabm.data.ActionContent.State;
import java.util.StringTokenizer;
/**
*
* @author Alex Lutman
*
*/
public class ActionList extends aos.jack.jak.beliefset.ClosedWorld {
private final java.lang.String NO_PARAMS = "null";
static public io.github.agentsoz.abmjack.env.ActionList__Tuple __hole = new io.github.agentsoz.abmjack.env.ActionList__Tuple(true);
public io.github.agentsoz.abmjack.env.ActionList__Tuple[][] __tables;
public io.github.agentsoz.bdiabm.data.ActionContent.State getState(java.lang.String actionID)
{
try {
return stringToState(fGetState(actionID));
}
catch (aos.jack.jak.beliefset.BeliefSetException bse) {
bse.printStackTrace();
java.lang.System.exit(1);
}
return null;
}
public java.lang.Object[] getParameters(java.lang.String actionID)
{
try {
return stringToParams(fGetParameters(actionID));
}
catch (aos.jack.jak.beliefset.BeliefSetException bse) {
bse.printStackTrace();
java.lang.System.exit(1);
}
return null;
}
private java.lang.Object[] stringToParams(java.lang.String params)
{
if (params.equals(NO_PARAMS)) {
return null;
}
java.util.StringTokenizer st = new java.util.StringTokenizer(params,":");
java.lang.Object[] newParams = new java.lang.Object[st.countTokens()];
int i = 0;
while (st.hasMoreTokens()) {
newParams[i++ ] = st.nextToken();
}
return newParams;
}
private java.lang.String paramsToString(java.lang.Object[] params)
{
if (params == null || params.length == 0) {
return NO_PARAMS;
}
java.lang.String newString = params[0].toString();
for (int i = 1; i < params.length; i++ ) {
newString.concat(":").concat(params[i].toString());
}
if (newString.endsWith(":")) {
newString = newString.substring(0,(newString.length() - 2));
}
;
return newString;
}
public void insert(java.lang.String actionID, io.github.agentsoz.bdiabm.data.ActionContent.State state, java.lang.Object[] params)
{
try {
add(actionID,stateToString(state),paramsToString(params));
}
catch (aos.jack.jak.beliefset.BeliefSetException bse) {
bse.printStackTrace();
java.lang.System.exit(1);
}
}
private io.github.agentsoz.bdiabm.data.ActionContent.State stringToState(java.lang.String state)
{
return io.github.agentsoz.bdiabm.data.ActionContent.State.valueOf(state);
}
private java.lang.String stateToString(io.github.agentsoz.bdiabm.data.ActionContent.State state)
{
return state.toString();
}
public void displayAll()
{
try {
fDisplayAll();
}
catch (aos.jack.jak.beliefset.BeliefSetException bse) {
bse.printStackTrace();
java.lang.System.exit(1);
}
}
public java.lang.String getDocumentation()
{
return "/**\n * \n * @author Alex Lutman\n *\n */\n";
}
public boolean attach(aos.jack.jak.event.EventRecipient __h)
{
java.lang.Object __o = __h;
if (!super.attach(__h))
return false;
return true;
}
public aos.jack.jak.beliefset.BeliefSetCursor qGetData(java.lang.String __v0, aos.jack.jak.logic.StringVariable __v1, aos.jack.jak.logic.StringVariable __v2)
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList__Tuple __t = new io.github.agentsoz.abmjack.env.ActionList__Tuple();
io.github.agentsoz.abmjack.env.ActionList.__Cursor __c = new io.github.agentsoz.abmjack.env.ActionList.__Cursor(__t);
__t.actionID = __v0;
if (!__v1.check_unifiable(StringType))
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetData:IOO: arg 1 state Incorrect Variable type");
if (__v1.isGround()) {
try {
__t.state = __v1.as_string();
}
catch (java.lang.Exception e) {
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetData:IOO: got " + e.toString());
}
}
else
__c.state = __v1;
if (!__v2.check_unifiable(StringType))
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetData:IOO: arg 2 parameters Incorrect Variable type");
if (__v2.isGround()) {
try {
__t.parameters = __v2.as_string();
}
catch (java.lang.Exception e) {
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetData:IOO: got " + e.toString());
}
}
else
__c.parameters = __v2;
__c.init(0,this);
return __c;
}
public aos.jack.jak.beliefset.BeliefSetCursor qGetAll(aos.jack.jak.logic.StringVariable __v0, aos.jack.jak.logic.StringVariable __v1, aos.jack.jak.logic.StringVariable __v2)
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList__Tuple __t = new io.github.agentsoz.abmjack.env.ActionList__Tuple();
io.github.agentsoz.abmjack.env.ActionList.__Cursor __c = new io.github.agentsoz.abmjack.env.ActionList.__Cursor(__t);
if (!__v0.check_unifiable(StringType))
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetAll:OOO: arg 0 actionID Incorrect Variable type");
if (__v0.isGround()) {
try {
__t.actionID = __v0.as_string();
}
catch (java.lang.Exception e) {
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetAll:OOO: got " + e.toString());
}
}
else
__c.actionID = __v0;
if (!__v1.check_unifiable(StringType))
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetAll:OOO: arg 1 state Incorrect Variable type");
if (__v1.isGround()) {
try {
__t.state = __v1.as_string();
}
catch (java.lang.Exception e) {
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetAll:OOO: got " + e.toString());
}
}
else
__c.state = __v1;
if (!__v2.check_unifiable(StringType))
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetAll:OOO: arg 2 parameters Incorrect Variable type");
if (__v2.isGround()) {
try {
__t.parameters = __v2.as_string();
}
catch (java.lang.Exception e) {
throw new aos.jack.jak.beliefset.BeliefSetException("ActionList:qGetAll:OOO: got " + e.toString());
}
}
else
__c.parameters = __v2;
__c.init(-1,this);
return __c;
}
java.lang.String fGetState(java.lang.String actionID)
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList.__complex_1 __c = new io.github.agentsoz.abmjack.env.ActionList.__complex_1(actionID);
try {
return __c.__complex_1_fGetState();
}
catch (java.lang.Exception __e) {
throw new aos.jack.jak.beliefset.BeliefSetException("fGetState got exception " + __e);
}
}
java.lang.String fGetParameters(java.lang.String actionID)
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList.__complex_2 __c = new io.github.agentsoz.abmjack.env.ActionList.__complex_2(actionID);
try {
return __c.__complex_2_fGetParameters();
}
catch (java.lang.Exception __e) {
throw new aos.jack.jak.beliefset.BeliefSetException("fGetParameters got exception " + __e);
}
}
java.lang.String fDisplayAll()
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList.__complex_3 __c = new io.github.agentsoz.abmjack.env.ActionList.__complex_3();
try {
return __c.__complex_3_fDisplayAll();
}
catch (java.lang.Exception __e) {
throw new aos.jack.jak.beliefset.BeliefSetException("fDisplayAll got exception " + __e);
}
}
public int keyIndex()
{
return 0;
}
public int fullIndex()
{
return 0;
}
public int nIndexes()
{
return 2;
}
public aos.jack.jak.beliefset.Tuple newTuple()
{
return new io.github.agentsoz.abmjack.env.ActionList__Tuple();
}
public aos.jack.jak.beliefset.Tuple getTuple(int t, int l)
{
return __tables[t][l];
}
public aos.jack.jak.beliefset.Tuple[] newTable(int t)
{
return new io.github.agentsoz.abmjack.env.ActionList__Tuple[t];
}
public aos.jack.jak.beliefset.Tuple[][] newTables(int t)
{
return new io.github.agentsoz.abmjack.env.ActionList__Tuple[t][];
}
public aos.jack.jak.beliefset.Tuple[] getTable(int t)
{
return __tables[t];
}
public aos.jack.jak.beliefset.Tuple[][] getTables()
{
return __tables;
}
public void setTables(aos.jack.jak.beliefset.Tuple[][] t)
{
__tables = (io.github.agentsoz.abmjack.env.ActionList__Tuple[][]) t;
}
public aos.jack.jak.beliefset.BeliefSetCursor newCursor(aos.jack.jak.beliefset.Tuple __t)
{
if (__t instanceof io.github.agentsoz.abmjack.env.ActionList__Tuple)
return new io.github.agentsoz.abmjack.env.ActionList.__Cursor((io.github.agentsoz.abmjack.env.ActionList__Tuple) __t);
return null;
}
public void add(java.lang.String __v0, java.lang.String __v1, java.lang.String __v2)
throws aos.jack.jak.beliefset.BeliefSetException
{
add(__v0,__v1,__v2,aos.jack.jak.cursor.Cursor.TRUE);
}
public void add(java.lang.String __v0, java.lang.String __v1, java.lang.String __v2, aos.jack.jak.cursor.BeliefState __d)
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList__Tuple __t = new io.github.agentsoz.abmjack.env.ActionList__Tuple();
__t.actionID = __v0;
__t.state = __v1;
__t.parameters = __v2;
super.assertTuple(__t,__d);
}
public void remove(java.lang.String __v0, java.lang.String __v1, java.lang.String __v2)
throws aos.jack.jak.beliefset.BeliefSetException
{
remove(__v0,__v1,__v2,aos.jack.jak.cursor.Cursor.TRUE);
}
public void remove(java.lang.String __v0, java.lang.String __v1, java.lang.String __v2, aos.jack.jak.cursor.BeliefState __d)
throws aos.jack.jak.beliefset.BeliefSetException
{
io.github.agentsoz.abmjack.env.ActionList__Tuple __t = new io.github.agentsoz.abmjack.env.ActionList__Tuple();
__t.actionID = __v0;
__t.state = __v1;
__t.parameters = __v2;
super.retractTuple(__t,__d);
}
public ActionList()
{
}
public ActionList(java.lang.String n)
{
super();
read(n);
}
class __Cursor extends aos.jack.jak.beliefset.ClosedWorldCursor {
public io.github.agentsoz.abmjack.env.ActionList__Tuple __tuple = null;
public aos.jack.jak.logic.Variable actionID;
public aos.jack.jak.logic.Variable state;
public aos.jack.jak.logic.Variable parameters;
public __Cursor()
{
__tuple = __hole;
}
public __Cursor(io.github.agentsoz.abmjack.env.ActionList__Tuple __t)
{
super();
__tuple = __t;
}
public int match(int __ti, int __st, int __c, boolean __k, int __ind)
{
io.github.agentsoz.abmjack.env.ActionList__Tuple[] __tab = __tables[__ti];
io.github.agentsoz.abmjack.env.ActionList__Tuple __t;
int __sz = __tab.length;
int __i;
if ((aos.jack.jak.core.Jak.debugging & aos.jack.jak.core.Jak.LOG_DB) != 0) {
aos.jack.jak.core.Jak.log.log("ActionList__Tuple:match:" + __ti + ":" + __st + ":" + __c + ":" + __k + ":" + __ind);
aos.jack.jak.core.Jak.log.log("Tuple=" + __tuple);
aos.jack.jak.core.Jak.log.log("Outputs are");
aos.jack.jak.core.Jak.log.log(" actionID:" + actionID);
aos.jack.jak.core.Jak.log.log(" state:" + state);
aos.jack.jak.core.Jak.log.log(" parameters:" + parameters);
}
for (__i = __st; __c > 0; __i = (__i + 1) % __sz, __c-- ) {
__t = __tab[__i];
if (__t == null) {
if (__ind < 0)
continue;
return -1;
}
if (__t == __hole)
continue;
if (__t.isFree) {
__tab[__i] = __hole;
continue;
}
if ((aos.jack.jak.core.Jak.debugging & aos.jack.jak.core.Jak.LOG_DB) != 0)
aos.jack.jak.core.Jak.log.log("t" + __i + ":" + __t);
try {
if (cp != null)
cp.backtrack();
if (actionID == null) {
if (!__tuple.actionID.equals(__t.actionID))
continue;
}
else {
if (!actionID.unify(__t.actionID))
continue;
}
if (__k)
return __i;
if (state == null) {
if (!__tuple.state.equals(__t.state))
continue;
}
else {
if (!state.unify(__t.state))
continue;
}
if (parameters == null) {
if (!__tuple.parameters.equals(__t.parameters))
continue;
}
else {
if (!parameters.unify(__t.parameters))
continue;
}
}
catch (java.lang.Exception e) {
continue;
}
return __i;
}
return -1;
}
public int hash(int __i)
{
return (__tuple == null?0:__tuple.hash(__i));
}
public aos.jack.jak.logic.ChoicePoint getChoicePoint()
{
if (actionID != null)
return actionID.getEnv().newChoicePoint();
if (state != null)
return state.getEnv().newChoicePoint();
if (parameters != null)
return parameters.getEnv().newChoicePoint();
return null;
}
public boolean isKeyGround()
{
if (actionID != null)
return false;
return true;
}
}
class __complex_1 extends aos.jack.plugin.view.rt.CleanupCursor {
java.lang.String actionID;
aos.jack.jak.logic.StringVariable __local_2;
aos.jack.jak.logic.StringVariable __local_3;
aos.jack.jak.cursor.Cursor __local_4;
public java.lang.Object genObject(int __index)
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal Object Construction");
return null;
}
public aos.jack.jak.cursor.Cursor genCursor(int __index)
throws java.lang.Exception
{
switch (__index) {
case 0:
{
return (qGetData(actionID,__local_2,__local_3));
}
case 1:
{
return (__local_4 = (aos.jack.jak.beliefset.BeliefSetCursor) (genCursor(0)));
}
}
aos.jack.jak.core.Jak.error("illegal Cursor Construction");
return null;
}
public aos.jack.jak.fsm.FSM genFSM(int __index)
throws java.lang.Exception
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal FSM Construction");
return null;
}
public boolean testCondition(int __index)
throws java.lang.Exception
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal test Construction");
return false;
}
public __complex_1(java.lang.String actionID)
{
super();
this.actionID = actionID;
}
java.lang.String __complex_1_fGetState()
throws java.lang.Exception
{
__local_2 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
__local_3 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
try {
genCursor(1);
__local_4.next();
return __local_2.getValue();
}
catch (java.lang.Exception e) {
e.printStackTrace();
java.lang.System.exit(1);
}
return null;
}
}
class __complex_2 extends aos.jack.plugin.view.rt.CleanupCursor {
java.lang.String actionID;
aos.jack.jak.logic.StringVariable __local_2;
aos.jack.jak.logic.StringVariable __local_3;
aos.jack.jak.cursor.Cursor __local_4;
public java.lang.Object genObject(int __index)
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal Object Construction");
return null;
}
public aos.jack.jak.cursor.Cursor genCursor(int __index)
throws java.lang.Exception
{
switch (__index) {
case 0:
{
return (qGetData(actionID,__local_3,__local_2));
}
case 1:
{
return (__local_4 = (aos.jack.jak.beliefset.BeliefSetCursor) (genCursor(0)));
}
}
aos.jack.jak.core.Jak.error("illegal Cursor Construction");
return null;
}
public aos.jack.jak.fsm.FSM genFSM(int __index)
throws java.lang.Exception
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal FSM Construction");
return null;
}
public boolean testCondition(int __index)
throws java.lang.Exception
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal test Construction");
return false;
}
public __complex_2(java.lang.String actionID)
{
super();
this.actionID = actionID;
}
java.lang.String __complex_2_fGetParameters()
throws java.lang.Exception
{
__local_2 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
__local_3 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
try {
genCursor(1);
__local_4.next();
return __local_2.getValue();
}
catch (java.lang.Exception e) {
e.printStackTrace();
java.lang.System.exit(1);
}
return null;
}
}
class __complex_3 extends aos.jack.plugin.view.rt.CleanupCursor {
aos.jack.jak.logic.StringVariable __local_2;
aos.jack.jak.logic.StringVariable __local_3;
aos.jack.jak.logic.StringVariable __local_4;
aos.jack.jak.cursor.Cursor __local_5;
public java.lang.Object genObject(int __index)
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal Object Construction");
return null;
}
public aos.jack.jak.cursor.Cursor genCursor(int __index)
throws java.lang.Exception
{
switch (__index) {
case 0:
{
return (qGetAll(__local_2,__local_3,__local_4));
}
case 1:
{
return (__local_5 = (aos.jack.jak.beliefset.BeliefSetCursor) (genCursor(0)));
}
}
aos.jack.jak.core.Jak.error("illegal Cursor Construction");
return null;
}
public aos.jack.jak.fsm.FSM genFSM(int __index)
throws java.lang.Exception
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal FSM Construction");
return null;
}
public boolean testCondition(int __index)
throws java.lang.Exception
{
switch (__index) {
}
aos.jack.jak.core.Jak.error("illegal test Construction");
return false;
}
public __complex_3()
{
super();
}
java.lang.String __complex_3_fDisplayAll()
throws java.lang.Exception
{
java.lang.System.out.println("Displaying all Actions");
__local_2 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
__local_3 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
__local_4 = (aos.jack.jak.logic.StringVariable) new_variable(java.lang.String.class);
try {
genCursor(1);
for (; __local_5.next(); ) {
java.lang.System.out.println("actionID: " + __local_2 + ", state: " + __local_3 + ", params: " + __local_4);
}
}
catch (java.lang.Exception e) {
e.printStackTrace();
java.lang.System.exit(1);
}
return null;
}
}
}