# =============================================================================
# Cut chocolate bar
#      x1   x2   x3    n
#  ___  ___  ___  ___
# |___||___||___||___|  y1
# |___||___||___||___|  y2
# |___||___||___||___|  y3
# |___||___||___||___|  ml
#
# Luis Lopez Diaz - llopeza@uninorte.edu.co
# =============================================================================
using JuMP, GLPK, Gurobi;
# Input data
m, n = 6, 4;                # Chocolate bar dimension
x = [2 1 3];                # Cost of vertical cuts
y = [1 4 4 1 2];            # Cost of horizontal cuts
nx = length(x);             # Number of horizontal cuts
ny = length(y);             # Number of vertical cuts
nX = 1:nx;                  # Sets for vertical cuts
nY = 1:ny;                  # Sets for horizontal cuts
ml = Model(with_optimizer(Gurobi.Optimizer));
@variable(ml, 1 ≤ X[i in nX] ≤ m,Int);
@variable(ml, 1 ≤ Y[i in nY] ≤ n, Int);
@variable(ml, f);
@constraint(ml, sumX_l, nx .<= ones(1,nx)*X)
@constraint(ml, sumY_l, ny .<= ones(1,ny)*Y)
@constraint(ml, sumX_u, ones(1,nx)*X .<= nx*(ny+1))
@constraint(ml, sumY_u, ones(1,ny)*Y .<= (nx+1)*ny)
@constraint(ml, cuts, ones(1,ny)*Y + ones(1,nx)*X .== m*n-1)
@constraint(ml, con, f .== x*X + y*Y);
@objective(ml, Min, f)

optimize!(ml)
println(value.(X))
println(value.(Y))
println(value(f))
