0

In the code below

% Facts
a.

% Rules
-a :- a, not not p.

Adding the fact p. to the above would cause it to be UNSAT. Is there a way in clingo to add a rule to show this? Something like

q :- Assuming p causes UNSAT.

Solutions like adding the rule

{p; q} = 1.

Wouldn't work. It would give q. in the answer set if p. causes UNSAT, as I'd want. But, it would give p. and q. as answer sets when p. doesn't cause UNSAT. In the case of p. not causing UNSAT I wouldn't want q. in the answer set.

I'd like to be able to check whether certain facts causes a certain complex condition to not hold. For example, suppose one part of a problem requires you to check that a graph does NOT contain a Hamiltonian cycle. A program that finds Hamiltonian cycles would return UNSAT if the graph satisfies the condition, but I wouldn't want the program to end, since there would be other calculations to do.

abyyskit
  • 3
  • 3

1 Answers1

0

You can probably treat it as an optimisation problem. So something that would normally be a constraint is turned into a special predicate which you then seek to minimise. Basically you have something of the form:

 err(err1) :- some-bad-condition.
 err(err2) :- some-other-bad-condition.

 #minimize{ 1,XXX: err(XXX) }.

Here the XXX is a unique identifier for each error condition. The optimisation statement finds a model that minimises the number of errs.

The only caveat is that this increases the complexity of the problem; you're now solving an optimisation problem instead of a decision problem. It is a useful trick when debugging asp programs, but for large/difficult problems it may be too slow.

daveraja
  • 839
  • 6
  • 9
  • This does solve the example I gave, but I'd appreciate a clarification on how this would apply to the Hamiltonian cycle example in my last paragraph. From what I understand, using your method I'd have the line `err(err1) :- cycle_exists.`, but defining `cycle_exists` is equivalent to the question I asked, namely checking if a block of code (in this case a block of code which finds a Hamiltonian cycle) is satisfiable. – abyyskit Sep 02 '21 at 08:19
  • Can you provide a more concrete example of the overall problem you are trying to model? Maybe you can break your program into separate programs and check their satisfiability individually? SAT/UNSAT applies to the program as a whole, so within a program you should be thinking about properties (or facts) as holding and not holding. So for the Hamiltonian cycle, instead of having a constraint that makes the program unsatisfiable if there is no cycle, you encode that if there is a cycle then these extra properties must also hold and if there is no cycle then these other properties must hold. – daveraja Sep 02 '21 at 23:05
  • The following question is an example of what I want to solve. _Given a graph G. Find the minimum number of edges you need to remove from G so that it no longer contains a Hamiltonian cycle._ – abyyskit Sep 04 '21 at 12:16
  • I think you have to look into disjunctive logic programs. It might be a NP^2 hard problem. There is way to model such things but I'm not competent enough to explain it. – Max Ostrowski Sep 05 '21 at 16:48