pythonlogic-programminganswer-set-programmingclingo

How to replace constants terms from python API in clingo / gringo?


Suppose I have a the following file foo.lp:

foo(x).

Now when I run gringo -t -c x=1 foo.lp I obviously get:

foo(1).

Now I want to know how to achieve the same behavior as the -c command line option from the Python API, like when I have:

from clingo.control import Control
ctl = Control()
ctl.load('foo.lp')


#ctl.ground() # What to do here exactly?

So that I can access the ground program / models of the solved program with the constant term replaced.


Solution

  • Turns out it's possible to initialize Control with the command-line parameters, so this does the trick:

    ctl = Control(["-c", "x=1"])