Need someone to explain to me this

Note that the both the utility of the indexes and of the constraints is documented within the example:

We have binary variables x[i, j, k] which, if = 1, say that cell (i, j) contains
the number k. The constraints are:
 1 - Each cell has one value only
 2 - Each row contains each number exactly once
 3 - Each column contains each number exactly once
 4 - Each 3x3 subgrid contains each number exactly once

Considering the variables are binary and the problem is a MIP, it means only one variable must have a value of one and all other must have value zero. Note that integer variables may allow negative values, so this only means the same for integer variables if they are restricted to the non-negative domain.

Not exactly. Learning how to write formulations is actually half of a class that I help my advisor in the university, so I cannot condense it in just a reply. When a certain range of values represent, in fact, a set of categorical values, and there is not a real relationship of ordering between the values, many times you will want to expand some dimension to all their possible values, and use a binary variable for each value instead, together with a constraint guaranteeing only one of these has non-zero value at a time. Otherwise, if the values actually represent an amount of something (vehicles, money, croissants, etc…), many times the best representation is just an integer variable. In some cases, you will not use the representation that feels more natural because of memory constraints, this is, you will need to make do with an integer variable because expanding all values to binary variables make the model too large. There is also a lot of tricks involved, here you can see some tips. The material is using MathProg instead of Julia+JuMP but more what is said is not framework specific.

1 Like