Error in the constraint writing

Problems with syntax of GAMS
Post Reply
stef
User
User
Posts: 5
Joined: 4 months ago

Error in the constraint writing

Post by stef » 2 months ago

Good morning to all.
I'm trying to write the first objective function and the constraint 3 of the attached file, but GAMS gives me these error:

obf .. z1 =E= sum(i,t$(ord(t)<=card(U)-d(i))), b(i,t)*x(i,t);
$148 $198,154 $654,409

constr3(i) .. sum(t$(ord(t)<=card(U)-d(i)+1), x(i,t)) =L= 1;
$198

U is the number of time periods (makespan), that in the text is called T.

Thanks to those who will help me.
Attachments
Project.pdf
(1004.8 KiB) Downloaded 17 times

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 2 months ago

Hi Stef

It would be better to attach the code..., but here some hints. Look always at the first error that appears. Following errors can be caused by the first error.
In your case error 148
148 Dimension different - The symbol is referenced with more/less 148 indices as declared
It looks like you defined obf over a set (something like obv(i)).
Furthermore, if you sum over two indices, they should be surround by parentheses (e.g. sum(i,t....), b(i,t)*x(i,t));). Furthermore, your summing of the objective misses a closing matrix.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

stef
User
User
Posts: 5
Joined: 4 months ago

Re: Error in the constraint writing

Post by stef » 2 months ago

Hi Ranger and thank for your answer.
Well, now i'm going to attach the code that i wrote. I wrote only the parameter, the function objective (1) (called "fob" in the code) and the constraint (3) (called "vincolo3(i)" in the code). Please, answer me if you have more hints or if you can write this code in the correct way.
Best regards, stef.
Attachments
Progetto.gms
(1.01 KiB) Downloaded 8 times

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 2 months ago

Hi Stef

As I wrote before,f you sum over two indices, they should be surrounded by parentheses (e.g. sum(i,t....), b(i,t)*x(i,t));). Furthermore, your summing of the objective misses a closing matrix.
As GAMS collects all the set elements used in a model from begin to start in a unified element list (UEL), you will run into problems if you try to use ord(t), as GAMS, in your case, first reads the set with an element /5/ and at the end all the t elements.
It will complain that t is not ordered. You can either use a non-used set with all the numbers at the beginning (like set overall /1*10/) or move set t to the beginning.

Your code will run without a problem, if you correct your objective using the hints I gave:

Code: Select all

fob .. z1 =E= sum((i,t)$(ord(t)<=card(U)-d(i)), b(i,t)*x(i,t));
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

stef
User
User
Posts: 5
Joined: 4 months ago

Re: Error in the constraint writing

Post by stef » 2 months ago

Hi Renger,
I correct the compilation and now the code runs without problems. Now i'm having problems with the writing of constrains (4), (5) and (6), because of:
the presence of the variable x(i,j) instead of the variable x(i,t);
the presence of the parameter a(k,i) and r(t,k) instead of the parameter a(i,k) and r(k,t);
the presence of max and min over the sum;
Sorry for the lot of questions, but i don't have sufficient experience to write this constraint.
Can you help me in the writing, please?
(P.S. i'm going to attach the corrected version of the code).
Best regards, Stef.
Attachments
Progetto.gms
(1.01 KiB) Downloaded 5 times

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 2 months ago

Hi Stef
See here the equation 4. You need to use the alias.

Code: Select all

alias(t,j);

eq_sum(t,k)..
    sum(i,
        sum(j$((j.val > max(1, t.val +1 )-1) and
            j.val < min(t.val, card(t) -d(i)+ 1)), X(i,j)) * a(i,k)) =L= r(k,t);
See if this can help you formulate the other equations.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

stef
User
User
Posts: 5
Joined: 4 months ago

Re: Error in the constraint writing

Post by stef » 2 months ago

Hi Renger,
i write all the constraint and i don't have any problems. Thank you very much for your precious help.
Cheers, Stef.

Post Reply