I assume things are slow because you are initializing Jess with the same
rules in each method call; and only one thread is touching an instance of
Jess at a time. I play the following game to allow multiple (Java) threads
to touch a single Jess instance simultaneously.
Add a slot member to the fact template:
(slot uidKey)
In the Java before building facts:
int uidKey = new UID().hashCode();
Then (in Java) build each fact adding the uidKey to the uidKey slot in each
fact.
Then (from Java) store a HashSet into Jess as follows:
"(store UIDKey" + uidKey + " (new java.util.HashSet))"
Then - assert the facts into Jess
Then - (run)
Each rule is something like the following.
Each fired rule builds up the Set/List.
(defrule whatever
(whatever
(uidKey ?uidKey)
...
=>
(bind ?list (fetch (str-cat UIDKey ?uidKey)))
(call ?list add "whatever"))
[Luckily - Jess allows "-" in global names (since UID().hashCode() may
return a negative number)]
Then, after running, gather up the Set/List (in Java):
// Fetch the Set
Set whatever = (Set) ((Value) engine.fetch("UIDKey" +
uidKey)).externalAddressValue(context);
This strategy allows me to send down facts from multiple (Java) threads
without reinitializing rules each time (and also to "process" groups of
facts as a single logical entity.)
- keith
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Rowan Constable
Sent: Wednesday, March 30, 2005 8:34 AM
To: [email protected]
Subject: JESS: Using Store-Fetch to transfer values between Jess Java
Hi,
I'm trying to finish off an expert system for selecting engineering
materials. I
have an object which is passed a vector of materials and the expert system
returns their suitability using store-fetch. The rete object (materials
decider) is used in a method called getAcceptibility which batches the rules
located in rules.clp everytime the method is called. This approach works
fine
but it is REALLY slow.
Is there anyway of speeding this up? I tried batching the rules in the
constructor of the class and it is dramatically faster but store-fetch
doesn't
work properly then. This results in every material given the same
suitability
(20%). I tried to remedy this by clearing the storage of rule engine using
clearStorage but this throws up a null-pointer exception.
Is there anything else I can try?
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------