how to show all the maximum result in clingo when using the maximize?

2.8k Views Asked by At

I'm currently writing an asp program. when I comment the line #maximize{S:ce(S)}. within the program, the answer shows as follows

omit the Answer 1 to 6.

Answer: 7
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(ben,english) review(nick,chinese) **ce(4)**

Answer: 8
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,english) review(nick,chinese) **ce(4)**

SATISFIABLE

in which the answer 7 and answer 8 have the same ce value of 4.

when I uncomment the line #maximize{S:ce(S)}. the answer shows as follows

Answer: 1
review(ben,chinese) review(nick,math) ce(2) review(harris,math) review(ben,english) review(nick,english) review(nick,chinese)
Optimization: -2

Answer: 2
review(harris,english) review(ben,math) review(ben,chinese) ce(3) review(harris,math) review(nick,english) review(nick,chinese)
Optimization: -3

Answer: 3
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) **ce(4)** review(nick,english) review(nick,chinese)
Optimization: -4

OPTIMUM FOUND

there is only one result of ce(4), but I'd like to get all the result of the maximum value of ce, what should I do to get the two result with the value ce(4).

1

There are 1 best solutions below

0
On

Maybe you could share your command when executing clingo. I simplified your program as I am not aware of the problem you are encoding.

review(harris,english).
review(ben,math).
review(ben,chinese).
review(nick,math).
review(ben,english) | review(nick, english). % miss one in your problem
review(nick,chinese).
ce(4).
#maximize{S:ce(S)}. 

Basically, the missing condition of your problem is the enumeration of review(ben,english) and review(nick, english).

If executing with command clingo 0 filename.lp the output would generate only one answer set:

Answer: 1
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,chinese) ce(4) review(ben,english)
Optimization: -4
OPTIMUM FOUND

Similar to your attempt, if I comment the last line, two answer sets will be shown:

Answer: 1
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,chinese) ce(4) review(ben,english)
Answer: 2
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,chinese) ce(4) review(nick,english)
SATISFIABLE

But if you uncomment the last line and add --opt-mode=optN after the original command, the output would be:

Answer: 1
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,chinese) ce(4) review(ben,english)
Optimization: -4
Answer: 1
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,chinese) ce(4) review(ben,english)
Optimization: -4
Answer: 2
review(harris,english) review(ben,math) review(ben,chinese) review(nick,math) review(nick,chinese) ce(4) review(nick,english)
Optimization: -4
OPTIMUM FOUND

Not sure if this is what you want. You might as well refer to clingo guide regarding the parameter of --opt-mode:

--opt-mode=mode Configure handling of optimization statements. Available values for mode are:

opt Compute an optimal model (requires --models=0).

enum Enumerate models with costs less than or equal to some fixed bound (cf. --opt-bound).

optN Compute optimum, then enumerate optimal models.

ignore Ignore any optimization statements during computation.