MCPcopy Create free account
hub / github.com/Gecode/gecode / WordSquare

Method WordSquare

examples/word-square.cpp:72–113  ·  view source on GitHub ↗

Actual model

Source from the content-addressed store, hash-verified

70 };
71 /// Actual model
72 WordSquare(const SizeOptions& opt)
73 : Script(opt), w_l(opt.size()), letters(*this, w_l*w_l) {
74
75 // Initialize letters
76 Matrix<IntVarArray> ml(letters, w_l, w_l);
77 for (int i=0; i<w_l; i++)
78 for (int j=i; j<w_l; j++)
79 ml(i,j) = ml(j,i) = IntVar(*this, 'a','z');
80
81 // Number of words with that length
82 const int n_w = dict.words(w_l);
83
84 // Initialize word array
85 IntVarArgs words(*this, w_l, 0, n_w-1);
86
87 // All words must be different
88 distinct(*this, words);
89
90 // Link words with letters
91 for (int i=0; i<w_l; i++) {
92 // Map each word to i-th letter in that word
93 IntSharedArray w2l(n_w);
94 for (int n=0; n<n_w; n++)
95 w2l[n]=dict.word(w_l,n)[i];
96 for (int j=0; j<w_l; j++)
97 element(*this, w2l, words[j], ml(i,j));
98 }
99
100 // Symmetry breaking: the last word must be later in the wordlist
101 rel(*this, words[0], IRT_LE, words[w_l-1]);
102
103 switch (opt.branching()) {
104 case BRANCH_WORDS:
105 // Branch by assigning words
106 branch(*this, words, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
107 break;
108 case BRANCH_LETTERS:
109 // Branch by assigning letters
110 branch(*this, letters, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
111 break;
112 }
113 }
114 /// Constructor for cloning \a s
115 WordSquare(WordSquare& s)
116 : Script(s), w_l(s.w_l) {

Callers

nothing calls this directly

Calls 15

distinctFunction · 0.85
INT_VAR_SIZE_MINFunction · 0.85
INT_VAL_SPLIT_MINFunction · 0.85
INT_VAR_AFC_SIZE_MAXFunction · 0.85
INT_VAL_MINFunction · 0.85
wordMethod · 0.80
branchingMethod · 0.80
IntVarClass · 0.50
elementFunction · 0.50
relFunction · 0.50
branchFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected