Hi,
Well I assumed you have to have a refence to your agent somehow, and get
your Tiles somehow.
Was just an example, assuming Agent is of class tile.
Correct, an nicer, would be:
when
agent : Agent();
closestTile : Tile (closestDistance : distance) from agent.getTiles();
not Tile(this != closestTile; distance < closestDistance) from
agent.getTiles();
then
.... System.out.println("Closest Tile "+ closestTile);
The idea here to have agent.getTiles() is to have the Tiles already know
their distance to the agent. ;)
having one engine per agent , in separate threads, could allow the gent
to be a global variable, simplifying the design.
I suggest you to work through the DRools doc, especially the part with
the RETE Algorithm,then you will see, that rules are faster the
Java-If-Then, at least for a serious amount of rules. ;)
Good luck,
Darko Ivancan
On 10/12/2007 09:23, velven wrote:
Hi, thanks for replying.
I'll try this implementation of yours, can you clarify
this part of your rule:
> agent : Tile();
> closestTile : Tile( closestDistance: distance) from agent.getTiles();
>
you mean in my Tile class there you should be a method getTiles()? What
should it return?
Sorry, I'm very new to Rule engines.
Actually I'm trying to compare abit on Jess and Drools. Overall my aim is to
identify efficient way/implementation of writing rules and What kinds of
problem is more suitable/faster to be implemented in Rule engines than just
using Java's "if-else". supposed to show some case study.
rules for Case studying now is:
1) Agents go for closest tile/hole within its SenseRange
2) If exists equal closestDistance, then choose the tile that was created
first <randomness here is not allowed, need same event occurance during each
run. Index given during initialisation>
3) If target Tile/hole is taken/carried by other Agent, then look for new
tiles/hole again
4) nothing in range => wander
In my java code, I also have a 2D array/Grid which stores the Tiles and
Agents at their respective location.
so, in java I can start looking for tiles from the Agent's range 1 to the
max Range of Agent using "for-loop"
its the fastest way by far,(given many tiles in enviroment), since the
closest Tile can be found first and search stops even if I have other Tiles
in Range.
Rule Engine can't do this right? The engine tries to match all the Tiles in
the WM which takes time.
I can't make the rule run on incremental range constraint too right?
PLS correct me if I am wrong about this!
Things I have are Lists of Hole, Agents, Tiles in Java and a Grid
enviroment.
current model-> iterates thru Agent list, each Agent executes its action,
then tries to fire any rules possible.
I guess this is a design question, hope its not too out of place. I needed
to know if its the way I wrote my rule that made the engine inefficient, or
this is the kind of problem that Rule engines doesn't perform well on.
Thanks for any feedback!
Darko IVANCAN wrote:
> Hi,
>
> One more thing: You might consider having different engines for
> different agents, and then having the agent as global variable.
>
> Hope this helps,
> Darko Ivancan
>
> On 09/12/2007 18:28, Darko IVANCAN wrote:
>
>> Hi,
>>
>> Let's assume we have
>> class Tile {
>> public int x;
>> public int y;
>> public double distance;
>> }
>> For the simplicity of the reader of drop the getters and setters,
>>
>> Rule "MyRule"
>> agent : Tile();
>> closestTile : Tile( closestDistance: distance) from agent.getTiles();
>> not Tile(this != closest; distance < clostestDistance) from
>> agent.getTiles();
>> ...
>>
>> nasty, but should do the "find closest" job.
>>
>> Weird, this sounds less like a rules tech/usability question to me than
>> rather like a desgin question.
>>
>> If the answers don'T help, maybe you think about telling us the whole
>> problem.
>>
>> hope this helps,
>> Darko Ivancan
>>
>>
>> On 06/12/2007 20:03, velven wrote:
>>
>>
>>> HI, i have a problem
>>> using tileworld model, i'm supposed to write a rule which will cause the
>>> agents to choose the tile in the agent's range which is closest to the
>>> agent.
>>>
>>> so a rough idea is
>>>
>>> when
>>>
>>> agent: Agent(x1:x, y1:y, r:range)
>>>
>>> tile1: Tile(<tile's x to be between (x1+r) and (x1-r)> &&
<tile's y to
>>> be
>>> between (y1+r and y1-r)>)
>>>
>>> tile2: not Tile( < which is closer than the tile1 to agent> )
>>>
>>> desperately need help,
>>> alternatives tried::
>>> i tried to use a query to return a list of tiles which is within the
>>> agent's
>>> range then compared which one is closer and other similar
>>> implementation,
>>> but this too slow for my simulation...
>>>
>>> I need one single good rule or efficient way of implementing the above
>>> rule
>>>
>>>
>>> then i tried to do multiple constraints too, say x (> 30 &&
< 40) is
>>> ok
>>> but
>>> x (>
>>> ($x-$r) && < ($x+$r)) gives errors ,due to extra parenthesis? i
dunno..
>>> any
>>> workarounds?
>>>
>>> Thanks!
>>>
>>>
>>>
>>>
>>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>