-
Notifications
You must be signed in to change notification settings - Fork 1
/
latinSquare.cpp
68 lines (55 loc) · 1.69 KB
/
latinSquare.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// @Author: Jxtopher
// @Date: 27 Jan 2019
// @Version: 1 beta
// @Purpose: latin square
// @Compilation: g++ main.cpp -lgecodeint -lgecodesearch -lgecodekernel -lgecodesupport -lgecodedriver -lgecodeminimodel -lgecodegist
//
//
#include <iostream>
#include <unistd.h>
// gecode
#include <gecode/minimodel.hh>
#include <gecode/int.hh>
#include <gecode/driver.hh>
using namespace Gecode;
using namespace std;
class LatinSquare : public Script {
public:
LatinSquare(const SizeOptions &opt) : Script(opt),
n(opt.size()),
latinSquare(*this, n * n, 0, n - 1) {
Matrix<IntVarArray> matrix(latinSquare, n, n);
for (unsigned int i = 0 ; i < n ; i++) {
distinct(*this, matrix.col(i));
distinct(*this, matrix.row(i));
}
branch(*this, latinSquare, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
}
LatinSquare(bool share, LatinSquare &s) : Script(share, s), n(s.n) {
latinSquare.update(*this, share, s.latinSquare);
}
virtual Space *copy(bool share) {
return new LatinSquare(share, *this);
}
virtual void print(std::ostream &os) const {
Matrix<IntVarArray> matrix(latinSquare, n, n);
for (int i = 0 ; i < n ; i++) {
os << "\t";
for (int j = 0 ; j < n ; j++) {
os.width(2);
os << matrix(i,j) << " ";
}
os << std::endl;
}
}
private:
const int n;
IntVarArray latinSquare;
};
int main() {
SizeOptions opt("Latin square");
opt.size(3);
Script::run<LatinSquare, DFS, SizeOptions>(opt);
return EXIT_SUCCESS;
}