Skip to content

Commit

Permalink
fixed a problem with the slice splitting of the waters
Browse files Browse the repository at this point in the history
  • Loading branch information
molok committed May 1, 2018
1 parent 9194f05 commit fe47d46
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>alebolo</groupId>
<artifactId>rabdomante</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
<url>https://github.com/molok/rabdomante/</url>
<build>
<resources>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>alebolo</groupId>
<artifactId>rabdomante</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
<url>https://github.com/molok/rabdomante/</url>

<dependencies>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/alebolo/rabdomante/core/ChocoSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Iterables;
import com.google.common.primitives.Ints;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.util.IntegerSequence;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
Expand Down Expand Up @@ -163,9 +164,11 @@ private IntVar error(IntVar actual, int expected) {
*/
static public int[] range(int max, int perc) {
int step = Math.max(1, (max * perc) / 100);
return Ints.toArray(
IteratorUtils.toList(
new IntegerSequence.Range(0, max, step ).iterator()));
HashSet<Integer> res = new HashSet<>(IteratorUtils.toList(new IntegerSequence.Range(0, max, step).iterator()));
/* I have to include max otherwise in same cases I can't find a solution even
though there is enough water */
res.add(max);
return Ints.toArray(res);
}

private Optional<IntVar> sumSalt(Map<SaltProfile, IntVar> ss, Function<SaltProfile, Integer> f) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/alebolo/rabdomante/core/WaterSolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ public void bruteforce(String desc, Function<IntVar[], AbstractStrategy<IntVar>>
System.out.println(recipe);
}

@Test public void range2() {
System.out.println(Arrays.toString(ChocoSolver.range(31, 10)));
}

@Test public void range3() {
System.out.println(Arrays.toString(ChocoSolver.range(1, 10)));
}

@Test public void range() {
assertThat(ChocoSolver.range(10000, 10)).hasSize(11);
}
Expand Down

0 comments on commit fe47d46

Please sign in to comment.