00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "examples/support.hh"
00043 #include "gecode/minimodel.hh"
00044
00045 namespace {
00046
00067
00068
00069 const int k0[] = {
00070
00071 12,10,
00072
00073 2, 0, 5,16, 3, 0, 2, 4, 5, 0, 3, 6, 6, 0, 2, 4,
00074 7, 0, 5,15, 10, 0, 3, 6, 11, 0, 3, 7, 1, 1, 3, 7,
00075 9, 1, 5,16, 4, 2, 2, 5, 8, 2, 2, 3, 3, 3, 5,16,
00076 6, 3, 3, 8, 5, 4, 5,15, 10, 4, 5,15, 4, 5, 2, 3,
00077 8, 5, 2, 4, 11, 5, 3, 7, 1, 6, 3, 6, 2, 6, 3, 7,
00078 7, 6, 3, 7, 6, 7, 2, 3, 9, 7, 2, 4, -1,
00079
00080 1, 1, 2, 7, 4, 1, 3, 9, 9, 1, 2, 4, 0, 2, 3, 7,
00081 4, 2, 3, 7, 8, 2, 3, 6, 0, 3, 2, 3, 3, 3, 2, 4,
00082 6, 3, 5,16, 0, 4, 4,10, 5, 4, 4,10, 1, 5, 2,10,
00083 4, 5, 3, 6, 8, 5, 2, 5, 2, 6, 4,10, 7, 6, 4,12,
00084 0, 7, 5,16, 6, 7, 2, 4, 9, 7, 2, 4, 0, 8, 3, 7,
00085 4, 8, 3, 8, 8, 8, 3, 6, 0, 9, 2, 3, 4, 9, 3, 7,
00086 8, 9, 2, 3, -1
00087 };
00088
00089
00090 const int k1[] = {
00091
00092 12,10,
00093
00094 1, 0, 2, 4, 2, 0, 5,15, 5, 0, 5,18, 6, 0, 2,12,
00095 7, 0, 3, 8, 10, 0, 3,24, 11, 0, 3,23, 3, 1, 2, 7,
00096 9, 1, 3,24, 4, 2, 5,16, 8, 2, 5,35, 1, 3, 2,12,
00097 6, 3, 3,17, 7, 4, 5,34, 10, 4, 5,34, 11, 4, 2,16,
00098 3, 5, 3, 6, 1, 6, 3, 7, 2, 6, 3, 6, 5, 6, 3,23,
00099 9, 6, 2,10, 6, 7, 2,14, 11, 7, 2,10, -1,
00100
00101 0, 1, 2, 3, 4, 1, 3,15, 9, 1, 2,16, 0, 2, 3, 6,
00102 4, 2, 3, 7, 8, 2, 3,24, 1, 3, 4,11, 6, 3, 5,34,
00103 0, 4, 2,14, 3, 4, 3,23, 7, 4, 2,14, 0, 5, 2, 7,
00104 3, 5, 5,15, 9, 5, 2,17, 2, 6, 2, 6, 5, 6, 3,23,
00105 9, 6, 2,13, 0, 7, 5,16, 6, 7, 4,30, 0, 8, 3, 6,
00106 4, 8, 3,23, 8, 8, 3, 7, 0, 9, 2, 4, 4, 9, 3,24,
00107 9, 9, 2,17, -1
00108 };
00109
00110
00111 const int k2[] = {
00112
00113 12,10,
00114
00115 2, 0, 5,15, 3, 0, 2, 3, 7, 0, 3, 7, 8, 0, 4,23,
00116 9, 0, 2,12, 10, 0, 3,20, 11, 0, 3, 9, 4, 1, 3, 7,
00117 5, 1, 4,10, 1, 2, 3, 6, 6, 2, 5,15, 9, 3, 2,16,
00118 3, 4, 2, 3, 7, 4, 4,13, 10, 4, 5,35, 11, 4, 3,23,
00119 4, 5, 4,11, 8, 5, 3,23, 1, 6, 3,23, 2, 6, 3,14,
00120 5, 6, 3,11, 3, 7, 2,13, 9, 7, 2,17, -1,
00121
00122 1, 1, 2, 4, 6, 1, 5,15, 1, 2, 4,11, 6, 2, 5,34,
00123 0, 3, 2, 3, 3, 3, 5,15, 9, 3, 2,10, 0, 4, 2, 4,
00124 3, 4, 3, 6, 7, 4, 2,17, 0, 5, 3, 7, 4, 5, 3, 8,
00125 8, 5, 3,18, 2, 6, 2, 3, 5, 6, 3,11, 9, 6, 2,16,
00126 0, 7, 2,16, 3, 7, 5,16, 9, 7, 2,17, 0, 8, 5,16,
00127 6, 8, 4,30, 0, 9, 5,35, 8, 9, 2,17, -1
00128 };
00129
00130
00131 const int k3[] = {
00132
00133 12,10,
00134
00135 3, 0, 3, 7, 4, 0, 6,21, 7, 0, 4,29, 8, 0, 2,17,
00136 10, 0, 4,29, 11, 0, 3,23, 2, 1, 3, 6, 6, 1, 2,16,
00137 9, 1, 4,14, 1, 2, 2, 4, 5, 2, 2, 3, 8, 3, 6,22,
00138 3, 4, 4,10, 2, 5, 4,11, 5, 5, 4,10, 7, 5, 2,10,
00139 10, 5, 3,24, 11, 5, 2,16, 1, 6, 3, 7, 6, 6, 2, 9,
00140 9, 6, 3,23, 4, 7, 2, 4, -1,
00141
00142 2, 1, 2, 4, 6, 1, 2,17, 9, 1, 2,16, 1, 2, 3, 6,
00143 5, 2, 6,39, 0, 3, 7,28, 8, 3, 3,24, 0, 4, 2, 3,
00144 3, 4, 2, 3, 6, 4, 4,20, 2, 5, 2, 9, 7, 5, 2, 4,
00145 1, 6, 4,10, 6, 6, 2, 3, 9, 6, 2,16, 0, 7, 3, 6,
00146 4, 7, 7,42, 0, 8, 6,21, 7, 8, 3,21, 0, 9, 2, 4,
00147 3, 9, 2, 3, 7, 9, 2,16, -1
00148 };
00149
00150
00151 const int k4[] = {
00152
00153 20,12,
00154
00155 3, 0, 3,21, 4, 0, 2, 4, 5, 0, 4,11, 8, 0, 2, 8,
00156 9, 0, 3, 7, 11, 0, 2, 3, 12, 0, 3, 6, 15, 0, 6,39,
00157 16, 0, 2, 3, 17, 0, 3,23, 2, 1, 5,15, 6, 1, 4,10,
00158 10, 1, 4,11, 14, 1, 4,11, 18, 1, 3, 6, 1, 2, 3,24,
00159 7, 2, 4,14, 13, 2, 2,10, 19, 2, 2,16, 4, 3, 5,18,
00160 8, 3, 4,10, 11, 3, 4,12, 16, 3, 5,33, 3, 4, 3,23,
00161 9, 4, 4,29, 12, 4, 4,30, 17, 4, 3,18, 5, 5, 6,38,
00162 13, 5, 4,29, 18, 5, 5,15, 6, 6, 4,25, 10, 6, 4,12,
00163 14, 6, 4,28, 19, 6, 3,21, 1, 7, 2, 4, 2, 7, 3, 7,
00164 7, 7, 2, 7, 15, 7, 4,11, 3, 8, 3,19, 8, 8, 3,24,
00165 11, 8, 3, 7, 17, 8, 3, 6, 4, 9, 2,16, 9, 9, 2,16,
00166 12, 9, 2,17, 16, 9, 2, 5, -1,
00167
00168 2, 1, 3, 7, 7, 1, 2, 4, 10, 1, 2, 4, 14, 1, 3,19,
00169 1, 2, 5,18, 7, 2, 5,15, 13, 2, 5,16, 0, 3, 3,21,
00170 4, 3, 3, 6, 8, 3, 2, 3, 11, 3, 4,11, 16, 3, 3,20,
00171 0, 4, 2,14, 3, 4, 5,15, 9, 4, 2, 3, 12, 4, 4,29,
00172 17, 4, 2, 8, 0, 5, 4,27, 5, 5, 7,42, 13, 5, 4,12,
00173 1, 6, 4,12, 6, 6, 3, 8, 10, 6, 3,20, 14, 6, 4,29,
00174 2, 7, 4,28, 7, 7, 7,28, 15, 7, 4,28, 0, 8, 2, 3,
00175 3, 8, 4,11, 8, 8, 2,10, 11, 8, 5,35, 17, 8, 2,10,
00176 0, 9, 3, 6, 4, 9, 4,30, 9, 9, 2, 3, 12, 9, 3,19,
00177 16, 9, 3, 7, 1,10, 5,34, 7,10, 5,34, 13,10, 5,17,
00178 2,11, 3,23, 7,11, 2,17, 10,11, 2,10, 14,11, 3, 6,
00179 -1
00180 };
00181
00182
00183 const int k5[] = {
00184
00185 20,12,
00186
00187 1, 0, 2, 3, 2, 0, 5,33, 4, 0, 2, 8, 5, 0, 4,14,
00188 7, 0, 5,15, 8, 0, 3,19, 9, 0, 2,12, 11, 0, 4,11,
00189 12, 0, 2, 4, 13, 0, 5,16, 15, 0, 4,11, 16, 0, 2,17,
00190 18, 0, 5,34, 19, 0, 2,17, 3, 1, 2, 3, 10, 1, 9,45,
00191 17, 1, 2,16, 6, 2, 3,20, 14, 2, 3,12, 1, 3, 2,13,
00192 4, 3, 5,33, 9, 3, 3,20, 16, 3, 5,21, 19, 3, 2, 8,
00193 3, 4, 3,11, 8, 4, 3,11, 12, 4, 3, 7, 17, 4, 3, 8,
00194 11, 5, 3,23, 1, 6, 2,11, 2, 6, 5,15, 6, 6, 3,23,
00195 7, 6, 5,27, 13, 6, 5,30, 14, 6, 3, 7, 18, 6, 5,15,
00196 19, 6, 2, 3, 5, 7, 4,26, 9, 7, 4,27, 15, 7, 4,27,
00197 3, 8, 2, 7, 12, 8, 3,24, 17, 8, 2,17, 1, 9, 2, 5,
00198 4, 9, 2, 9, 8, 9, 2, 3, 11, 9, 2,16, 16, 9, 2,16,
00199 19, 9, 2,10, -1,
00200
00201 0, 1, 2, 4, 3, 1, 2, 7, 6, 1, 3, 7, 10, 1, 3, 7,
00202 14, 1, 2,11, 17, 1, 2,16, 0, 2, 5,16, 6, 2, 7,42,
00203 14, 2, 5,35, 1, 3, 2,10, 4, 3, 4,15, 9, 3, 2, 6,
00204 12, 3, 3, 7, 16, 3, 2,13, 0, 4, 2,17, 3, 4, 4,29,
00205 8, 4, 3,19, 12, 4, 4,11, 17, 4, 2, 9, 0, 5, 4,29,
00206 5, 5, 5,33, 11, 5, 3, 6, 15, 5, 4,29, 2, 6, 2, 4,
00207 7, 6, 5,16, 15, 6, 2, 4, 0, 7, 4,12, 5, 7, 3,10,
00208 9, 7, 5,18, 15, 7, 4,12, 0, 8, 2,13, 3, 8, 4,29,
00209 8, 8, 3,24, 12, 8, 4,23, 17, 8, 2, 5, 1, 9, 2, 6,
00210 4, 9, 3,24, 8, 9, 2, 4, 11, 9, 4,28, 16, 9, 2,11,
00211 0,10, 5,15, 6,10, 7,41, 14,10, 5,34, 0,11, 2, 3,
00212 3,11, 2,17, 6,11, 3,14, 10,11, 3,23, 14,11, 2,11,
00213 17,11, 2, 4, -1
00214 };
00215
00216
00217 const int k6[] = {
00218
00219 20,12,
00220
00221 1, 0, 2, 6, 2, 0, 2,16, 4, 0, 3,10, 5, 0, 2,12,
00222 9, 0, 7,28, 10, 0, 2,12, 11, 0, 3,24, 15, 0, 3,10,
00223 16, 0, 2,17, 17, 0, 6,22, 3, 1, 3,18, 6, 1, 4,10,
00224 8, 1, 2, 8, 12, 1, 2,10, 13, 1, 3,18, 18, 1, 3,12,
00225 7, 2, 4,11, 14, 2, 3, 7, 19, 2, 2, 7, 1, 3, 2, 8,
00226 2, 3, 3, 7, 5, 3, 4,25, 10, 3, 2, 4, 16, 3, 4,15,
00227 4, 4, 4,11, 11, 4, 7,42, 12, 4, 2,17, 15, 4, 4,26,
00228 3, 5, 6,22, 8, 5, 2,16, 13, 5, 4,30, 18, 5, 3,24,
00229 6, 6, 3, 7, 10, 6, 2, 4, 14, 6, 4,29, 19, 6, 2,14,
00230 1, 7, 2,16, 2, 7, 3,11, 7, 7, 3,24, 17, 7, 3,21,
00231 5, 8, 3,23, 8, 8, 2,12, 9, 8, 3,20, 12, 8, 2,17,
00232 16, 8, 3, 6, 4, 9, 2, 9, 10, 9, 2,16, 15, 9, 2, 9,
00233 18, 9, 2, 3, 19, 9, 2,12, -1,
00234
00235 0, 1, 2,10, 3, 1, 2, 5, 8, 1, 3,23, 14, 1, 3,11,
00236 0, 2, 6,38, 7, 2, 6,39, 14, 2, 4,30, 2, 3, 2,10,
00237 5, 3, 4,11, 10, 3, 5,18, 16, 3, 3, 7, 0, 4, 3, 7,
00238 4, 4, 3, 7, 8, 4, 2, 6, 12, 4, 2, 8, 15, 4, 4,11,
00239 0, 5, 2, 8, 3, 5, 4,14, 8, 5, 4,24, 13, 5, 4,10,
00240 1, 6, 4,13, 6, 6, 3,14, 10, 6, 3,19, 14, 6, 4,29,
00241 2, 7, 4,15, 7, 7, 4,14, 12, 7, 4,29, 17, 7, 2,16,
00242 0, 8, 4,29, 5, 8, 2,13, 9, 8, 2, 8, 12, 8, 3,23,
00243 16, 8, 3,22, 0, 9, 3,10, 4, 9, 5,32, 10, 9, 4,29,
00244 15, 9, 2,10, 1,10, 4,14, 6,10, 6,39, 13,10, 6,22,
00245 2,11, 3,21, 8,11, 3,23, 14,11, 2, 6, 17,11, 2,11,
00246 -1
00247 };
00248
00249
00250 const int k7[] = {
00251
00252 22,14,
00253
00254 1, 0, 3,23, 2, 0, 4,29, 3, 0, 2,16, 7, 0, 2, 7,
00255 8, 0, 2,10, 9, 0, 5,30, 13, 0, 7,41, 14, 0, 2,16,
00256 15, 0, 4,29, 17, 0, 2, 3, 18, 0, 6,21, 20, 0, 3, 7,
00257 21, 0, 2, 4, 4, 1, 5,35, 6, 1, 2, 4, 10, 1, 2,17,
00258 12, 1, 3,24, 19, 1, 9,45, 5, 2, 3,23, 11, 2, 9,45,
00259 16, 2, 4,21, 3, 3, 9,45, 7, 3, 5,15, 8, 3, 4,10,
00260 14, 3, 2,10, 17, 3, 2, 3, 6, 4, 2, 4, 10, 4, 4,30,
00261 20, 4, 4,11, 2, 5, 4,13, 12, 5, 4,30, 15, 5, 5,35,
00262 21, 5, 2, 4, 1, 6, 2, 4, 9, 6, 7,41, 14, 6, 4,29,
00263 4, 7, 6,38, 6, 7, 4,11, 16, 7, 2,16, 18, 7, 5,15,
00264 5, 8, 2, 9, 8, 8, 2,17, 13, 8, 5,16, 17, 8, 3, 7,
00265 7, 9, 4,20, 10, 9, 3,23, 20, 9, 4,12, 2,10, 3,23,
00266 12,10, 2, 6, 16,10, 2, 4, 21,10, 3, 9, 1,11, 2,16,
00267 5,11, 2,16, 8,11, 2,16, 14,11, 2, 6, 15,11, 2, 4,
00268 19,11, 2, 4, -1,
00269
00270 0, 1, 3,23, 6, 1, 3, 8, 12, 1, 3,23, 16, 1, 2, 4,
00271 19, 1, 2, 4, 0, 2, 4,30, 5, 2, 5,31, 11, 2, 4,29,
00272 16, 2, 5,15, 0, 3, 2,16, 3, 3, 3,19, 8, 3, 5,32,
00273 14, 3, 2,17, 17, 3, 3, 8, 1, 4, 4,29, 6, 4, 3, 9,
00274 10, 4, 9,45, 2, 5, 9,45, 12, 5, 2,17, 15, 5, 5,16,
00275 1, 6, 3,24, 5, 6, 3, 6, 9, 6, 4,30, 14, 6, 2,16,
00276 17, 6, 4,11, 0, 7, 3, 7, 6, 7, 9,45, 18, 7, 3, 7,
00277 0, 8, 4,11, 5, 8, 2, 4, 8, 8, 4,29, 13, 8, 3,23,
00278 17, 8, 3, 7, 1, 9, 5,16, 7, 9, 2,17, 10, 9, 9,45,
00279 2,10, 9,45, 12,10, 3,23, 16,10, 4,14, 1,11, 3,24,
00280 5,11, 2, 6, 8,11, 5,16, 15,11, 3, 7, 19,11, 2, 8,
00281 0,12, 5,35, 6,12, 4,30, 11,12, 5,15, 17,12, 4,11,
00282 0,13, 2,17, 3,13, 2,16, 6,13, 3,24, 12,13, 3, 6,
00283 18,13, 3, 7, -1
00284 };
00285
00286
00287 const int k8[] = {
00288
00289 22,14,
00290
00291 1, 0, 2, 4, 2, 0, 5,15, 5, 0, 5,16, 6, 0, 2,10,
00292 7, 0, 3,18, 8, 0, 4,29, 10, 0, 5,16, 11, 0, 2, 6,
00293 13, 0, 2, 8, 14, 0, 5,16, 15, 0, 6,38, 18, 0, 5,15,
00294 19, 0, 2, 8, 20, 0, 3, 7, 21, 0, 3, 8, 3, 1, 9,45,
00295 16, 1, 2, 4, 4, 2, 2, 3, 9, 2, 8,39, 17, 2, 2, 3,
00296 1, 3, 2, 5, 6, 3, 6,22, 11, 3, 3,22, 13, 3, 8,38,
00297 19, 3, 9,45, 7, 4, 2, 4, 12, 4, 3,24, 16, 4, 6,38,
00298 20, 4, 3,24, 4, 5, 2,16, 8, 5, 2,14, 17, 5, 2,16,
00299 21, 5, 2,11, 1, 6, 2, 4, 2, 6, 3, 8, 5, 6, 2, 7,
00300 10, 6, 3,18, 14, 6, 2,16, 18, 6, 2,16, 7, 7, 6,22,
00301 11, 7, 3, 7, 15, 7, 2,15, 4, 8, 5,35, 8, 8, 5,34,
00302 12, 8, 5,34, 17, 8, 5,34, 20, 8, 5,34, 21, 8, 2, 3,
00303 5, 9, 2,16, 14, 9, 4,12, 18, 9, 2, 7, 1,10, 3,23,
00304 2,10, 3,21, 6,10, 2, 9, 15,10, 3,20, 3,11, 2,17,
00305 9,11, 2, 4, 11,11, 2, 4, 16,11, 2,10, 21,11, 2,16,
00306 -1,
00307
00308 0, 1, 2, 6, 4, 1, 4,30, 9, 1, 2, 6, 12, 1, 3,10,
00309 17, 1, 4,12, 0, 2, 3, 8, 4, 2, 4,11, 9, 2, 2, 4,
00310 12, 2, 4,20, 17, 2, 4,11, 1, 3, 4,12, 6, 3, 4,28,
00311 13, 3, 5,15, 19, 3, 2, 5, 0, 4, 6,22, 7, 4, 4,28,
00312 12, 4, 3, 8, 16, 4, 3, 6, 0, 5, 3, 7, 4, 5, 3, 7,
00313 8, 5, 8,40, 17, 5, 3,22, 2, 6, 2, 8, 5, 6, 4,12,
00314 10, 6, 3,23, 14, 6, 3,22, 18, 6, 3,22, 0, 7, 6,38,
00315 7, 7, 3,24, 11, 7, 3,23, 15, 7, 6,39, 0, 8, 3, 6,
00316 4, 8, 3, 6, 8, 8, 3, 6, 12, 8, 4,29, 17, 8, 2,14,
00317 1, 9, 3,18, 5, 9, 8,36, 14, 9, 3,22, 18, 9, 3,10,
00318 2,10, 3,22, 6,10, 3,24, 10,10, 4,10, 15,10, 6,21,
00319 0,11, 2,16, 3,11, 5,34, 11,11, 4,29, 16,11, 4,30,
00320 0,12, 4,29, 5,12, 4,12, 10,12, 2,10, 13,12, 4,10,
00321 18,12, 3,23, 0,13, 4,28, 6,13, 3, 7, 10,13, 2,11,
00322 13,13, 4,28, 19,13, 2,13, -1
00323 };
00324
00325
00326 const int k9[] = {
00327
00328 22,14,
00329
00330 1, 0, 4,10, 2, 0, 4,24, 3, 0, 3, 7, 7, 0, 3, 8,
00331 8, 0, 2,17, 9, 0, 3,13, 13, 0, 3,22, 14, 0, 2,12,
00332 15, 0, 3,24, 19, 0, 3,19, 20, 0, 4,28, 21, 0, 4,14,
00333 4, 1, 5,16, 6, 1, 5,17, 10, 1, 5,32, 12, 1, 5,34,
00334 16, 1, 5,35, 18, 1, 5,31, 5, 2, 3, 9, 11, 2, 3, 7,
00335 17, 2, 3, 7, 3, 4, 5,27, 7, 4, 5,16, 9, 4, 5,20,
00336 13, 4, 5,30, 15, 4, 5,30, 19, 4, 5,26, 1, 5, 3,12,
00337 2, 5, 3,20, 8, 5, 3,22, 14, 5, 3, 9, 20, 5, 3,10,
00338 21, 5, 3,20, 4, 7, 5,31, 6, 7, 5,16, 10, 7, 5,17,
00339 12, 7, 5,32, 16, 7, 5,19, 18, 7, 5,34, 5, 8, 3, 8,
00340 11, 8, 3,24, 17, 8, 3,24, 1, 9, 4,10, 2, 9, 4,15,
00341 20, 9, 4,30, 21, 9, 4,12, 3,10, 3,20, 7,10, 3, 6,
00342 9,10, 3, 9, 13,10, 3, 6, 15,10, 3, 7, 19,10, 3,24,
00343 8,11, 2, 8, 14,11, 2, 7, -1,
00344
00345 0, 1, 3, 7, 6, 1, 3,12, 12, 1, 3,23, 18, 1, 3,23,
00346 0, 2, 4,11, 5, 2, 5,19, 11, 2, 5,33, 17, 2, 4,28,
00347 0, 3, 7,28, 8, 3, 5,34, 14, 3, 7,29, 0, 4, 2,12,
00348 3, 4, 3, 7, 9, 4, 3,16, 15, 4, 3,10, 19, 4, 2,10,
00349 2, 5, 5,18, 8, 5, 5,20, 14, 5, 5,29, 0, 6, 4,24,
00350 5, 6, 5,35, 11, 6, 5,23, 17, 6, 4,26, 0, 7, 3,23,
00351 6, 7, 3, 9, 12, 7, 3,10, 18, 7, 3,23, 0, 8, 4,15,
00352 5, 8, 5,19, 11, 8, 5,33, 17, 8, 4,10, 2, 9, 5,19,
00353 8, 9, 5,35, 14, 9, 5,31, 0,10, 2, 4, 3,10, 3,10,
00354 9,10, 3,18, 15,10, 3,24, 19,10, 2,12, 0,11, 7,41,
00355 8,11, 5,23, 14,11, 7,36, 0,12, 4,14, 5,12, 5,17,
00356 11,12, 5,15, 17,12, 4,26, 0,13, 3, 7, 6,13, 3, 7,
00357 12,13, 3, 6, 18,13, 3,23, -1
00358 };
00360
00362 const int* examples[] = {
00363 &k0[0], &k1[0], &k2[0], &k3[0], &k4[0],
00364 &k5[0], &k6[0], &k7[0], &k8[0], &k9[0]
00365 };
00367 const unsigned int n_examples = sizeof(examples)/sizeof(char*);
00368
00369
00373 class DistinctLinear : public Space {
00374 public:
00376 IntVarArray x;
00378 DistinctLinear(int n, int s) : x(this,n,1,9) {
00379 distinct(this, x);
00380 linear(this, x, IRT_EQ, s);
00381 branch(this, x, INT_VAR_NONE, INT_VAL_SPLIT_MIN);
00382 }
00384 DistinctLinear(bool share, DistinctLinear& s) : Space(share,s) {
00385 x.update(this, share, s.x);
00386 }
00388 virtual Space*
00389 copy(bool share) {
00390 return new DistinctLinear(share,*this);
00391 }
00392 };
00399 template <class C> C generate(int n, int c);
00400
00404 template <>
00405 DFA generate<DFA>(int n, int c) {
00406
00407 DistinctLinear* e = new DistinctLinear(n,c);
00408 DFS<DistinctLinear> d(e);
00409 delete e;
00410
00411 DFA::Transition* ts = new DFA::Transition[n];
00412 for (int i=n; i--; )
00413 ts[i].symbol = 0;
00414 ts[0].i_state = 0;
00415
00416 Support::DynamicArray<DFA::Transition> ts_all;
00417 int ts_next = 0;
00418 int n_state = 2;
00419 while (DistinctLinear* s = d.next()) {
00420 int i=0;
00421
00422 for (; ts[i].symbol == s->x[i].val(); i++) {}
00423
00424 int i_state = ts[i].i_state;
00425 for (;i<n;i++) {
00426 ts[i].i_state = i_state;
00427 ts[i].symbol = s->x[i].val();
00428 ts[i].o_state = i_state = n_state++;
00429 ts_all[ts_next++] = ts[i];
00430 }
00431
00432 ts_all[ts_next-1].o_state = 1;
00433 delete s;
00434 }
00435 delete [] ts;
00436 ts_all[ts_next].i_state = -1;
00437 int final[2] = {1,-1};
00438 DFA dfa(0,&ts_all[0],final);
00439 return dfa;
00440 }
00444 template <>
00445 TupleSet generate<TupleSet>(int n, int c) {
00446
00447 DistinctLinear* e = new DistinctLinear(n,c);
00448 DFS<DistinctLinear> d(e);
00449 delete e;
00450 TupleSet ts;
00451 while (DistinctLinear* s = d.next()) {
00452 IntArgs ia(n);
00453 for (int i = n; i--; ) ia[i] = s->x[i].val();
00454 ts.add(ia);
00455 delete s;
00456 }
00457 ts.finalize();
00458 return ts;
00459 }
00460
00464 template <class Data>
00465 class Cache {
00466 private:
00467 class Entry {
00468 public:
00469 int n;
00470 int c;
00471 Data d;
00472 Entry* next;
00473 };
00474 Entry* cache;
00475 public:
00477 Cache(void) : cache(NULL) {}
00479 Data get(int n, int c) {
00480 for (Entry* e = cache; e != NULL; e = e->next)
00481 if ((e->n == n) && (e->c == c))
00482 return e->d;
00483 Entry* e = new Entry;
00484 e->n = n;
00485 e->c = c;
00486 e->d = generate<Data>(n,c);
00487 e->next = cache;
00488 cache = e;
00489 return cache->d;
00490 }
00492 ~Cache(void) {
00493 Entry* e = cache;
00494 while (e != NULL) {
00495 Entry* d = e;
00496 e = e->next;
00497 delete d;
00498 }
00499 }
00500 };
00501
00502 }
00503
00504
00512 class Kakuro : public Example {
00513 protected:
00514 const int w;
00515 const int h;
00516 IntVarArray _b;
00517 public:
00519 enum {
00520 PROP_DFA,
00521 PROP_TUPLE_SET
00522 };
00524 enum {
00525 MODEL_DECOMPOSE,
00526 MODEL_COMBINE,
00527 };
00529 IntVar& b(int x, int y) {
00530 assert((x >= 0) && (x < w) && (y >= 0) && (y < h));
00531 return _b[x+y*w];
00532 }
00534 void init(int x, int y) {
00535 if (b(x,y).min() == 0)
00536 b(x,y).init(this,1,9);
00537 }
00539 template <class Data>
00540 void distinctlinear(Cache<Data>& dc, const IntVarArgs& x, int c,
00541 const SizeOptions& opt) {
00542 if (opt.model() == MODEL_DECOMPOSE) {
00543 distinct(this, x, opt.icl());
00544 linear(this, x, IRT_EQ, c, opt.icl());
00545 } else {
00546 int n=x.size();
00547 switch (n) {
00548 case 0:
00549 return;
00550 case 1:
00551 rel(this, x[0], IRT_EQ, c);
00552 return;
00553 case 8:
00554
00555 rel(this, x, IRT_NQ, 9*(9+1)/2 - c);
00556 break;
00557 case 9:
00558 break;
00559 default:
00560 if (c == n*(n+1)/2) {
00561
00562 rel(this, x, IRT_LQ, n);
00563 } else if (c == n*(n+1)/2 + 1) {
00564
00565 rel(this, x, IRT_LQ, n+1);
00566 rel(this, x, IRT_NQ, n);
00567 } else if (c == 9*(9+1)/2 - (9-n)*(9-n+1)/2) {
00568
00569 rel(this, x, IRT_GQ, 9-n+1);
00570 } else if (c == 9*(9+1)/2 - (9-n)*(9-n+1)/2 + 1) {
00571
00572 rel(this, x, IRT_GQ, 9-n);
00573 rel(this, x, IRT_NQ, 9-n+1);
00574 } else if (n == 2) {
00575
00576 IntArgs e(c);
00577 e[0]=0;
00578 for (int i=1; i<c; i++)
00579 e[i]=(c-i == i) ? 0 : c-i;
00580 element(this, e, x[0], x[1]);
00581 return;
00582 } else {
00583 extensional(this, x, dc.get(n,c), opt.icl(), opt.pk());
00584 return;
00585 }
00586 }
00587 distinct(this, x, opt.icl());
00588 }
00589 }
00591 Kakuro(const SizeOptions& opt)
00592 : w(examples[opt.size()][0]), h(examples[opt.size()][1]),
00593 _b(this,w*h) {
00594 IntVar black(this,0,0);
00595
00596
00597
00598 for (int i=w*h; i--; )
00599 _b[i] = black;
00600 const int* k = &examples[opt.size()][2];
00601
00602 Cache<DFA> dfa_cache;
00603
00604 Cache<TupleSet> ts_cache;
00605
00606 while (*k >= 0) {
00607 int x=*k++; int y=*k++; int n=*k++; int s=*k++;
00608 IntVarArgs col(n);
00609 for (int i=n; i--; ) {
00610 init(x,y+i+1); col[i]=b(x,y+i+1);
00611 }
00612 if (opt.propagation() == PROP_TUPLE_SET)
00613 distinctlinear(ts_cache,col,s,opt);
00614 else
00615 distinctlinear(dfa_cache,col,s,opt);
00616 }
00617 k++;
00618
00619 while (*k >= 0) {
00620 int x=*k++; int y=*k++; int n=*k++; int s=*k++;
00621 IntVarArgs row(n);
00622 for (int i=n; i--; ) {
00623 init(x+i+1,y); row[i]=b(x+i+1,y);
00624 }
00625 if (opt.propagation() == PROP_TUPLE_SET)
00626 distinctlinear(ts_cache,row,s,opt);
00627 else
00628 distinctlinear(dfa_cache,row,s,opt);
00629 }
00630 branch(this, _b, INT_VAR_SIZE_MIN, INT_VAL_SPLIT_MIN);
00631 }
00633 Kakuro(bool share, Kakuro& s) : Example(share,s), w(s.w), h(s.h) {
00634 _b.update(this, share, s._b);
00635 }
00637 virtual Space*
00638 copy(bool share) {
00639 return new Kakuro(share,*this);
00640 }
00642 virtual void
00643 print(std::ostream& os) {
00644 for (int y=0; y<h; y++) {
00645 os << '\t';
00646 for (int x=0; x<w; x++)
00647 if (b(x,y).min() == 0)
00648 os << ". ";
00649 else
00650 os << b(x,y) << ' ';
00651 os << std::endl;
00652 }
00653 }
00654 };
00655
00656
00660 int
00661 main(int argc, char* argv[]) {
00662 SizeOptions opt("Kakuro");
00663 opt.propagation(Kakuro::PROP_TUPLE_SET);
00664 opt.propagation(Kakuro::PROP_DFA,
00665 "dfa","Use DFAs for storing combinations");
00666 opt.propagation(Kakuro::PROP_TUPLE_SET,
00667 "tuple-set","Use tuple sets for storing combinations");
00668
00669 opt.model(Kakuro::MODEL_COMBINE);
00670 opt.model(Kakuro::MODEL_DECOMPOSE,
00671 "decompose","decompose distinct and linear constraints");
00672 opt.model(Kakuro::MODEL_COMBINE,
00673 "combine","combine distinct and linear constraints");
00674
00675 opt.icl(ICL_DOM);
00676 opt.parse(argc,argv);
00677 if (opt.size() >= n_examples) {
00678 std::cerr << "Error: size must be between 0 and "
00679 << n_examples-1 << std::endl;
00680 return 1;
00681 }
00682 Example::run<Kakuro,DFS,SizeOptions>(opt);
00683 return 0;
00684 }
00685
00686