Different ways to declare a constraint

jump

#1

Hello, I’m taking my first steps into Julia and I’m trying to modelate a LP. I wrote the following constraint:

@constraint(m, ctte_equilibre[r in set_regions, tec in tech_by_site[r], dy in div_years, y in years, t in timeslice],
demand_df[Symbol(r)][tl] for tl in 1:size(periode_demande,1)==sum(x_prod[r, tec, dy, y, t]))

That gives me the following error:

 LoadError: In @constraint(m,ctte_equilibre[r in set_regions, tec in tech_by_site[r], dy in div_years, y in years, t in timesli
ce],(sum(x_prod[r, tec, dy, y, t]) == (demand_df[Symbol(r)])[tl] for tl = periode_demande)): Constraints must be in one of the follow
ing forms:
       expr1 <= expr2
       expr1 >= expr2
       expr1 == expr2
       lb <= expr <= ub

The constraint related to demande_df can be expressed in a traditional loop as follow and I can acess all the elements desired at a time.

for r in set_regions

    for tl in 1:size(periode_demande,1)
        print(demand_df[Symbol(r)][tl],  '\n') 
    end

end

However, when I wrote in the reduced to way in order to be able to pass it as a constraint, it seems don’t be appropried because it returns a object called "Generator{Base.Iterators.Prod2{Array{Int64,1},Array{String,1}},##481#482} "
that I know nothing about. See bellow the reduced way I used:

demand_df[Symbol(r)][tl] for tl in 1:size(periode_demande,1),r in set_regions)

When I use this reduced way I cannot anymore to see any element at a time.
Anyone could help me to understand my problem ? Thanks in advance.


#2

Why do you mean by

demand_df[Symbol(r)][tl] for tl in 1:size(periode_demande,1)==sum(x_prod[r, tec, dy, y, t]))

Do you mean that demand_df[Symbol(r)][tl]==sum(x_prod[r, tec, dy, y, t])) for all tl ?


#3

yeahh, that’s it ! ‘demand_df’ is a data frame and the data I’m interested in are present in the column associated with the key of the dictionnary.
The demand for all tl must be equal to she sum of the the production represented here for ‘x_prod’


#4

Then why don’t you do

@constraint(m, ctte_equilibre[tl in 1:size(periode_demande,1), r in set_regions, tec in tech_by_site[r], dy in div_years, y in years, t in timeslice],
demand_df[Symbol(r)][tl]==sum(x_prod[r, tec, dy, y, t]))