Skip to content

Commit

Permalink
⬆️ Corrections ACE 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
romainwallon committed Dec 21, 2024
1 parent 3a56346 commit 6710e83
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
Binary file modified lib/ace-2.4.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static fr.univartois.cril.juniverse.csp.intension.UniverseIntensionConstraintFactory.neq;
import static fr.univartois.cril.juniverse.csp.intension.UniverseIntensionConstraintFactory.unary;
import static fr.univartois.cril.juniverse.csp.intension.UniverseIntensionConstraintFactory.variable;
import static org.xcsp.common.Types.TypeFramework.values;
import static utility.Kit.control;

import java.io.File;
Expand All @@ -45,6 +46,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.IntStream;

import org.xcsp.common.Condition;
import org.xcsp.common.Condition.ConditionIntset;
Expand Down Expand Up @@ -1366,26 +1368,29 @@ public void addSupport(String arg0, List<BigInteger> arg1)
var t = new int[arg1.size()];
toTuples(arg1, t);

getHead().xcsp3.addConstraintsToAdd(p -> p.extension((Variable) toVar(arg0), t, true));
getHead().xcsp3.addConstraintsToAdd(p -> {
var y = (Variable) toVar(arg0);
var tuple = IntStream.of(t).filter(v -> y.dom.containsValue(v)).toArray();
p.extension(y, tuple, true);
});
}

@Override
public void addSupport(List<String> arg0, List<List<BigInteger>> arg1)
throws UniverseContradictionException {
int[][] t;
boolean starred;
if (arg1 == previousList) {
t = previousArray;
starred = previousStarred;
} else {
t = new int[arg1.size()][arg1.get(0).size()];
starred = toTuples(arg1, t);
previousList = arg1;
previousArray = t;
previousStarred = starred;
}

getHead().xcsp3.addConstraintsToAdd(p -> p.extension(toVarArray(arg0), t, true, starred));
t = new int[arg1.size()][arg1.get(0).size()];
starred = toTuples(arg1, t);
previousList = arg1;
previousArray = t;
previousStarred = starred;
getHead().xcsp3.addConstraintsToAdd(p -> {
var array = toVarArray(arg0);
Variable[] scp = Stream.of(array).map(x -> (Variable) x).toArray(Variable[]::new);
var tuple = Stream.of(t).filter(x -> Variable.isValidTuple(scp, x, false)).toArray(int[][]::new);
p.extension(array, tuple, true, starred);
});

}

Expand All @@ -1395,7 +1400,12 @@ public void addConflicts(String arg0, List<BigInteger> arg1)
var t = new int[arg1.size()];
toTuples(arg1, t);

getHead().xcsp3.addConstraintsToAdd(p -> p.extension((Variable) toVar(arg0), t, false));

getHead().xcsp3.addConstraintsToAdd(p -> {
var y = (Variable) toVar(arg0);
var tuple = IntStream.of(t).filter(v -> y.dom.containsValue(v)).toArray();
p.extension(y, tuple, false);
});

}

Expand All @@ -1404,17 +1414,17 @@ public void addConflicts(List<String> arg0, List<List<BigInteger>> arg1)
throws UniverseContradictionException {
int[][] t;
boolean starred;
if (arg1 == previousList) {
t = previousArray;
starred = previousStarred;
} else {
t = new int[arg1.size()][arg1.get(0).size()];
starred = toTuples(arg1, t);
previousList = arg1;
previousArray = t;
previousStarred = starred;
}
getHead().xcsp3.addConstraintsToAdd(p -> p.extension(toVarArray(arg0), t, false, starred));
t = new int[arg1.size()][arg1.get(0).size()];
starred = toTuples(arg1, t);
previousList = arg1;
previousArray = t;
previousStarred = starred;
getHead().xcsp3.addConstraintsToAdd(p -> {
var array = toVarArray(arg0);
Variable[] scp = Stream.of(array).map(x -> (Variable) x).toArray(Variable[]::new);
var tuple = Stream.of(t).filter(x -> Variable.isValidTuple(scp, x, false)).toArray(int[][]::new);
p.extension(array, tuple, false, starred);
});

}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/univartois/cril/aceurancetourix/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public static void main(String[] args) {
solver.loadInstance(args[0]);
//solver.setBounds(BigInteger.valueOf(74), BigInteger.valueOf(862));
System.out.println(solver.solve());
solver.reset();
solver.setUpperBound(BigInteger.valueOf(148));
System.out.println(solver.solve());
//solver.reset();
//solver.setUpperBound(BigInteger.valueOf(148));
//System.out.println(solver.solve());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.IntStream;

import static org.xcsp.common.Types.TypeFlag.UNCLEAN_TUPLES;
import org.xcsp.common.Condition;
import org.xcsp.common.Condition.ConditionIntset;
import org.xcsp.common.Condition.ConditionIntvl;
Expand Down Expand Up @@ -70,6 +72,7 @@
import fr.univartois.cril.juniverse.csp.operator.UniverseOperator;
import fr.univartois.cril.juniverse.csp.operator.UniverseRelationalOperator;
import fr.univartois.cril.juniverse.csp.operator.UniverseSetBelongingOperator;
import variables.Variable;

/**
* The XCSPXCallback is an implementation of {@link XCallbacks2} that hides all
Expand Down Expand Up @@ -1076,7 +1079,6 @@ public void buildCtrExactly(String id, XVarInteger[] list, int value, XVarIntege
@Override
public void buildCtrExtension(String id, XVarInteger x, int[] values, boolean positive,
Set<TypeFlag> flags) {

if (positive) {
listener.addSupport(x.id(), toBigInteger(values));
} else {
Expand Down

0 comments on commit 6710e83

Please sign in to comment.