Search code examples
answer-set-programmingclingo

How to use data structures instead of command line arguments with clingo - (ASP)


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


Solution

  • 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