Skip to content

Commit

Permalink
Fix a minor bug which involved creating a redundant linear program wh…
Browse files Browse the repository at this point in the history
…en a branch was completed. This could also lead to nasty errors, because the matrix was reduced to a zero-width one.
  • Loading branch information
rayferric committed Dec 16, 2020
1 parent 57447fa commit ccefb88
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,37 @@ private Spliterator<Vector> split() {
// The basis is a square:
int size = basis.getWidth();

// We have reached the end of this branch:
if(depth == size)
return Arrays.spliterator(new Vector[] { vertex });

Vector gradient = basis.getRow(depth);

BigInteger min = program.minimize(gradient).dot(gradient).ceil().getNumerator();
BigInteger max = program.maximize(gradient).dot(gradient).floor().getNumerator();
Fraction min = program.minimize(gradient).dot(gradient).ceil();
Fraction max = program.maximize(gradient).dot(gradient).floor();

Queue<TreeNode> children = new LinkedList<>();
int width = max.sub(min).getNumerator().intValue() + 1;

for(BigInteger i = min; i.compareTo(max) <= 0; i = i.add(BigInteger.ONE)) {
Fraction value = new Fraction(i);
if(depth + 1 == size) {
// We have reached the end of this branch and found {width} solutions.

LinearProgram newProgram = program.withEquality(gradient, value);
Vector newVertex = vertex.add(Vector.basis(size, depth, value));
Vector[] solutions = new Vector[width];

children.add(new TreeNode(depth + 1, basis, newProgram, newVertex));
}
for(int i = 0; i < width; i++) {
Fraction value = min.add(new Fraction(i));
solutions[i] = vertex.add(Vector.basis(size, depth, value));
}

return Arrays.spliterator(solutions);
} else {
Queue<TreeNode> children = new LinkedList<>();

for(int i = 0; i < width; i++) {
Fraction value = min.add(new Fraction(i));

return new TreeSpliterator(children);
LinearProgram newProgram = program.withEquality(gradient, value);
Vector newVertex = vertex.add(Vector.basis(size, depth, value));

children.add(new TreeNode(depth + 1, basis, newProgram, newVertex));
}

return new TreeSpliterator(children);
}
}
}

0 comments on commit ccefb88

Please sign in to comment.