Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SAT4J
sat4j
Commits
875dd60b
Commit
875dd60b
authored
May 24, 2017
by
Lonca Emmanuel
Browse files
Simple AllDifferent constraints take much less memory.
parent
d1a49f59
Pipeline
#167
passed with stage
in 12 minutes and 59 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
org.sat4j.csp/src/main/java/org/sat4j/csp/constraints3/ComparisonCtrBuilder.java
View file @
875dd60b
...
@@ -21,6 +21,7 @@ package org.sat4j.csp.constraints3;
...
@@ -21,6 +21,7 @@ package org.sat4j.csp.constraints3;
import
java.util.SortedSet
;
import
java.util.SortedSet
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
import
org.sat4j.csp.intension.ICspToSatEncoder
;
import
org.sat4j.csp.intension.IIntensionCtrEncoder
;
import
org.sat4j.csp.intension.IIntensionCtrEncoder
;
import
org.sat4j.reader.XMLCSP3Reader
;
import
org.sat4j.reader.XMLCSP3Reader
;
import
org.xcsp.common.Types.TypeOperatorRel
;
import
org.xcsp.common.Types.TypeOperatorRel
;
...
@@ -40,19 +41,20 @@ public class ComparisonCtrBuilder {
...
@@ -40,19 +41,20 @@ public class ComparisonCtrBuilder {
public
ComparisonCtrBuilder
(
IIntensionCtrEncoder
intensionEnc
)
{
public
ComparisonCtrBuilder
(
IIntensionCtrEncoder
intensionEnc
)
{
this
.
intensionCtrEncoder
=
intensionEnc
;
this
.
intensionCtrEncoder
=
intensionEnc
;
}
}
public
boolean
buildCtrAllDifferent
(
XVarInteger
[]
list
)
{
// TODO:
public
boolean
buildCtrAllDifferent
(
XVarInteger
[]
list
)
{
// remove
final
ICspToSatEncoder
solver
=
this
.
intensionCtrEncoder
.
getSolver
();
// dependence
// to
// varmapping
for
(
int
i
=
0
;
i
<
list
.
length
-
1
;
++
i
)
{
for
(
int
i
=
0
;
i
<
list
.
length
-
1
;
++
i
)
{
final
String
norm1
=
CtrBuilderUtils
.
normalizeCspVarName
(
list
[
i
].
id
);
final
int
[]
d1
=
solver
.
getCspVarDomain
(
list
[
i
].
id
);
for
(
int
j
=
i
+
1
;
j
<
list
.
length
;
++
j
)
{
for
(
int
j
=
i
+
1
;
j
<
list
.
length
;
++
j
)
{
final
String
norm2
=
CtrBuilderUtils
.
normalizeCspVarName
(
list
[
j
].
id
);
final
int
[]
d2
=
solver
.
getCspVarDomain
(
list
[
j
].
id
);
final
String
expr
=
"ne("
+
norm1
+
","
+
norm2
+
")"
;
for
(
int
v1
:
d1
)
{
if
(
this
.
intensionCtrEncoder
.
encode
(
expr
))
for
(
int
v2
:
d2
)
{
return
true
;
if
(
v1
==
v2
)
{
solver
.
addClause
(
new
int
[]{-
solver
.
getSolverVar
(
list
[
i
].
id
,
v1
),
-
solver
.
getSolverVar
(
list
[
j
].
id
,
v2
)});
}
}
}
}
}
}
}
return
false
;
return
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment