Clingo: Intersecting All Possible Optimal Solutions (ASP)

475 Views Asked by At

I want to find atoms, within a pre-defined set of atoms, that are in all possible optimal solutions of an ASP problem.

I'll explain what i want to do. I have an optimization problem where multiple optimal answer sets can exist. An answer set consists of atoms that characterizes a solution, for example node(0), edge(1,2) , as well as some that are not relevant, like color(0).

I want to compute all optimal answer sets, only show atoms of the type node() and edge(), then find the specific relevant atoms (like node(0) and edge(1,0)) that exist in all optimal answer sets.

I know i can limit the output of certain atoms with the #show directive. I can also add the flags --opt-mode=optN to compute all optimal answer and limit the output to only those with --quiet=1. As per guide, using --enum-mode cautious computes the intersection of all answer sets.

An example:

If i have two optimal answer sets:

Answer set 1: node(1) node(0) edge(1,0) edge(0,1) color(1)

Answer set 2: node(1) node(0) edge(1,0) color(0)

I want to the result node(1) node(0) edge(1,0)

  1. I can run clingo with --opt-mode=optN --quiet=1 then manually search for all node() or edge() atoms that all answer sets have in common.

  2. I can add #show node/1 #show edge/2 to my encoding then run clingo with --opt-mode=optN --quiet=1 --enum-mode cautious.

Are all those two options logically equivalent?

Is there a more efficient way of achieving what i want?

I'm unsure about the interplay between the #show directive and the --opt-mode, --quiet and --enum-mode flags. I have a problem where answer sets can be very large, so i would prefer using option 2 since it would use the least disk space.

Thank you in advance.

1

There are 1 best solutions below

0
On

You are definitely on the right track. I'm unsure about the combination of options though, especially --quiet as it only prevents showing the non-optimal models, but they will still be counted as models for the --enum-mode=cautious thingy.

You should simply use the clingo python API to achieve your goal. First, compute one optimal solution. Then you do have the bound that you can give as an additional argument to the opt-mode and your approach should work.

https://potassco.org/clingo/python-api/current/clingo/