python - 如何在 cligo / gringo 中替换 python API 中的常量术语?
问题描述
假设我有以下文件foo.lp
:
foo(x).
现在,当我跑步时,gringo -t -c x=1 foo.lp
我显然得到:
foo(1).
现在我想知道如何实现与-c
Python API 中的命令行选项相同的行为,例如:
from clingo.control import Control
ctl = Control()
ctl.load('foo.lp')
#ctl.ground() # What to do here exactly?
这样我就可以访问替换了常数项的已解决程序的基本程序/模型。
解决方案
事实证明可以Control
使用命令行参数进行初始化,所以这可以解决问题:
ctl = Control(["-c", "x=1"])
推荐阅读
- postgresql - 如何使用左连接 PSQL 获取电池的最后添加记录
- python - Python Twitch API 属性错误问题
- python - 使用自定义损失函数时出现 TensorFlow 错误
- ios - PFUser.become 返回无效的会话令牌
- php - laravel 新项目命令使用 php@7.3 代替 php@7.4
- jquery - 在媒体屏幕上显示 Jquery Slick 选项
- python - 按数字切片 Python 列表
- python-3.x - Python根据值的右子字符串从Dataframe中删除行
- python - 从 Selenium WebElement 中提取文本
- winapi - D3D11如何将纹理中alpha值为0的像素渲染为透明?