Re: JESS: [EXTERNAL] Jess exception: ' ' is a list, not a string
Thanks for your response Wolfgang, Yes, getMyUnits() returns an ArrayListUnit; I don't believe this likely to be the problem since I have these in other rules that are functioning. More debugging shows that the error is occurring in routine Value.stringValue. Do you see anywhere where I am trying to get the string value of a list? Hunter On Mon, Mar 12, 2012 at 9:38 AM, Wolfgang Laun wolfgang.l...@gmail.comwrote: Are you sure that (?*bwapi* getMyUnits) returns a list? Jess' foreach isn't quite as tolerant as for in Java 1.5 and later. You may have to return an java.util.iterator. -W On 10/03/2012, Hunter McMillen mcmil...@gmail.com wrote: I am receiving the error in the subject line when one of my rules is firing. I can't seem to find any other forum posts about it, here is my rule: (defrule build-supply-depot (minerals (value ?x:( ?x 100))) = (try (foreach ?u (?*bwapi* getMyUnits) (if (= (?u getTypeID) ?*SCV_ID*) then (bind ?p (call get-next-build-tile())) (call ?*bwapi* drawCircle ?p.x ?p.y 100 111 FALSE FALSE) (call ?*bwapi* build (?u getID) ?p.x ?p.y (UnitType$UnitTypes.Terran_Supply_Depot ordinal)) (break))) catch (printout t (call ?ERROR toString) crlf) ) ) and here is the exact error message: while executing (foreach ?u (call ?*bwapi* getMyUnits) (if (= (call ?u getTypeID) ?*SCV_ID*) then (bind ?p (call get-next-build-tile )) (call ?*bwapi* drawCircle ?p.x ?p.y 100 111 FALSE FALSE) (call ?*bwapi* build (call ?u getID) ?p.x ?p.y (UnitType$UnitTypes.Terran_Supply_Depot ordinal)) (break))). Message: '' is a list, not a string. But the error doesn't give me a line number. Any help would be appreciated. Thanks, Hunter McMillen To unsubscribe, send the words 'unsubscribe jess-users y...@address.com' in the BODY of a message to majord...@sandia.gov, NOT to the list (use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
Re: JESS: [EXTERNAL] Jess exception: ' ' is a list, not a string
Here is the stacktrace: Message: '' is a list, not a string. at jess.Value.a(Unknown Source) at jess.Value.a(Unknown Source) at jess.Value.a(Unknown Source) at jess.Value.stringValue(Unknown Source) at jess.Value.symbolValue(Unknown Source) at jess.dx.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.ce.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.f4.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.cu.a(Unknown Source) at jess.cu.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.i.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.Defrule.a(Unknown Source) at jess.Activation.a(Unknown Source) at jess.en.a(Unknown Source) at jess.en.a(Unknown Source) at jess.Rete.if(Unknown Source) at jess.Rete.run(Unknown Source) at hunterai.HunterAIClient.gameUpdate(HunterAIClient.java:156) at eisbot.proxy.JNIBWAPI.gameUpdate(JNIBWAPI.java:795) at eisbot.proxy.JNIBWAPI.startClient(Native Method) at eisbot.proxy.JNIBWAPI.start(JNIBWAPI.java:597) at hunterai.HunterAIClient.start(HunterAIClient.java:102) at hunterai.HunterAIClient.main(HunterAIClient.java:42) The first line in my code that the trace lists is where I run the engine from my Java application: engine.run(); Hunter On Mon, Mar 12, 2012 at 11:40 AM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: Hmmm. If that's the whole error message, then the error should be occurring executing that foreach function, not a function nested inside it; otherwise there would be more context information. But foreach doesn't try to coerce anything into a string, so that doesn't make sense. Inside your catch block, do this: (?ERROR printStackTrace) And show us what you get; that should narrow it down quite a bit. From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Fri, 9 Mar 2012 23:10:06 -0500 To: jess-users@sandia.gov Subject: JESS: [EXTERNAL] Jess exception: ' ' is a list, not a string I am receiving the error in the subject line when one of my rules is firing. I can't seem to find any other forum posts about it, here is my rule: (defrule build-supply-depot (minerals (value ?x:( ?x 100))) = (try (foreach ?u (?*bwapi* getMyUnits) (if (= (?u getTypeID) ?*SCV_ID*) then (bind ?p (call get-next-build-tile())) (call ?*bwapi* drawCircle ?p.x ?p.y 100 111 FALSE FALSE) (call ?*bwapi* build (?u getID) ?p.x ?p.y (UnitType$UnitTypes.Terran_Supply_Depot ordinal)) (break))) catch (printout t (call ?ERROR toString) crlf) ) ) and here is the exact error message: while executing (foreach ?u (call ?*bwapi* getMyUnits) (if (= (call ?u getTypeID) ?*SCV_ID*) then (bind ?p (call get-next-build-tile )) (call ?*bwapi* drawCircle ?p.x ?p.y 100 111 FALSE FALSE) (call ?*bwapi* build (call ?u getID) ?p.x ?p.y (UnitType$UnitTypes.Terran_Supply_Depot ordinal)) (break))). Message: '' is a list, not a string. But the error doesn't give me a line number. Any help would be appreciated. Thanks, Hunter McMillen
Re: JESS: [EXTERNAL] Jess exception: ' ' is a list, not a string
That was exactly the problem, thanks. What is the general rule for function calling in Jess, always without parentheses? I never would have caught that error because when I see something like get-next-build-tile() the parentheses tell me it is a function. Seeing it without the parens makes me think it is a variable, even without the ? sign is front. Also, as a corollary question; I am using an enumerated type in my rule: (import eisbot.proxy.types.UnitType$UnitTypes) (defrule build-supply-depot (minerals (value ?x:( ?x 100))) = (try (foreach ?u (?*bwapi* getMyUnits) (if (= (?u getTypeID) ?*SCV_ID*) then (bind ?p (call get-next-build-tile())) (call ?*bwapi* drawCircle ?p.x ?p.y 100 111 FALSE FALSE) * (call ?*bwapi* build (?u getID) ?p.x ?p.y (UnitType$UnitTypes.Terran_Supply_Depot ordinal))* (break))) catch (printout t (call ?ERROR toString) crlf) ) ) But after importing when my rule tries to execute the bolded line above, I get a class not found exception: Message: Class not found. at jess.dx.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.dx.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.f4.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.cu.a(Unknown Source) at jess.cu.call(Unknown Source) at jess.ac.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.Defrule.a(Unknown Source) at jess.Activation.a(Unknown Source) at jess.en.a(Unknown Source) at jess.en.a(Unknown Source) at jess.Rete.if(Unknown Source) at jess.Rete.run(Unknown Source) at hunterai.HunterAIClient.gameUpdate(HunterAIClient.java:156) at eisbot.proxy.JNIBWAPI.gameUpdate(JNIBWAPI.java:795) at eisbot.proxy.JNIBWAPI.startClient(Native Method) at eisbot.proxy.JNIBWAPI.start(JNIBWAPI.java:597) at hunterai.HunterAIClient.start(HunterAIClient.java:102) at hunterai.HunterAIClient.main(HunterAIClient.java:42) Caused by: java.lang.ClassNotFoundException: new at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at jess.dc.for(Unknown Source) at jess.dc.if(Unknown Source) at jess.Rete.findClass(Unknown Source) ... 28 more any ideas? Hunter On Mon, Mar 12, 2012 at 1:48 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: OK, I looked in the magic decoder file and I see a call being invoked inside a bind, so that fits only the line of code below. And lo and behold, look at it: the second argument to call, which should be the name of the function to call, is a pair of empty parentheses — i.e., a list. This line is asking Jess to to call the static method named () on the class named get-next-build-tile -- surely not what you intended. If you're just calling a deffunction by this name, then you just want (bind ?p (get-next-build-tile)) From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Mon, 12 Mar 2012 12:16:29 -0400 To: jess-users@sandia.gov Subject: Re: JESS: [EXTERNAL] Jess exception: ' ' is a list, not a string (bind ?p (call get-next-build-tile()))
Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
After a couple hours on the mail archive, I found the problem. When I added the defglobal to the Rete engine I used this command: *Defglobal playerIDGlobal = new Defglobal(*PLAYER_ID*, new Value(self.getID()));* *engine.addDefglobal(playerIDGlobal);* * * But this doesn't specify a type for the Value object, so when I tried to match against *?*PLAYER_ID** on the lhs of my rules it always returned false because the type of the defglobal was defaulted to Java object. I changed the command to this: *Defglobal playerIDGlobal = new Defglobal(*PLAYER_ID*, new Value(self.getID(), RU.INTEGER));* *engine.addDefglobal(playerIDGlobal);* * * And now everything seems to be working fine, Just out of curiosity though how does Jess infer types of variables when it is matching on the lhs of rules? Thanks, Hunter McMillen On Wed, Jan 11, 2012 at 6:04 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: For everything to work right, you always have to use the asterisks (as I said, they're part of the name), and you must include a (defglobal) declaration before using the variable. Setting a global variable by hand without declaring it first produces undefined results (I.e., it'll work right some of the time.) From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Wed, 11 Jan 2012 16:37:11 -0500 To: jess-users@sandia.gov Subject: Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule I placed the asterisks around PLAYER_ID then still received an error when the rule fired: No such variable *PLAYER_ID* But then noticed that when I call setVariable, I name the variable PLAYER_ID not *PLAYER_ID* so I changed my statement to this: *engine.getGlobalContext().setVariable(*PLAYER_ID*, new Value(player.getID());* and everything works fine. Does* getGlobalContext().setVariable(...)* define global variables implicitly? or do you have to include the asterisks like I did? Thanks. Hunter McMillen On Wed, Jan 11, 2012 at 3:13 PM, Friedman-Hill, Ernest ejfr...@sandia.gov wrote: The asterisks are part of the defglobal's name. You're not comparing to the defglobal: you're binding the value in the slot to a new variable. It's not legal to negate such a constraint in its first use, as the error message said. You need to use * (unit (ID ?id) (typeID ?typeID) (player ~?*PLAYER_ID*))* From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Wed, 11 Jan 2012 14:38:31 -0500 To: jess-users@sandia.gov Subject: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: *engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID());* * * And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID *(defrule myUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID))* *=* * .)* * * But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID *(defrule enemyUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID))* *=* * .)* * * How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: *engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID());* * * And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID *(defrule myUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID))* *=* * .)* * * But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID *(defrule enemyUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID))* *=* * .)* * * How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
I placed the asterisks around PLAYER_ID then still received an error when the rule fired: No such variable *PLAYER_ID* But then noticed that when I call setVariable, I name the variable PLAYER_ID not *PLAYER_ID* so I changed my statement to this: *engine.getGlobalContext().setVariable(*PLAYER_ID*, new Value(player.getID());* and everything works fine. Does* getGlobalContext().setVariable(...)* define global variables implicitly? or do you have to include the asterisks like I did? Thanks. Hunter McMillen On Wed, Jan 11, 2012 at 3:13 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: The asterisks are part of the defglobal's name. You're not comparing to the defglobal: you're binding the value in the slot to a new variable. It's not legal to negate such a constraint in its first use, as the error message said. You need to use * (unit (ID ?id) (typeID ?typeID) (player ~?*PLAYER_ID*))* From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Wed, 11 Jan 2012 14:38:31 -0500 To: jess-users@sandia.gov Subject: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: *engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID());* * * And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID *(defrule myUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID))* *=* * .)* * * But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID *(defrule enemyUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID))* *=* * .)* * * How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
JESS: [EXTERNAL] Iterate over a Java List in Jess
Is there anyway to iterate over a Java List object from Jess? I have a Java object that I store in a Jess variable: engine.getGlobalContext().setVariable(bwapi, new Value(bwapi)); one of the methods that can be called on bwapi returns a Java ArrayList, and I would like to be able to iterate over this list to check certain properties of its elements. Right now I am doing this: engine.executeCommand((bind ?units (create$ =(?bwapi getMyUnits; engine.executeCommand(foreach ?u ?units (printout t ?u crlf))); but when the units are supposed to be printed all I get is: = Java-Object:java.util.ArrayList Any ideas? Thanks, Hunter M
Re: JESS: [EXTERNAL] Access public enum inside of a class
Thanks very much that worked perfectly. Hunter McMillen On Wed, Dec 7, 2011 at 5:10 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: Nested enums, like nested classes, actually secretly have a name like UnitType$UnitTypes. I haven't tried this specifically for enums, but I suspect this would work: engine.executeCommand((import eisbot.proxy.types.UnitType$UnitTypes)); From: owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] On Behalf Of Hunter McMillen Sent: Wednesday, December 07, 2011 4:27 PM To: jess-users Subject: JESS: [EXTERNAL] Access public enum inside of a class Hi everyone, I am trying to use an enum from one of my Java classes inside of Jess. I read a forum post that said I could use the (import enum-name) feature to import enums into Jess, but that only seems to work when the enum is itself in a separate file. I have a class called UnitType, inside of it there is a public enum called UnitTypes where all of the UnitTypes in my game are listed. In Java to access this I would use UnitType.UnitTypes.Element_in_enum to get to the enum
JESS: [EXTERNAL] Access public enum inside of a class
Hi everyone, I am trying to use an enum from one of my Java classes inside of Jess. I read a forum post that said I could use the (import enum-name) feature to import enums into Jess, but that only seems to work when the enum is itself in a separate file. I have a class called UnitType, inside of it there is a public enum called UnitTypes where all of the UnitTypes in my game are listed. In Java to access this I would use UnitType.UnitTypes.Element_in_enum to get to the enum. When I try this in Jess however, I get an error: *Rete engine = new Rete();* *engine.executeCommand((import eisbot.proxy.types.UnitType.UnitTypes));* an error occurs,* java.lang.ClassNotFoundException: eisbot.proxy.types.UnitType.UnitTypes* I am curious as to how I could go about accessing an enum that is inside of a Java class from Jess. any help would be appreciated. Thanks Hunter McMillen
Re: [EXTERNAL] Re: JESS: Ignore slots when matching lhs of rules
This is what I thought it should be so I was confused when my rule wasn't firing. Thank you for your response. Somehow magically this morning the rule is firing as it should be. Ill attribute that to you :) Thanks On Fri, Nov 11, 2011 at 12:47 AM, Wolfgang Laun wolfgang.l...@gmail.comwrote: You need not worry about the object fields you don't care about when matching the unit fact in a rule. By definition, only slots used in the pattern matter; all others are literally don't care. -W On 11 November 2011 04:57, Hunter McMillen mcmil...@gmail.com wrote: Hi everyone, I am trying to match the lhs of a rule using a template that has 112 slots that is defined from a Java class. Here is the template definition (from show-deftemplates): (deftemplate MAIN::unit $JAVA-OBJECT$ eisbot.proxy.model.Unit (declare (from-class eisbot.proxy.model.Unit))) Now every time that I encounter a unit object in my application I define an instance of the unit to Jess from Java: engine.defclass(unit, eisbot.proxy.model.Unit, null, true); (I only do this the first time) Unit unit = //retrieve a unit engine.definstance(unit, unit, false); All of this above is working as it should be, but now when I try to match a unit in a rule I am having trouble: String unitSeen = (defrule unitSeen + (unit (ID ?id) (typeID ?typeID)) + = + (printout t \Unit seen with ID: \ ?id crlf)); engine.executeCommand(unitSeen); The problem is that the Unit class has 112 attributes, I am only listing two ID and typeID, and there are probably only another handful that I care about and need to use. Is there any way to ignore the rest of the slots in the template, matching only on a few slots? Goal: The main goal of what I am trying to is that when I encounter a Unit in my game application, I want to assert that unit object to Jess as a fact, then match rules on the existence of a Unit. Right now I only want to match on the existence of ANY unit, but later on the matches will be more specific. Any help would be most appreciated. Thanks. Hunter McMillen
JESS: Ignore slots when matching lhs of rules
Hi everyone, I am trying to match the lhs of a rule using a template that has 112 slots that is defined from a Java class. Here is the template definition (from show-deftemplates): (deftemplate MAIN::unit $JAVA-OBJECT$ eisbot.proxy.model.Unit (declare (from-class eisbot.proxy.model.Unit))) Now every time that I encounter a unit object in my application I define an instance of the unit to Jess from Java: engine.defclass(unit, eisbot.proxy.model.Unit, null, true); (I only do this the first time) Unit unit = //retrieve a unit engine.definstance(unit, unit, false); All of this above is working as it should be, but now when I try to match a unit in a rule I am having trouble: String unitSeen = (defrule unitSeen + (unit (ID ?id) (typeID ?typeID)) + = + (printout t \Unit seen with ID: \ ?id crlf)); engine.executeCommand(unitSeen); The problem is that the Unit class has 112 attributes, I am only listing two ID and typeID, and there are probably only another handful that I care about and need to use. Is there any way to ignore the rest of the slots in the template, matching only on a few slots? Goal: The main goal of what I am trying to is that when I encounter a Unit in my game application, I want to assert that unit object to Jess as a fact, then match rules on the existence of a Unit. Right now I only want to match on the existence of ANY unit, but later on the matches will be more specific. Any help would be most appreciated. Thanks. Hunter McMillen
Re: JESS: Is it possible to bind a Java object directly to a Jess variable without creating a new object?
Thanks for your quick reply. After I manage to get my Java object into Jess, can I assert it as a fact? Then have rules lhs match on the existence of some object with attributes x, y, and z? Hunter On Fri, Nov 4, 2011 at 4:01 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: ** There are (obviously) two options: (a) put the object somewhere accessible, and run Jess code that retrieves it, or (b) use Jess's Java API to set a Jess variable to contain the object. Either would work. The store/fetch mechanism is sort of an built-in easy way to do (a). Alternatively, say there's a global variable ?*x* defined in your Jess program. Then you can say engine.getGlobalContext().setVariable(*x*, new Value(unit)); and your Jess code can later get the value of *x*. If you don't like using variables this way, there's always directly invoking Jess functions from Java. Here we invoke 'add' to add the object to working memory directly: new Funcall(add, engine).arg(new Value(unit)).execute(engine.getGlobalContext()); -- *From:* owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] *On Behalf Of *Hunter McMillen *Sent:* Friday, November 04, 2011 1:08 PM *To:* jess-users *Subject:* JESS: Is it possible to bind a Java object directly to a Jess variable without creating a new object? Hi everyone, I am trying to assert to Jess that an object exists when I encounter a new object in my Java program. Right now I am using a template to mirror that object (i.e I have slot values for all of the Java objects fields) but this seems redundant to me. Is there any way to just bind a Java object to a Jess variable without creating a new Java object? A lot of the examples I see online and from JIA are of the form: (bind ?map (new HashMap)) or (call Classname method params...) but these either create a new object or call static methods. I already have the Java object and just want to store it. But I was hoping that there was someway I could do something like this: public Rete engine = new Rete(); public void unitDiscovered() { Unit unit = some unit encountered; //Java object engine.executeCommand((bind ?unit unit)); engine.executeCommand((assert ?unit)); } Or would I have to use the store() and fetch() methods for this? public void unitDiscovered() { Unit unit = some unit encountered; //Java object engine.store(UNIT, unit); engine.executeCommand((bind ?unit (fetch UNIT)); engine.executeCommand((assert ?unit)); } Basically I want to know the best practice for binding Java objects to Jess variables so I can assert them to the engine. Thanks, Hunter McMillen
JESS: Is it possible to bind a Java object directly to a Jess variable without creating a new object?
Hi everyone, I am trying to assert to Jess that an object exists when I encounter a new object in my Java program. Right now I am using a template to mirror that object (i.e I have slot values for all of the Java objects fields) but this seems redundant to me. Is there any way to just bind a Java object to a Jess variable without creating a new Java object? A lot of the examples I see online and from JIA are of the form: (bind ?map (new HashMap)) or (call Classname method params...) but these either create a new object or call static methods. I already have the Java object and just want to store it. But I was hoping that there was someway I could do something like this: public Rete engine = new Rete(); public void unitDiscovered() { Unit unit = some unit encountered; //Java object engine.executeCommand((bind ?unit unit)); engine.executeCommand((assert ?unit)); } Or would I have to use the store() and fetch() methods for this? public void unitDiscovered() { Unit unit = some unit encountered; //Java object engine.store(UNIT, unit); engine.executeCommand((bind ?unit (fetch UNIT)); engine.executeCommand((assert ?unit)); } Basically I want to know the best practice for binding Java objects to Jess variables so I can assert them to the engine. Thanks, Hunter McMillen
Re: JESS: Call Jess from C++ via JNI
Well I am trying to create an agent to compete in the Starcraft AI competition for next year, the API that the agents all use is called BWAPI: http://code.google.com/p/bwapi/, but this is also a standard library that some of the agents use that would be really useful for for my agent called BWSAL: http://code.google.com/p/bwsal/. Anyway there is a native interface that someone created for BWAPI, which I was planning on using in my code, so my plan was to create a native interface for BWSAL, that way I could do all the Jess interaction inside of Java, then call associated methods in C++ via JNI. Does this sound far-fetched? On Thu, Sep 29, 2011 at 5:10 PM, Socrates Frangis soc.fran...@gmail.comwrote: What framework are you using? Curious to see how it is invoking JNI. using this I think I can only interact with Jess in my Java program then pass data from my Java code to C++ -Unless your framework has an API supporting JESS specifically, i doubt that is the case. It should be providing a 'simpler' implementation to access your java classes but that would just eliminate the cryptic path declaration and still give you an interface to what youre playing with. Overall opinion, given the chance that your framework may inhibit full controll of the Rete engine or using JESS (and for the learning experience) i would recommend sticking with your current implementation. Rule engines require precise attention to detail and i wouldn't risk the chance of losing fidelity. On Wed, Sep 28, 2011 at 2:22 PM, Hunter McMillen mcmil...@gmail.comwrote: Sorry to pester you with more questions. The way I am currently doing things in invoking a JVM from C++ to call Java code that calls/interacts with Jess code, but it turns out that someone has actually created a java native interface for the api/framework I am using to make my agent, using this I think I can only interact with Jess in my Java program then pass data from my Java code to C++, I was wondering if you thought this would be a better solution than invoke a JVM from C++ Thanks Hunter On Tue, Sep 27, 2011 at 12:03 PM, Friedman-Hill, Ernest ejfr...@sandia.gov wrote: ** This is all perfectly reasonable so far. When you create the JVM you'll need to tell it where jess.jar is, along with any other jars you use, with the -cp flag or the java.class.path property. Once you have this working, you'll presumably want to connect things a little more tightly. You can use the JNI API to write the equivalent of your three-line main() in C++ pretty easily; you'll want to put together a C++ version executeCommand() that controls the Rete instance, passes a script along, executes it, and gets the Value back, decoding it as needed. -- *From:* owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] *On Behalf Of *Hunter McMillen *Sent:* Monday, September 26, 2011 8:51 PM *To:* jess-users *Subject:* JESS: Call Jess from C++ via JNI Hello everyone, I am working on a project where I am using a C++ framework and API to create a game agent. My agent has to be flexible so it can react to/predict events that occur inside the game environment, Jess has the kind of flexibility that I need for my agent to be good, but I am having trouble connecting to Jess from C++ and that is where I was hoping someone could help me out. *What I am doing right now* I have a C++ program that starts a Java Virtual Machine and searches for a Java class file name TestJNIJessInvoke Inside of TestJNIJessInvoke.java I define a simple function in Jess, and try to call that function then print the result import jess.*; public class TestJNIJessInvoke { public static void main(String[] args) throws JessException { Rete r = new Rete(); r.executeCommand((deffunction square (?n) (return (* ?n ?n; Value v = r.executeCommand((square 3)); System.out.println(v.intValue(r.getGlobalContext())); } } But when I try to compile and link the C++ file with: *cl * * -IC:\Program Files\Java\jdk1.7.0\include * * -IC:\Program Files\Java\jdk1.7.0\include\win32 * * TestJNIJessInvoke.cpp * * -link C:\Program Files\Java\jdk1.7.0\lib\jvm.lib* * * I get a class loader exception: *Exception in thread main java.lang.NoClassDefFoundError: jess/Rete* *at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6)* *Caused by: java.lang.ClassNotFoundException: jess.Rete* *at java.net.URLClassLoader$1.run(URLClassLoader.java:366)* *at java.net.URLClassLoader$1.run(URLClassLoader.java:355)* *at java.security.AccessController.doPrivileged(Native Method)* *at java.net.URLClassLoader.findClass(URLClassLoader.java:354)* *at java.lang.ClassLoader.loadClass(ClassLoader.java:423)* *at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)* *at java.lang.ClassLoader.loadClass(ClassLoader.java:356)* *... 1 more
Re: JESS: Call Jess from C++ via JNI
Thanks a lot! That was exactly what was going wrong. Hunter On Tue, Sep 27, 2011 at 1:31 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: ** The problem is here. The Java classpath doesn't list directories in which jar files can be found, but rather, the jar files themselves. The argument should be, e.g., -Djava.class.path=./jess.jar. * options[0].optionString = (char*)-Djava.class.path=.; //the current directory is where jess.jar is also*
Re: JESS: Call Jess from C++ via JNI
Sorry to pester you with more questions. The way I am currently doing things in invoking a JVM from C++ to call Java code that calls/interacts with Jess code, but it turns out that someone has actually created a java native interface for the api/framework I am using to make my agent, using this I think I can only interact with Jess in my Java program then pass data from my Java code to C++, I was wondering if you thought this would be a better solution than invoke a JVM from C++ Thanks Hunter On Tue, Sep 27, 2011 at 12:03 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: ** This is all perfectly reasonable so far. When you create the JVM you'll need to tell it where jess.jar is, along with any other jars you use, with the -cp flag or the java.class.path property. Once you have this working, you'll presumably want to connect things a little more tightly. You can use the JNI API to write the equivalent of your three-line main() in C++ pretty easily; you'll want to put together a C++ version executeCommand() that controls the Rete instance, passes a script along, executes it, and gets the Value back, decoding it as needed. -- *From:* owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] *On Behalf Of *Hunter McMillen *Sent:* Monday, September 26, 2011 8:51 PM *To:* jess-users *Subject:* JESS: Call Jess from C++ via JNI Hello everyone, I am working on a project where I am using a C++ framework and API to create a game agent. My agent has to be flexible so it can react to/predict events that occur inside the game environment, Jess has the kind of flexibility that I need for my agent to be good, but I am having trouble connecting to Jess from C++ and that is where I was hoping someone could help me out. *What I am doing right now* I have a C++ program that starts a Java Virtual Machine and searches for a Java class file name TestJNIJessInvoke Inside of TestJNIJessInvoke.java I define a simple function in Jess, and try to call that function then print the result import jess.*; public class TestJNIJessInvoke { public static void main(String[] args) throws JessException { Rete r = new Rete(); r.executeCommand((deffunction square (?n) (return (* ?n ?n; Value v = r.executeCommand((square 3)); System.out.println(v.intValue(r.getGlobalContext())); } } But when I try to compile and link the C++ file with: *cl * * -IC:\Program Files\Java\jdk1.7.0\include * * -IC:\Program Files\Java\jdk1.7.0\include\win32 * * TestJNIJessInvoke.cpp * * -link C:\Program Files\Java\jdk1.7.0\lib\jvm.lib* * * I get a class loader exception: *Exception in thread main java.lang.NoClassDefFoundError: jess/Rete* *at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6)* *Caused by: java.lang.ClassNotFoundException: jess.Rete* *at java.net.URLClassLoader$1.run(URLClassLoader.java:366)* *at java.net.URLClassLoader$1.run(URLClassLoader.java:355)* *at java.security.AccessController.doPrivileged(Native Method)* *at java.net.URLClassLoader.findClass(URLClassLoader.java:354)* *at java.lang.ClassLoader.loadClass(ClassLoader.java:423)* *at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)* *at java.lang.ClassLoader.loadClass(ClassLoader.java:356)* *... 1 more* * * Exception in thread main java.lang.NoClassDefFoundError: jess/Rete at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6) Caused by: java.lang.ClassNotFoundException: jess.Rete at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 1 more *Questions* 1) Is there some other directory that I am supposed to be including that has the .class files for Jess? Right now all I am including is jess.jar 2) Is the general design I have a good idea? or is there a better way to facilitate communication between Jess and C++? Thanks, Hunter McMillen
Re: JESS: Call Jess from C++ via JNI
Well the framework and API I am using are very large, so much so that it would be unreasonable to rewrite them in Java. Sorry for the somewhat unspecific question? Really I wanted to know why the class loader couldn't find the jess.Rete class, when I have jess.jar on my classpath, and have it in the directory where the c++ program executes. Here is the c++ code where I create the JVM: *#include jni.h* *#include cstdlib* *using namespace std;* *int main() * *{* * JNIEnv *env;* * JavaVM *jvm;* * jint res;* * jclass cls;* * jmethodID mid;* * jstring jstr;* * jclass stringClass;* * jobjectArray args;* * * * JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */* * JavaVMOption* options = new JavaVMOption[1];* * options[0].optionString = (char*)-Djava.class.path=.; //the current directory is where jess.jar is also* * vm_args.version = JNI_VERSION_1_6;* * vm_args.nOptions = 1;* * vm_args.options = options;* * vm_args.ignoreUnrecognized = false;* * * * /* load and initialize a Java VM, return a JNI interface* * * pointer in env */* * JNI_CreateJavaVM(jvm, (void**)env, vm_args);* * cls = env-FindClass(TestJNIJessInvoke);* * mid= env-GetStaticMethodID(cls, main, ** ([Ljava/lang/String;)V);* * jstr = env-NewStringUTF();* * stringClass = env-FindClass(java/lang/String);* * args = env-NewObjectArray(1, stringClass, jstr);* * * * env-CallStaticVoidMethod(cls, mid, args);* * * * if (env-ExceptionOccurred()) * * {* * env-ExceptionDescribe();* * }* * jvm-DestroyJavaVM();* *}* On Tue, Sep 27, 2011 at 11:58 AM, Dusan Sormaz sor...@ohio.edu wrote: Hunter, This is not Jess specific question. JVM simply can not find Java class to load. Can you show snippet of the C++ code that starts jvm and tries to load TestJNIJessinvoke? As for overall design, is C++ requirement? Can you do it all in Java? Dusan Sormaz On 9/26/2011 8:51 PM, Hunter McMillen wrote: Hello everyone, I am working on a project where I am using a C++ framework and API to create a game agent. My agent has to be flexible so it can react to/predict events that occur inside the game environment, Jess has the kind of flexibility that I need for my agent to be good, but I am having trouble connecting to Jess from C++ and that is where I was hoping someone could help me out. *What I am doing right now* I have a C++ program that starts a Java Virtual Machine and searches for a Java class file name TestJNIJessInvoke Inside of TestJNIJessInvoke.java I define a simple function in Jess, and try to call that function then print the result import jess.*; public class TestJNIJessInvoke { public static void main(String[] args) throws JessException { Rete r = new Rete(); r.executeCommand((deffunction square (?n) (return (* ?n ?n; Value v = r.executeCommand((square 3)); System.out.println(v.intValue(r.getGlobalContext())); } } But when I try to compile and link the C++ file with: *cl * * -IC:\Program Files\Java\jdk1.7.0\include * * -IC:\Program Files\Java\jdk1.7.0\include\win32 * * TestJNIJessInvoke.cpp * * -link C:\Program Files\Java\jdk1.7.0\lib\jvm.lib* * * I get a class loader exception: *Exception in thread main java.lang.NoClassDefFoundError: jess/Rete* *at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6)* *Caused by: java.lang.ClassNotFoundException: jess.Rete* *at java.net.URLClassLoader$1.run(URLClassLoader.java:366)* *at java.net.URLClassLoader$1.run(URLClassLoader.java:355)* *at java.security.AccessController.doPrivileged(Native Method)* *at java.net.URLClassLoader.findClass(URLClassLoader.java:354)* *at java.lang.ClassLoader.loadClass(ClassLoader.java:423)* *at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)* *at java.lang.ClassLoader.loadClass(ClassLoader.java:356)* *... 1 more* * * Exception in thread main java.lang.NoClassDefFoundError: jess/Rete at TestJNIJessInvoke.main(TestJNIJessInvoke.java:6) Caused by: java.lang.ClassNotFoundException: jess.Rete at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 1 more *Questions* 1) Is there some other directory that I am supposed to be including that has the .class files for Jess? Right now all I am including is jess.jar 2) Is the general design I have a good idea? or is there a better way to facilitate