3

I am starting off with logical programming, and I am working on a simple program to find shortest paths between nodes. The only tutorial I could really understand dealt with command arguments.

Is there a way I can replace Args in my program for a hardcoded structure like a list or something? Is that possible with asp?

import com.sap.cxlabs.bewater.logic.asp._
val shortestPath = SModels(Args( %here is where I'd like to use a data structure.
 p.path(X, Y, W) :-(p.start(X), p.edge(X, Y, W)),
 p.path(X, Z, A + B) :- (p.path(X, Y, A), p.edge(Y, Z, B)),
 p.shortest(W) :- (p.end(Y), p.path(X, Y, W), not p.path(X, Y, Z), W < Z),
))
shortestPath.deduct(facts)

edit Args is start-nodes, end-nodes, edges

1 Answers1

0

I checked the guide and the examples and found only examples where actually you need to call clingo from the command line, although you can use python code inside the program in #script tags. For example this one: https://github.com/potassco/clingo/blob/master/examples/clingo/addclause/addclause-py.lp

However, I routinely use clingo only as a python library and you can find some example code here: https://github.com/peschue/ai4eu-sudoku/blob/master/aspsolver/server.py

peschü
  • 1,299
  • 12
  • 21
  • 1
    That's actually brilliant. Just use python code if you can't get past an lp problem. I didn't even know python worked inside clingo. Thank you. – linda baldwell Mar 22 '21 at 23:45
  • 1
    It is tempting to use too much python inside clingo. To create efficient solutions, one needs to find a good balance. – peschü Mar 24 '21 at 08:09