# ==============================================================================
# Xavier Gandibleux - November 2021
#   Implemented in Julia 1.6

# ==============================================================================
# Parser of bi-01BKP instances generated by O. Perederieieva and X. Gandibleux
#   All coefficients P, W, and  ω are integer, all variables are binary

# ==============================================================================
# Datastructure of a multi-objective multi-dimensionnal KP with 0/1 variables
struct _MOMKP
    P  :: Matrix{Int} # profit of items for the objectives, k=1..p, j=1..n
    W  :: Matrix{Int} # weight of items for the constraints, i=1..m, j=1..n
    ω  :: Vector{Int} # capacity of knapsacks, i=1..m
end

# ==============================================================================
function readInstanceMOMKPformatPG(verbose::Bool, fname::String)

    f=open(fname)

    n = parse(Int, readline(f) )
    m = 2  # 2 constraints
    p = 2  # 2 objectives

    momkp = _MOMKP(zeros(Int,p,n),zeros(Int,m,n),zeros(Int,m))
    !verbose ? nothing : println("Instance of bi-01BKP : ",n," variables")

    momkp.ω[1] = parse(Int, readline(f) )
    momkp.ω[2] = parse(Int, readline(f) )
    !verbose ? nothing : println("ω[1]=",momkp.ω[1])
    !verbose ? nothing : println("ω[2]=",momkp.ω[2])

    # Extract the data of the MKP from the following lines ---------------------
    for j = 1:n
        momkp.P[1,j],
        momkp.P[2,j],
        momkp.W[1,j],
        momkp.W[2,j] = parse.(Int, split(readline(f)) )

        !verbose ? nothing :
          println("j=",j, "  |  ",
                  "p[1,",j,"]=",momkp.P[1,j], "   ",
                  "p[2,",j,"]=",momkp.P[2,j], "  |  ",
                  "w[1,",j,"]=",momkp.W[1,j], "   ",
                  "w[2,",j,"]=",momkp.W[2,j]
                 )
    end
    close(f)

    return momkp
end

# ==============================================================================

# Example on how to use it :
# fname="set1/ZL28.DAT"; verbose = true
# instancePG = readInstanceMOMKPformatPG(verbose,fname)
