I’m new to Julia and I want tot solve this problem with integer, digits solutions:
“Each letter represents a different non-zero digit: SEE + SEE = AXES”
I create this code and returns an inaccurate solution:
using JuMP, Clp
m = Model(Clp.Optimizer)
@variables m begin
A
X
E
S
end
#SEE + SEE = AXES
@constraints m begin
2(100S + 10E + E) == 1000A + 100X + 10E + S
A >= 1; A <=9
X >= 1; X <=9
E >= 1; E <=9
S >= 1; S <=9
end
optimize!(m)
value.((A, X, E, S))
I can’t force proper the constrains. Any help is wellcomed!
using JuMP, GLPK
m = Model(GLPK.Optimizer)
@variables m begin
A, Int
X, Int
E, Int
S, Int
end
#SEE + SEE = AXES
@constraints m begin
2(100S + 10E + E) == 1000A + 100X + 10E + S
A >= 1; A <=9
X >= 1; X <=9
E >= 1; E <=9;
S >= 1; S <=9;
end
optimize!(m)
You are welcome. I am by no means an expert in this field, and cannot comment whether this is the best solution.
The difference from you formulation ist, that the integer constraint is given in the variable definition.
If you are interested the corresponding part in the docs can be found here: https://jump.dev/JuMP.jl/dev/manual/variables/#Integer-constraints
The other problem was about your particular choice of solver.
Not all of them can handle integer constraints. As interger linear programs are NP hard in general, solvers that can tackle this kind of problems are much more sophisticated.