首页 > 解决方案 > 如何在 cligo / gringo 中替换 python API 中的常量术语?

问题描述

假设我有以下文件foo.lp

foo(x).

现在,当我跑步时,gringo -t -c x=1 foo.lp我显然得到:

foo(1).

现在我想知道如何实现与-cPython API 中的命令行选项相同的行为,例如:

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


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

这样我就可以访问替换了常数项的已解决程序的基本程序/模型。

标签: pythonlogic-programminganswer-set-programmingclingo

解决方案


事实证明可以Control使用命令行参数进行初始化,所以这可以解决问题:

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

推荐阅读