本文整理汇总了Java中jason.asSyntax.NumberTerm类的典型用法代码示例。如果您正苦于以下问题:Java NumberTerm类的具体用法?Java NumberTerm怎么用?Java NumberTerm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberTerm类属于jason.asSyntax包,在下文中一共展示了NumberTerm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: process
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
if (outerContent == null)
return null;
try {
String id = ((StringTerm)directive.getTerm(0)).getString();
if (directive.getArity() == 1) {
// it is implemented in java
outerContent.addFunction((Class<ArithFunction>)Class.forName(id));
} else if (directive.getArity() == 3) {
// is is implemented in AS
int arity = (int)((NumberTerm)directive.getTerm(1)).solve();
String predicate = ((StringTerm)directive.getTerm(2)).getString();
outerContent.addFunction(id, arity, predicate);
} else {
// error
logger.log(Level.SEVERE, "Wrong number of arguments for register_function "+directive);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error processing directive register_function.",e);
}
return null;
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:25,代码来源:FunctionRegister.java
示例2: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(final TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
checkArguments(args);
if (args.length == 1) {
return un.unifies(args[0], new NumberTermImpl(random.nextDouble()));
} else {
final int max = (int)((NumberTerm)args[1]).solve();
return new Iterator<Unifier>() {
int n = 0;
// we always have a next random number
public boolean hasNext() {
return (n < max || max == 0) && ts.getUserAgArch().isRunning();
}
public Unifier next() {
Unifier c = un.clone();
c.unifies(args[0], new NumberTermImpl(random.nextDouble()));
n++;
return c;
}
public void remove() {}
};
}
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:26,代码来源:random.java
示例3: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
if (args[0].isNumeric() && args[1].isString()) {
return un.unifies(args[2], deleteFromString((int)((NumberTerm)args[0]).solve(),(StringTerm)args[1]));
}
if (args[0].isNumeric() && args[1].isList()) {
return un.unifies(args[2], deleteFromList((int)((NumberTerm)args[0]).solve(),(ListTerm)args[1]));
}
if (args[0].isString() && args[1].isString()) {
return un.unifies(args[2], deleteFromString((StringTerm)args[0],(StringTerm)args[1]));
}
if (args[0].isString()) { // consider arg[1] as string
return un.unifies(args[2], deleteFromString((StringTerm)args[0], new StringTermImpl(args[1].toString())));
}
// first element as term
if (args[1].isList()) {
return un.unifies(args[2], deleteFromList(args[0],(ListTerm)args[1], un.clone()));
}
throw new JasonException("Incorrect use of the internal action '.delete' (see documentation).");
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:25,代码来源:delete.java
示例4: structure2timestamp
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
/** translates structure like "timestamp(Y,M,D,H,M,S)" into a SQL timestamp */
@SuppressWarnings("deprecation")
public static Timestamp structure2timestamp(Term timestamp) throws Exception {
if (timestamp.isStructure()) {
Structure s = (Structure)timestamp;
if (s.getFunctor().equals(timestampFunctor) && s.getArity() == 6) {
return new Timestamp(
(int)((NumberTerm)s.getTerm(0)).solve() - 1900,
(int)((NumberTerm)s.getTerm(1)).solve(),
(int)((NumberTerm)s.getTerm(2)).solve(),
(int)((NumberTerm)s.getTerm(3)).solve(),
(int)((NumberTerm)s.getTerm(4)).solve(),
(int)((NumberTerm)s.getTerm(5)).solve(),
0
);
}
}
return null;
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:JDBCPersistentBB.java
示例5: testSolve
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
public void testSolve() throws Exception {
NumberTerm nb;
nb = ArithExpr.parseExpr("3");
assertEquals(nb.solve(),3.0);
nb = ArithExpr.parseExpr("3+2");
assertEquals(nb.solve(),new NumberTermImpl(5).solve());
nb = ArithExpr.parseExpr("3+2*5");
assertFalse(nb.isLiteral());
assertTrue(nb.solve() == 13);
nb = ArithExpr.parseExpr("(3+2)*5");
assertTrue(nb.solve() == 25);
nb = ArithExpr.parseExpr("3 - 5");
assertTrue(nb.solve() == -2);
nb = ArithExpr.parseExpr("-(3+5*(4----1))*-1-15");
// System.out.println(nb+"="+nb.solve());
assertTrue(nb.solve() == 13d);
nb = ArithExpr.parseExpr("3+5.1*2");
// System.out.println(nb+"="+nb.solve());
assertTrue(nb.solve() == 13.2);
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:27,代码来源:ExprTermTest.java
示例6: testVarTermAsNumber
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
public void testVarTermAsNumber() throws Exception {
Term k = new VarTerm("K");
Unifier u = new Unifier();
NumberTermImpl n = new NumberTermImpl(10);
assertTrue(n.isNumeric());
assertFalse(n.isVar());
assertTrue(u.unifies(k, n));
k = k.capply(u);
// System.out.println(k+" u="+u);
assertTrue(k.isNumeric());
assertFalse(k.isLiteral());
ArithExpr exp = new ArithExpr((NumberTerm)k, ArithmeticOp.plus, new NumberTermImpl(20));
assertTrue(exp.solve() == 30d);
NumberTerm nt = ArithExpr.parseExpr("5 div 2");
assertTrue(nt.solve() == 2d);
nt = ArithExpr.parseExpr("5 mod 2");
assertTrue(nt.solve() == 1d);
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:VarTermTest.java
示例7: testArithExpr
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
public void testArithExpr() throws Exception {
NumberTerm t1 = ArithExpr.parseExpr("1 - 1 - 1");
assertTrue(t1 != null);
assertEquals(t1.solve(), -1.0);
t1 = ArithExpr.parseExpr("1 - 1 - 1 -1");
assertTrue(t1 != null);
assertEquals(t1.solve(), -2.0);
t1 = ArithExpr.parseExpr("1 - (1 - 1)");
assertTrue(t1 != null);
assertEquals(t1.solve(), 1.0);
t1 = ArithExpr.parseExpr("8 / 4 / 2");
assertTrue(t1 != null);
assertEquals(t1.solve(), 1.0);
}
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:ASParserTest.java
示例8: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception{
try {
boolean result = false;
int iagx = (int)((NumberTerm)terms[0]).solve();//Atual
int iagy = (int)((NumberTerm)terms[1]).solve();//Atual
String dir = terms[2].toString();
if(dir.equals("up")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(iagx))) && un.unifies(terms[4], new Atom(String.valueOf(1))));
}else if(dir.equals("down")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(iagx))) && un.unifies(terms[4], new Atom(String.valueOf(48))));
}else if(dir.equals("left")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(1))) && un.unifies(terms[4], new Atom(String.valueOf(iagy))));
}else if(dir.equals("right")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(48))) && un.unifies(terms[4], new Atom(String.valueOf(iagy))));
}
return result;
}catch(Throwable e) {
e.printStackTrace();
return false;
}
}
开发者ID:MTeixeira24,项目名称:Jasovacs_fire,代码行数:24,代码来源:get_sign_point.java
示例9: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
WorldModel model = ((MinerArch)ts.getUserAgArch()).getModel();
if (model == null) {
ts.getLogger().log(Level.SEVERE, "no model to get near_least_visited!");
} else {
NumberTerm agx = (NumberTerm)terms[0];
NumberTerm agy = (NumberTerm)terms[1];
Location n = model.getNearLeastVisited((int)agx.solve(), (int)agy.solve());
un.unifies(terms[2], new NumberTermImpl(n.x));
un.unifies(terms[3], new NumberTermImpl(n.y));
//ts.getLogger().info("at "+agx+","+agy+" to "+n.x+","+n.y);
return true;
}
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "near_least_visited error: "+e, e);
}
return false;
}
开发者ID:jason-lang,项目名称:apps,代码行数:21,代码来源:near_least_visited.java
示例10: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
WorldModel model = ((MinerArch)ts.getUserAgArch()).getModel();
if (model == null) {
ts.getLogger().log(Level.SEVERE, "no model to get near_least_visited!");
} else {
if (oldTarget != null && model.inGrid(oldTarget)) {
model.remove(WorldModel.TARGET, oldTarget);
}
NumberTerm x = (NumberTerm)terms[0];
NumberTerm y = (NumberTerm)terms[1];
Location t = new Location((int)x.solve(), (int)y.solve());
if (model.inGrid(t)) {
model.add(WorldModel.TARGET, t);
oldTarget = t;
}
}
return true;
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "jia.set_target error: "+e, e);
}
return false;
}
开发者ID:jason-lang,项目名称:apps,代码行数:25,代码来源:set_target.java
示例11: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
WorldModel model = ((MinerArch)ts.getUserAgArch()).getModel();
int agId = MiningEnvironment.getAgId(ts.getUserAgArch().getAgName());
int in = (int)((NumberTerm)terms[0]).solve();
int ig = 0;
int resultIndex = 2;
if (terms.length == 3) {
// use the number of golds informed as argument
ig = (int)((NumberTerm)terms[1]).solve();
} else {
// use the number of golds the agent is carrying
ig = model.getGoldsWithAg(agId);
resultIndex = 1;
}
int r = (int)(in + in * model.getAgFatigue(agId, ig));
return un.unifies(terms[resultIndex], new NumberTermImpl(r));
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "jia.add_fatigue error: "+e, e);
}
return false;
}
开发者ID:jason-lang,项目名称:apps,代码行数:26,代码来源:add_fatigue.java
示例12: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
public boolean execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
NumberTerm agx = (NumberTerm)terms[0].clone(); un.apply((Term)agx);
NumberTerm agy = (NumberTerm)terms[1].clone(); un.apply((Term)agy);
NumberTerm tox = (NumberTerm)terms[2].clone(); un.apply((Term)tox);
NumberTerm toy = (NumberTerm)terms[3].clone(); un.apply((Term)toy);
int iagx = (int)agx.solve();
int iagy = (int)agy.solve();
int itox = (int)tox.solve();
int itoy = (int)toy.solve();
return new Location(iagx,iagy).isNeigbour(new Location(itox,itoy));
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
开发者ID:jason-lang,项目名称:apps,代码行数:17,代码来源:neighbour.java
示例13: admCommand
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
/**
* Commands that the owner of the scheme can perform.
*
* @param cmd, possible values (as strings):
* commitMission(<agent>,<mission>),
* goalDone(<agent>,<goal>) -- for performance goals --,
* goalSatisfied(<goal>) -- for achievement goals --
* setCardinality(<element type>,<element id>,<new min>,<new max>)
* [element type=mission]
*
* @throws CartagoException
* @throws jason.asSyntax.parser.ParseException
* @throws MoiseException
* @throws NoValueException
*/
@OPERATION @LINK public void admCommand(String cmd) throws CartagoException, jason.asSyntax.parser.ParseException, NoValueException, MoiseException, ParseException {
if (!running) return;
// this operation is available only for the owner of the artifact
if ((!getOpUserName().equals(ownerAgent)) && !getOpUserName().equals("workspace-manager")) {
failed("Error: agent '"+getOpUserName()+"' is not allowed to run "+cmd,"reason",new JasonTermWrapper("not_allowed_to_start(admCommand)"));
} else {
Literal lCmd = ASSyntax.parseLiteral(cmd);
if (lCmd.getFunctor().equals("goalDone")) {
goalDone(fixAgName(lCmd.getTerm(0).toString()), lCmd.getTerm(1).toString());
} else if (lCmd.getFunctor().equals("commitMission")) {
commitMission(fixAgName(lCmd.getTerm(0).toString()), lCmd.getTerm(1).toString());
} else if (lCmd.getFunctor().equals("goalSatisfied")) {
enableSatisfied(lCmd.getTerm(0).toString());
} else if (lCmd.getFunctor().equals("setCardinality")) {
setCardinality(lCmd.getTerm(0).toString(), lCmd.getTerm(1).toString(), (int)((NumberTerm)lCmd.getTerm(2)).solve(), (int)((NumberTerm)lCmd.getTerm(3)).solve());
}
}
}
开发者ID:moise-lang,项目名称:moise,代码行数:34,代码来源:SchemeBoard.java
示例14: admCommand
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
/**
* Commands that the owner of the group can perform.
*
* @param cmd, possible values (as strings):
* adoptRole(<agent>,<role>)
* setCardinality(<element type>,<element id>,<new min>,<new max>)
* [element type= role/subgroup]
*
* @throws CartagoException
* @throws jason.asSyntax.parser.ParseException
* @throws NoValueException
* @throws MoiseException
*/
@OPERATION @LINK public void admCommand(String cmd) throws CartagoException, jason.asSyntax.parser.ParseException, NoValueException, MoiseException, ParseException {
// this operation is available only for the owner of the artifact
if (getCurrentOpAgentId() != null && (!getOpUserName().equals(ownerAgent)) && !getOpUserName().equals("workspace-manager")) {
failed("Error: agent '"+getOpUserName()+"' is not allowed to run "+cmd,"reason",new JasonTermWrapper("not_allowed_to_start(admCommand)"));
} else {
Literal lCmd = ASSyntax.parseLiteral(cmd);
if (lCmd.getFunctor().equals("adoptRole")) {
adoptRole(fixAgName(lCmd.getTerm(0).toString()), lCmd.getTerm(1).toString());
} else if (lCmd.getFunctor().equals("leaveRole")) {
System.out.println("adm leave role not implemented yet! come back soon");
} else if (lCmd.getFunctor().equals("setCardinality")) {
setCardinality(lCmd.getTerm(0).toString(), lCmd.getTerm(1).toString(), (int)((NumberTerm)lCmd.getTerm(2)).solve(), (int)((NumberTerm)lCmd.getTerm(3)).solve());
}
}
}
开发者ID:moise-lang,项目名称:moise,代码行数:29,代码来源:GroupBoard.java
示例15: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
LocalWorldModel model = ((MinerArch)ts.getUserAgArch()).getModel();
if (model == null) {
ts.getLogger().log(Level.SEVERE, "no model to get near_least_visited!");
} else {
NumberTerm agx = (NumberTerm)terms[0];
NumberTerm agy = (NumberTerm)terms[1];
Location n = model.getNearLeastVisited((int)agx.solve(), (int)agy.solve());
un.unifies(terms[2], new NumberTermImpl(n.x));
un.unifies(terms[3], new NumberTermImpl(n.y));
//ts.getLogger().info("at "+agx+","+agy+" to "+n.x+","+n.y);
return true;
}
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "near_least_visited error: "+e, e);
}
return false;
}
开发者ID:jason-lang,项目名称:jason,代码行数:21,代码来源:near_least_visited.java
示例16: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
WorldModel model = ((MinerArch)ts.getUserAgArch()).getModel();
if (model == null) {
ts.getLogger().log(Level.SEVERE, "no model to get near_least_visited!");
} else {
if (oldTarget != null && model.inGrid(oldTarget)) {
model.remove(WorldModel.TARGET, oldTarget);
}
NumberTerm x = (NumberTerm)terms[0];
NumberTerm y = (NumberTerm)terms[1];
Location t = new Location((int)x.solve(), (int)y.solve());
if (model.inGrid(t)) {
model.add(WorldModel.TARGET, t);
oldTarget = t;
}
}
return true;
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "jia.set_target error: "+e, e);
}
return false;
}
开发者ID:jason-lang,项目名称:jason,代码行数:25,代码来源:set_target.java
示例17: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
try {
WorldModel model = ((MinerArch)ts.getUserAgArch()).getModel();
int agId = MinerArch.getAgId(ts.getUserAgArch().getAgName());
int in = (int)((NumberTerm)terms[0]).solve();
int ig = 0;
int resultIndex = 2;
if (terms.length == 3) {
// use the number of golds informed as argument
ig = (int)((NumberTerm)terms[1]).solve();
} else {
// use the number of golds the agent is carrying
ig = model.getGoldsWithAg(agId);
resultIndex = 1;
}
int r = (int)(in + in * model.getAgFatigue(agId, ig));
return un.unifies(terms[resultIndex], new NumberTermImpl(r));
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "jia.add_fatigue error: "+e, e);
}
return false;
}
开发者ID:jason-lang,项目名称:jason,代码行数:26,代码来源:add_fatigue.java
示例18: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
if (args.length>0 && args[0].isNumeric()) {
NumberTerm n = (NumberTerm)args[0];
switch ((int)n.solve()) {
case 0:
ts.getLogger().setLevel(Level.SEVERE);
break;
case 1:
ts.getLogger().setLevel(Level.INFO);
break;
case 2:
ts.getLogger().setLevel(Level.FINE);
System.out.println("*****");
break;
}
return true;
} else {
return false;
}
}
开发者ID:jason-lang,项目名称:jason,代码行数:21,代码来源:verbose.java
示例19: execute
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
@Override
public Object execute(final TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
checkArguments(args);
if (args.length == 1) {
return un.unifies(args[0], new NumberTermImpl(random.nextDouble()));
} else {
final int max = (int)((NumberTerm)args[1]).solve();
return new Iterator<Unifier>() {
int n = 0;
// we always have a next random number
public boolean hasNext() {
return (n < max || max == 0) && ts.getUserAgArch().isRunning();
}
public Unifier next() {
Unifier c = un.clone();
c.unifies(args[0], new NumberTermImpl(random.nextDouble()));
n++;
return c;
}
public void remove() {}
};
}
}
开发者ID:jason-lang,项目名称:jason,代码行数:26,代码来源:random.java
示例20: structure2timestamp
import jason.asSyntax.NumberTerm; //导入依赖的package包/类
/** translates structure like "timestamp(Y,M,D,H,M,S)" into a SQL timestamp */
@SuppressWarnings("deprecation")
public static Timestamp structure2timestamp(Term timestamp) throws Exception {
if (timestamp.isStructure()) {
Structure s = (Structure)timestamp;
if (s.getFunctor().equals(timestampFunctor) && s.getArity() == 6) {
return new Timestamp(
(int)((NumberTerm)s.getTerm(0)).solve() - 1900,
(int)((NumberTerm)s.getTerm(1)).solve(),
(int)((NumberTerm)s.getTerm(2)).solve(),
(int)((NumberTerm)s.getTerm(3)).solve(),
(int)((NumberTerm)s.getTerm(4)).solve(),
(int)((NumberTerm)s.getTerm(5)).solve(),
0
);
}
}
return null;
}
开发者ID:jason-lang,项目名称:jason,代码行数:20,代码来源:JDBCPersistentBB.java
注:本文中的jason.asSyntax.NumberTerm类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论