-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I am trying to use Zelen for part 2 of Advent of Code 2025 day 10. The puzzle is effectively asking us to find a linear combination y from a series of vectors in matrix A, but minimizing the sum of the nonnegative integers in the combiner, x. So, given A and y, find the minimum sum(x) such that Ax=y.
The first example is having us build y=[3; 5; 4; 7] from A = [0 0 0 0 1 1; 0 1 0 0 0 1; 0 0 1 1 1 0; 1 1 0 1 0 0]. The text tells us (you won't see part 2 until you finish part 1) that an optimal solution is x = [1; 3; 0; 3; 1; 1], with sum(x) = 10.
julia> [0 0 0 0 1 1; 0 1 0 0 0 1; 0 0 1 1 1 0; 1 1 0 1 0 0] * [1; 3; 0; 3; 1; 2]
4-element Vector{Int64}:
3
5
4
7
I don't think Minizinc/Zelen support matrix multiplication, so I've built a program to construct a Minizinc input with the above:
var 0..: a;
var 0..: b;
var 0..: c;
var 0..: d;
var 0..: e;
var 0..: f;
var 1..: z;
constraint 3 = e + f;
constraint 5 = b + f;
constraint 4 = c + d + e;
constraint 7 = a + b + d;
constraint z = a + b + c + d + e + f;
solve minimize z;
The above input works in Gecode, but Zelen throws a parse error of kind "UnexpectedToken" on character 7. I think Zelen doesn't support this kind of half-open interval. Not sure if this is a bug, a non-standard feature in Geocode, or something else.
By setting an explicit lower and upper bound on variables a through f, Zelen solves the problem with the expected answer. I tried setting var int: a and a constraint a >= 0 for each free variable, but so far I've only gotten it to work with at most two unbounded int variables.
var 0..100: a;
var 0..100: b;
var 0..100: c;
var 0..100: d;
var 0..100: e;
var 0..100: f;
var int: z;
constraint 3 = e + f;
constraint 5 = b + f;
constraint 4 = c + d + e;
constraint 7 = a + b + d;
constraint z = a + b + c + d + e + f;
solve minimize z;
Thanks for creating Zelen!