-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagicSequence.cpp
65 lines (51 loc) · 1.32 KB
/
magicSequence.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
//
// @Author: Jxtopher
// @Date: 27 Jan 2019
// @Version: 1 beta
// @Purpose: http://www.csplib.org/Problems/prob019/
// @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 MagicSequence : public Script {
public:
MagicSequence(const SizeOptions &opt) :
Script(opt),
n(opt.size()),
sequence(*this, n, 0, n - 1) {
IntRelType s(IRT_EQ);
for (unsigned int i = 0; i < n; i++) {
count(*this, sequence, i, s, sequence[i]);
}
rel(*this, sum(sequence) == n);
branch(*this, sequence, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
}
MagicSequence(bool share, MagicSequence &s) : Script(share, s), n(s.n) {
sequence.update(*this, share, s.sequence);
}
virtual Space *copy(bool share) {
return new MagicSequence(share, *this);
}
virtual void print(std::ostream &os) const {
for (unsigned int i = 0; i < n; i++) {
os << sequence[i];
os.width(2);
}
}
private:
const int n;
IntVarArray sequence;
};
int main() {
SizeOptions opt("Magic Sequence");
opt.size(10);
Script::run<MagicSequence, DFS, SizeOptions>(opt);
return EXIT_SUCCESS;
}