Skip to content

Commit a2aed8a

Browse files
committed
additional tweaks
1 parent c161ff1 commit a2aed8a

14 files changed

+156
-20
lines changed

subprojects/Diet/src/main/groovy/DietChocoInt.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//@Grab('org.choco-solver:choco-solver:4.10.5')
16+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1717
import org.chocosolver.solver.Model
1818
import org.chocosolver.solver.variables.IntVar
1919

subprojects/Diet/src/main/groovy/DietChocoReal.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
// need to point to ibex installation
1717
// JAVA_OPTS=-Djava.library.path=/usr/local/lib
18-
//@Grab('org.choco-solver:choco-solver:4.10.5')
18+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1919
import org.chocosolver.solver.Model
2020
import org.chocosolver.solver.variables.RealVar
2121

subprojects/McNuggets/src/main/groovy/Choco.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//@Grab('org.choco-solver:choco-solver:4.10.5')
16+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1717
import org.chocosolver.solver.Model
1818
import org.chocosolver.solver.variables.IntVar
1919

subprojects/Pythagorean/src/main/groovy/Choco.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//@Grab('org.choco-solver:choco-solver:4.10.5')
16+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1717
import org.chocosolver.solver.Model
1818

1919
// find pythagorean-triples for a, b, c <= 30

subprojects/Pythagorean/src/main/notebook/Pythagorean.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
],
2828
"source": [
2929
"%%classpath add mvn\n",
30-
"org.choco-solver choco-solver 4.10.5\n",
30+
"org.choco-solver choco-solver 4.10.9\n",
3131
"tech.tablesaw tablesaw-beakerx 0.38.1"
3232
]
3333
},
@@ -263,7 +263,7 @@
263263
"layout": "IPY_MODEL_a0bde121-ddfa-4c9a-b886-52c0720f4744",
264264
"msg_throttle": 3,
265265
"placeholder": "",
266-
"value": "VectorGraphics2D-0.13.jar, choco-sat-4.10.5.jar, jheaps-0.11.jar, graphics2d-0.27.jar, cpprof-java-1.3.0.jar, commons-logging-1.2.jar, choco-solver-4.10.5.jar, fontbox-2.0.19.jar, trove4j-3.0.3.jar, automaton-1.11-8.jar, xchart-3.6.4.jar, protobuf-java-2.6.1.jar, jgrapht-core-1.4.0.jar, pdfbox-2.0.19.jar, animated-gif-lib-1.4.jar",
266+
"value": "VectorGraphics2D-0.13.jar, choco-sat-4.10.9.jar, jheaps-0.11.jar, graphics2d-0.27.jar, cpprof-java-1.3.0.jar, commons-logging-1.2.jar, choco-solver-4.10.5.jar, fontbox-2.0.19.jar, trove4j-3.0.3.jar, automaton-1.11-8.jar, xchart-3.6.4.jar, protobuf-java-2.6.1.jar, jgrapht-core-1.4.0.jar, pdfbox-2.0.19.jar, animated-gif-lib-1.4.jar",
267267
"visible": true
268268
}
269269
},

subprojects/SendMoreMoney/SendMoreMoney.gradle

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ dependencies {
2626
implementation "org.apache.groovy:groovy:$groovy4Version"
2727
implementation "org.choco-solver:choco-solver:$chocoVersion"
2828
implementation "com.google.ortools:ortools-java:$ortoolsVersion"
29-
implementation "org.jacop:jacop:$jacopVersion"
29+
implementation("org.jacop:jacop:$jacopVersion") {
30+
exclude(group: 'org.slf4j', module :'slf4j-log4j12')
31+
}
32+
implementation('com.javasolver:jsr331-choco:2.2.0') {
33+
exclude(group: 'com.javasolver', module :'jsr331-choco2')
34+
}
35+
runtimeOnly files('lib/choco-solver-2.1.5.jar')
36+
runtimeOnly 'org.slf4j:slf4j-simple:2.0.0'
3037
}
3138

3239
FileUtil.baseNames(sourceSets.main.allSource.files).each { name ->
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import org.chocosolver.solver.Model
17+
import org.chocosolver.solver.variables.IntVar
18+
19+
new Model("ABCD*4=DCBA").with {
20+
def (A, D) = ['A', 'D'].collect { intVar(it, 1, 9) }
21+
def (B, C) = ['B', 'C'].collect { intVar(it, 0, 9) }
22+
def R = (0..2).collect { intVar(0, 9) }
23+
24+
allDifferent(A, B, C, D).post()
25+
R[2].add(A.mul(4)).eq(D).post()
26+
R[1].add(B.mul(4)).eq(C.add(R[2].mul(10))).post()
27+
R[0].add(C.mul(4)).eq(B.add(R[1].mul(10))).post()
28+
D.mul(4).eq(A.add(R[0].mul(10))).post()
29+
solver.findAllSolutions().each {
30+
println "$name: ${pretty(it, [A, B, C, D, ' * 4 = ', D, C, B, A])}\n$it\n"
31+
}
32+
}
33+
34+
new Model("AA+BB+CC=ABC").with {
35+
def (A, B, C) = ['A', 'B', 'C'].collect { intVar(it, 1, 9) }
36+
allDifferent(A, B, C).post()
37+
A.mul(11).add(B.mul(11).add(C.mul(11))).eq(A.mul(100).add(B.mul(10)).add(C)).post()
38+
solver.findAllSolutions().each {
39+
println "$name: ${pretty(it, [A, A, ' + ', B, B, ' + ', C, C, ' = ', A, B, C])}\n$it\n"
40+
}
41+
}
42+
43+
new Model("HALF+HALF=WHOLE").with {
44+
def (H, W) = ['H', 'W'].collect { intVar(it, 1, 9) }
45+
def (A, E, F, L, O) = ['A', 'E', 'F', 'L', 'O'].collect { intVar(it, 0, 9) }
46+
allDifferent(H, W, A, E, F, L, O).post()
47+
IntVar[] ALL = [
48+
H, A, L, F,
49+
W, H, O, L, E]
50+
int[] COEFFS = [
51+
2000, 200, 20, 2,
52+
-10000, -1000, -100, -10, -1]
53+
scalar(ALL, COEFFS, "=", 0).post()
54+
solver.findAllSolutions().each {
55+
println "$name: ${pretty(it, [H, A, L, F, ' + ', H, A, L, F, ' = ', W, H, O, L, E])}\n$it\n"
56+
}
57+
}
58+
59+
new Model("HALF+FIFTH+TENTH+TENTH+TENTH=WHOLE").with {
60+
def (H, F, T, W) = ['H', 'F', 'T', 'W'].collect { intVar(it, 1, 9) }
61+
def (A, L, I, E, N, O) = ['A', 'L', 'I', 'E', 'N', 'O'].collect { intVar(it, 0, 9) }
62+
allDifferent(H, F, T, W, A, L, I, E, N, O).post()
63+
IntVar[] ALL = [
64+
H, A, L, F,
65+
F, I, F, T, H,
66+
T, E, N, T, H,
67+
T, E, N, T, H,
68+
T, E, N, T, H,
69+
W, H, O, L, E]
70+
int[] COEFFS = [
71+
1000, 100, 10, 1,
72+
10000, 1000, 100, 10, 1,
73+
10000, 1000, 100, 10, 1,
74+
10000, 1000, 100, 10, 1,
75+
10000, 1000, 100, 10, 1,
76+
-10000, -1000, -100, -10, -1]
77+
scalar(ALL, COEFFS, "=", 0).post()
78+
solver.findAllSolutions().each {
79+
def parts = [H, A, L, F, '+', F, I, F, T, H, '+', T, E, N, T, H, '+',
80+
T, E, N, T, H, '+', T, E, N, T, H, '=', W, H, O, L, E]
81+
println "$name: ${pretty(it, parts)}\n$it\n"
82+
}
83+
}
84+
85+
// helper method to print solutions
86+
def pretty(model, parts) {
87+
parts.collect { p -> p instanceof IntVar ? model.getIntVal(p) : p }.join()
88+
}

subprojects/SendMoreMoney/src/main/groovy/SendMoreMoneyChoco.groovy

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//@Grab('org.choco-solver:choco-solver:4.10.5')
16+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1717
import org.chocosolver.solver.Model
1818
import org.chocosolver.solver.variables.IntVar
1919
import static java.lang.System.currentTimeMillis
@@ -30,14 +30,15 @@ new Model("SEND+MORE=MONEY").with {
3030
IntVar[] ALL = [
3131
S, E, N, D,
3232
M, O, R, E,
33-
M, O, N, E, Y]
33+
M, O, N, E, Y ]
3434
int[] COEFFS = [
35-
1000, 100, 10, 1,
36-
1000, 100, 10, 1,
37-
-10000, -1000, -100, -10, -1]
35+
1000, 100, 10, 1,
36+
1000, 100, 10, 1,
37+
-10000, -1000, -100, -10, -1 ]
38+
3839
scalar(ALL, COEFFS, "=", 0).post()
3940

4041
def start = currentTimeMillis()
4142
println solver.findSolution()
4243
println "Solved in ${currentTimeMillis() - start} millis"
43-
}
44+
}

subprojects/SendMoreMoney/src/main/groovy/SendMoreMoneyChocoCarry.groovy

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//@Grab('org.choco-solver:choco-solver:4.10.5')
16+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1717
import org.chocosolver.solver.Model
18-
import org.chocosolver.solver.variables.IntVar
1918
import static java.lang.System.currentTimeMillis
2019

2120
new Model("SEND+MORE=MONEY").with {
2221
def (S, M) = ['S', 'M'].collect { intVar(it, 1, 9) }
2322
def (E, N, D, O, R, Y) = ['E', 'N', 'D', 'O', 'R', 'Y'].collect { intVar(it, 0, 9) }
24-
def C = new IntVar[4]
25-
for (n in 0..<C.size()) { C[n] = intVar(0, 1) }
23+
def C = (0..3).collect{ intVar("C$it", 0, 9) }
2624

2725
allDifferent(S, E, N, D, M, O, R, Y).post()
2826
C[3] .eq(M).post()

subprojects/SendMoreMoney/src/main/groovy/SendMoreMoneyChocoCarryDSL.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
//@Grab('org.choco-solver:choco-solver:4.10.5')
16+
//@Grab('org.choco-solver:choco-solver:4.10.9')
1717
import groovy.transform.CompileStatic
1818
import groovy.transform.Immutable
1919
import org.chocosolver.solver.Model
@@ -28,7 +28,7 @@ model("SEND+MORE=MONEY") {
2828
def (E, N, D, O, R, Y) = ['E', 'N', 'D', 'O', 'R', 'Y'].collect { intVar(it, 0..9) }
2929
def C = intVarArray(4, 0..1)
3030

31-
[allDifferent(S, E, N, D, M, O, R, Y), // C3 C2 C1 C0
31+
[allDifferent(S, E, N, D, M, O, R, Y), // C3 C2 C1 C0
3232
C[3] .eq(M), // S E N D
3333
(C[2] + S + M).eq(O + C[3] * 10), // M O R E
3434
(C[1] + E + O).eq(N + C[2] * 10), // -------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import javax.constraints.*
18+
19+
ProblemFactory.newProblem('SEND+MORE=MONEY').with {
20+
def (S, M) = ['S', 'M'].collect { variable(it, 1, 9) }
21+
def (E, N, D, O, R, Y) = ['E', 'N', 'D', 'O', 'R', 'Y'].collect { variable(it, 0, 9) }
22+
23+
postAllDifferent(S, E, N, D, M, O, R, Y)
24+
25+
Var[] ALL = [
26+
S, E, N, D,
27+
M, O, R, E,
28+
M, O, N, E, Y]
29+
int[] COEFFS = [
30+
1000, 100, 10, 1,
31+
1000, 100, 10, 1,
32+
-10000, -1000, -100, -10, -1]
33+
34+
post(COEFFS, ALL, '=', 0)
35+
36+
def solver = getSolver()
37+
def solution = solver.findSolution()
38+
println solution ?: 'No solution'
39+
solver.logStats()
40+
}

subprojects/SendMoreMoney/src/main/groovy/SendMoreMoneyPermutations.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
def digits = 0..9
17+
long start = System.currentTimeMillis()
1718
for (p in digits.permutations()) {
1819
if (p[-1] < p[-2]) continue
1920
def (s, e, n, d, m, o, r, y) = p
@@ -26,3 +27,4 @@ for (p in digits.permutations()) {
2627
println "m = $m, o = $o, r = $r, y = $y"
2728
}
2829
}
30+
println System.currentTimeMillis() - start

subprojects/SendMoreMoney/src/main/notebook/SendMoreMoney.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
"source": [
253253
"%%groovy\n",
254254
"\n",
255-
"@Grab('org.choco-solver:choco-solver:4.10.2')\n",
255+
"@Grab('org.choco-solver:choco-solver:4.10.9')\n",
256256
"import org.chocosolver.solver.Model\n",
257257
"import org.chocosolver.solver.variables.IntVar\n",
258258
"\n",

0 commit comments

Comments
 (0)