potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
601 stars 79 forks source link

Calling incmode From Python #374

Closed Genco2 closed 2 years ago

Genco2 commented 2 years ago

Hello Everyone, I am looking for a way to solve a planner example like in the potassco guide (Section 6.3 ([https://github.com/potassco/guide])) using clingo package of Python. Actually, I want to obtain a Python script that takes 2 .lp files in the correct format (world0.lp and blocks.lp in this case) and outputs the possible answers to reach the given goal state. I tried code blocks like ; ` ctl = clingo.Control(arguments=["1", "--warn=none","--single-shot"])

ctl.add("base",[],world)

ctl.add("base2",[],blocks)

ctl.ground([("base", [])])

ctl.ground([("base2", [])])

answers = []

ret = ctl.solve(on_model=lambda m: answers.append(str(m)))

print(answers)

`

However, I can not reach the output of the "clingo world0.lp blocks.lp" command with this block. The answers array I obtained were empty. Thanks. Genco Cosgun

rkaminsk commented 2 years ago

It looks like you are grounding first the encoding and then the instance. The other way round it should work. Usually, we ground both together, though:

ctl.ground([("base", []), ("base2", [])])

I saw that you also wrote to our list. So I am closing this here.