Help with JuMP model formulation

Hello there,
I kindly need help with my code. The following is a piece of my model. The entire model is quite lengthy, so I do not wish to bore you with that. The error (stated immediately below) :

julia> for (key, value) in w
           @constraint(m, (value*(sum(d[i,j]*x[i,j] for i=1:V, j=1:V )-29)/29) <= Q)
       end
ERROR: BoundsError
Stacktrace:
 [1] getindex(::Float64, ::Int64, ::Int64) at .\number.jl:43
 [2] macro expansion at C:\Users\XX67\.julia\v0.6\JuMP\src\parseExpr_staged.jl:508 [inlined]
 [3] macro expansion at C:\Users\XX67\.julia\v0.6\JuMP\src\macros.jl:493 [inlined]
 [4] macro expansion at .\REPL[327]:2 [inlined]
 [5] anonymous at .\<missing>:?

It appears to be coming from the portion of my code listed below. I shall, therefore, be very grateful for your assistance in what I am doing wrong. Thank you in advance for the help.

V = 5

d = 
1	2	3	4	5
999	8	4	9	9
8	999	6	7	10
4	6	999	5	6
9	7	5	999	4
9	10	6	4	999


## define Variables:------------#
@variable(m, x[i=1:V,j=1:V], Bin) #decision binary variable
@variable(m, 0.0<=Q<=1.0) #mini_max variable

#3 Assign weights:________________________________#
w = Pair{Tuple{Int64,Int64},Float64}[]
for i=1:V , j=1:V
		push!( w ,  (i,j) =>  i != j ? 0.00001 : 0.00003)
end

## define Objective function:---------------#
@objective(m, Min, Q) #variable for the min_max weighted percentage deviation from the target values for the goals.

## MOLP/MOMP Goal/target contraints:----
for (key, value) in w
	@constraint(m, (value*(sum(d[i,j]*x[i,j] for i=1:V, j=1:V )-29)/29) <= Q)
end

NB: I have several other constraints, but the error as indicated above, is coming from the “MOLP/MOMP Goal/target constraint” as stated above.

Get rid of value(). It is for accessing the primal solution after a solve, not for adding in constraints.

Here’s the quickstart of the JuMP documentation: https://www.juliaopt.org/JuMP.jl/stable/quickstart/

I was too quick and missed the *. The real issue is that

d = 
1	2	3	4	5
999	8	4	9	9
8	999	6	7	10
4	6	999	5	6
9	7	5	999	4
9	10	6	4	999

is not valid syntax for a matrix. You need

d = [
1	2	3	4	5
999	8	4	9	9
8	999	6	7	10
4	6	999	5	6
9	7	5	999	4
9	10	6	4	999]

Actually, I read the matrix from a csv file using the following code. I just forgot to enclose it in bracket when I posted the code. Thank you anyways, but I don’t think that is the problem.

d = readcsv("C:/Users/XX67/Bmatrix5_dist.csv")[1]

Please make a minimal working example that demonstrates your problem. When I run the code you have (with the brackets), it works.

1 Like

You’re right, I was missing the “header=true” argument of the “readcsv” command. It should be as follows:

d = readcsv("C:/Users/XX67/Bmatrix5_dist.csv", header=true)[1]

Thanks for making me take a harder look.