14
14
15
15
import cryptator .gen .member .CryptaMemberLen ;
16
16
import cryptator .gen .member .CryptaMemberPair ;
17
- import cryptator .solver .AdaptiveSolver ;
18
17
import cryptator .specs .ICryptaNode ;
19
18
20
19
class CryptaMemberMult extends CryptaMemberPair {
21
20
22
- private final IntVar sumL ;
23
-
24
- private final IntVar sumR ;
25
-
26
- public CryptaMemberMult (final Model model , final String [] words , final String prefix ) {
27
- super (new CryptaMemberLen (model , words , prefix + "L_" ), new CryptaMemberLen (model , words , prefix + "R_" ));
28
- final int ub = AbstractCryptaGenModel .getSumLength (words );
29
- this .sumL = model .intVar ("L_sumLength" , 0 , ub );
30
- this .sumR = model .intVar ("R_sumLength" , 0 , ub );
31
-
21
+ public CryptaMemberMult (final Model model , final String [] words , final String prefix , final boolean isRightUnique ) {
22
+ super (model , words , prefix , isRightUnique );
32
23
}
33
24
34
25
@ Override
@@ -45,18 +36,18 @@ public ICryptaNode recordCryptarithm() {
45
36
46
37
@ Override
47
38
protected void postSymBreakLengthConstraint () {
48
- getModel ().lexLess (left .getWordVars (), right .getWordVars ()).post ();
49
- }
50
-
51
- public void postMultPrecisionConstraints (final int base ) {
52
- getModel ().sum (left .lengths , "=" , sumL ).post ();
53
- getModel ().sum (((CryptaMemberLen ) right ).lengths , "=" , sumR ).post ();
54
- final int thresh = AdaptiveSolver .computeThreshold (base ) + 1 ;
55
- sumL .le (thresh ).post ();
56
- sumR .le (thresh ).post ();
39
+ if (right instanceof CryptaMemberLen ) {
40
+ getModel ().lexLess (left .getWordVars (), right .getWordVars ()).post ();
41
+ } else {
42
+ left .getMaxLength ().le (right .getMaxLength ()).post ();
43
+ }
57
44
}
58
45
59
46
public void postMultHeavyConstraints (final int base ) {
47
+ final IntVar sumL = getModel ().sum ("L_sumLength" , left .lengths );
48
+ final IntVar sumR = (right instanceof CryptaMemberLen )
49
+ ? getModel ().sum ("R_sumLength" , ((CryptaMemberLen ) right ).lengths )
50
+ : right .getMaxLength ();
60
51
final ArExpression minL = sumL .sub (left .getWordCount ()).add (1 );
61
52
final ArExpression minR = sumR .sub (right .getWordCount ()).add (1 );
62
53
minL .le (sumR ).post ();
@@ -71,9 +62,9 @@ public class CryptaGenMult extends AbstractCryptaListModel {
71
62
72
63
private final CryptaMemberMult multiplication ;
73
64
74
- public CryptaGenMult (final String [] words ) {
65
+ public CryptaGenMult (final String [] words , final boolean isRightUnique ) {
75
66
super (new Model ("Generate-Multiplication" ), words );
76
- multiplication = new CryptaMemberMult (model , words , "" );
67
+ multiplication = new CryptaMemberMult (model , words , "" , isRightUnique );
77
68
}
78
69
79
70
@ Override
@@ -132,13 +123,6 @@ public void postDoublyTrueConstraints(final int lb) {
132
123
sumL .sub (sumR ).abs ().mul (2 ).le (wordCount ).post ();
133
124
}
134
125
135
- @ Override
136
- public void postPrecisionConstraints (final int base ) {
137
- final int thresh = AdaptiveSolver .computeThreshold (base );
138
- getMaxLength ().le (thresh ).post ();
139
- multiplication .postMultPrecisionConstraints (base );
140
- }
141
-
142
126
@ Override
143
127
public final ICryptaNode recordCryptarithm () {
144
128
return multiplication .recordCryptarithm ();
0 commit comments