File: terminate.cpp

package info (click to toggle)
cadical 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,216 kB
  • sloc: cpp: 36,901; ansic: 4,521; sh: 1,770; makefile: 91
file content (47 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "../../src/cadical.hpp"

#ifdef NDEBUG
#undef NDEBUG
#endif

extern "C" {
#include <assert.h>
#include <signal.h>
#include <unistd.h>
}

static int n = 11;

static int ph (int p, int h) {
  assert (0 <= p), assert (p < n + 1);
  assert (0 <= h), assert (h < n);
  return 1 + h * (n + 1) + p;
}

static CaDiCaL::Solver solver;

static void handler (int) { solver.terminate (); }

int main () {

  // Construct a pigeon hole formula for 'n+1' pigeons in 'n' holes.
  //
  for (int h = 0; h < n; h++)
    for (int p1 = 0; p1 < n + 1; p1++)
      for (int p2 = p1 + 1; p2 < n + 1; p2++)
        solver.add (-ph (p1, h)), solver.add (-ph (p2, h)), solver.add (0);

  for (int p = 0; p < n + 1; p++) {
    for (int h = 0; h < n; h++)
      solver.add (ph (p, h));
    solver.add (0);
  }

  (void) signal (SIGALRM, handler);
  ualarm (1e5, 0);
  int res = solver.solve ();
  assert (!res);
  solver.statistics ();

  return 0;
}