I have some heavy problems of formulation with Sagemath. It's certainly a formulation problem :
I have corrected my code. May be some errors could stay. But even if I am wrong I need some information on how to write my program. You can find the source in the free paper https://pubsonline.informs.org/doi/pdf/10.1287/ited.2016.0163. There is also an Excel code on the internet. Here is my code
p = MixedIntegerLinearProgram(maximization=True,solver='PPL')
v = p.new_variable(nonnegative=True)# permet de définir v[i, j] aussi bien que v[i]
c = p.new_variable(nonnegative=True)# permet de définir v[i, j] aussi bien que v[i]
p.set_objective(v[0,0])
for i in range(7) : # nombre de lettres (8)
for j in range(9) : #nombre de chiffres
p.set_binary(v[i,j])
#S=sum(j*v[0,j] for j in range(9))
#E=sum(j*v[1,j] for j in range(9))
#N=sum(j*v[2,j] for j in range(9))
#D=sum(j*v[3,j] for j in range(9))
#M=sum(j*v[4,j] for j in range(9))
#O=sum(j*v[5,j] for j in range(9))
#R=sum(j*v[6,j] for j in range(9))
#Y=sum(j*v[7,j] for j in range(9))
for k in range(1,4) :
p.set_binary(c[k])
# Une lettre n'est représentée que par un chiffre
for j in range(8) :
p.add_constraint(0<= sum(v[i,j] for i in range(7)) <= 1)
# Un chiffre n'est associé qu'à une seule lettre
for i in range(7) :
p.add_constraint(sum(v[i,j] for j in range(9)) == 1)
# D + E = Y + 10 C_1
p.add_constraint(sum(j*v[3,j] for j in range(7))+sum(j*v[1,j] for j in range(9))==
sum(j*v[7,j] for j in range(7))+10*c[1])#
# C_1 + R + N = E + 10 C_2
p.add_constraint(c[1]+sum(j*v[6,j] for j in range(7))+sum(j*v[2,j] for j in range(9))==
sum(j*v[1,j] for j in range(9))+10*c[2])#
# C_2 + E + O = N + 10 C_3
p.add_constraint(c[2]+sum(j*v[5,j] for j in range(8))+sum(j*v[1,j] for j in range(9))==
sum(j*v[2,j] for j in range(9))+10*c[3])#
# C_3 + S + M = O + 10 C_4
p.add_constraint(c[3]+sum(j*v[0,j] for j in range(9)) + sum(j*v[4,j] for j in range(9))==
sum(j*v[5,j] for j in range(9))+10*c[4])#
# C_4 = M
p.add_constraint(c[4]==sum(j*v[4,j] for j in range(9)))
p.solve()
p.show()
xx=p.get_values(v)
show(xx)
for j in range(9) :
if xx[0,j]== 1 : print('S='+ `j`)
for j in range(9) :
if xx[1,j]== 1 : print('E='+ `j`)
for j in range(9) :
if xx[2,j]== 1 : print('N='+ `j`)
for j in range(9) :
if xx[3,j]== 1 : print('D='+ `j`)
for j in range(9) :
if xx[4,j]== 1 : print('M='+ `j`)
for j in range(9) :
if xx[5,j]== 1 : print('O='+ `j`)
for j in range(9) :
if xx[6,j]== 1 : print('R='+ `j`)
for j in range(9) :
if xx[7,j]== 1 : print('Y='+ `j`)
I have 8x10 = 80, v[i,j] variables v[i, j] and 4 c[j] variables. I have asked all to be binary. But when I look the printed model I see only 73 variables and from $x_{66}$ to $x_{73}$ they are not binary. More than that the (7,6) variables takes a value of 3/6. It's not particularly simple to associate the variables internal variables to the internal ones.
I need help! (Thanks by advance). The documentation is of no help for me.