[rules-users] How to write a rule which only fires for a closest value?

Darko IVANCAN ivancan at gmx.de
Sun Dec 9 07:58:00 EST 2007


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!
>
>
>   



More information about the rules-users mailing list