Hi Cle,

> Nice idea! Now I reformulated my Pilog rules for usage with database
> like this:
> 
>    (be graph:walk (@Begin @Way)
>      (@E db 'id '+DB:Edge (-> @Begin))
>      (@To get (-> @E) 'tgt)
>      (graph:walk @To (@Begin) @Way)
>    )
> 
>    (be graph:walk (@Node @Way @Way))
> 
>    (be graph:walk (@FromNode @AuxWay @Way)
>      (@Edges collect 'src '+DB:Edge (-> @FromNode))
>      (lst @Edge @Edges)
>      (@Id get (-> @Edge) 'id)
>      (@ToNode get (-> @Edge) 'tgt)
>      (graph:walk @ToNode (@Id . @AuxWay) @Way)
>    )

Hehe, nice. Our mails crossed-over, without paying attention to a point
or signal ;-) The solutions look pretty similar. As you see, the
explicit 'get' can be substituted by a more concise 'val' predicate.

I also notice that the '@From' in my walk/2 is not used and thus
unnecessary. So I would propose (especially if you use a numeric 'id'):

   (be walk (@Begin @Way)
      (db id +Test @Begin @Obj)
      (val @To @Obj tgt)
      (walk @To (@Begin) @Way) )

   (be walk (@Node @Way @Way))

   (be walk (@FromNode @AuxWay @Way)
      (db src +Test @FromNode @Obj)
      (val @Edge @Obj id)
      (val @ToNode @Obj tgt)
      (walk @ToNode (@Edge . @AuxWay) @Way) )


> This is an excerp from my actual code. You will find, that I use a
> <module>: prefix in my clauses to modularize the Pilog clauses and
> facts. A slight misuse I know, as those prefix should be used for
> function in shared libraries ... :-}

I would not worry about that. It is just the other way round: If the
interpreter finds an _undefined_function_ with a colon in the name, then
it searches for a library. This doesn't inhibit us, though, to define
such functions ourselves. And here we are not dealing with functions
anyway.


> With those changes the traversion becomes a bit faster; it needed 87
> seconds for 1000 pathes, where Pilog facts would take 3 seconds ;-)

This large difference is rather strange. I would expect _some_ slowdown,
as the DB involves I/O operations while Pilog only runs in memory, but
not so much.

The question is what happens if you have millions of edges. Then the
linear lookup in Pilog versus the index accesses in the DB might show
effect.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to