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 48 49 | /* Steiner triplets (using sets) in Comet. This Comet model was created by Hakan Kjellerstrand (hakank@gmail.com) Also, see my Comet page: http://www.hakank.org/comet */ // Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/ import cotfd; int t0 = System.getCPUTime(); Solver<CP> cp(); int n = 9; int nb = n *(n-1) / 6; cout << "nb: " << nb << endl; int c = 3; // cardinality var <CP>{ set { int }} steiner[1..nb](cp, 1..n, c); Integer num_solutions(0); exploreall <cp>{ forall (i in 1..nb, j in 1..nb : i < j) { cp.post(atmostIntersection(steiner[i], steiner[j], 1)); } } using { // label(cp); forall (i in 1..nb) label(steiner[i]); cout << steiner << endl; num_solutions := num_solutions + 1; } cout << "\nnum_solutions: " << num_solutions << endl; int t1 = System.getCPUTime(); cout << "time: " << (t1-t0) << endl; cout << "#choices = " << cp.getNChoice() << endl; cout << "#fail = " << cp.getNFail() << endl; cout << "#propag = " << cp.getNPropag() << endl; |