Error in the constraint writing

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

Error in the constraint writing

Post by stef » 9 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 32 times

User avatar
Renger
Posts: 547
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 9 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: 11 months ago

Re: Error in the constraint writing

Post by stef » 9 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 25 times

User avatar
Renger
Posts: 547
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 8 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: 11 months ago

Re: Error in the constraint writing

Post by stef » 8 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 20 times

User avatar
Renger
Posts: 547
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 8 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: 11 months ago

Re: Error in the constraint writing

Post by stef » 8 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.

anil
User
User
Posts: 3
Joined: 2 weeks ago

Re: Error in the constraint writing

Post by anil » 2 weeks ago

English Exam.JPG[/attachment [attachment=1]Math Model.jpeg


Hi. When I create and write the mathematical model, I get the following Errors. I would appreciate your help.

GAMS 31.1.0 r55b6ce3 Released May 1, 2020 WEX-WEI x86 64bit/MS Windows - 05/16/20 17:39:01 Page 1
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
C o m p i l a t i o n


1 variables
2 x11
3 x12
4 x13
5 x14
6 x15
7 x21
8 x22
9 x23
10 x24
11 x25
12 x31
13 x32
14 x33
15 x34
16 x35
17 y1
18 y2
19 y3
20 z;
21 positive variables
22 x11
23 x12
24 x13
25 x14
26 x15
27 x21
28 x22
29 x23
30 x24
31 x25
32 x31
33 x32
34 x33
35 x34
36 x35
37 y1
38 y2
39 y3;
40 equations
41 amac
42 kisit1
43 kisit2
44 kisit3
45 kisit4
46 kisit5
47 kisit6
48 kisit7
49 kisit8
50 kisit9
51 kisit10
52 kisit11;
53 amac..z=e=10*y1+8*y2+6*y3;
54 kisit1..2700*x11+2800*x12+1100*x13+1800*x14+3500*x15+y1=e=2900
55 kisit2..2700*x21+2800*x22+1100*x23+1800*x24+3500*x25+y2=e=4000
**** $409
**** 409 Unrecognizable item - skip to find a new statement
**** looking for a ';' or a key word to get started again

56 kisit3..2700*x31+2800*x32+1100*x33+1800*x34+3500*x35+y3=e=4900
57 kisit4..y1=l=500
58 kisit5..y2=l=500
59 kisit6..y3=l=500
60 kisit7..x11+x21+x31=e=1
61 kisit8..x12+x22+x32=e=1
62 kisit9..x13+x23+x33=e=1
63 kisit10..x14+x24+x34=e=1
64 kisit11..x15+x25+x35=e=1;
65 model Gamsdeneme1/all/
66
67 solve Gamsdeneme1 using mip minimizing z;
**** $257
**** 257 Solve statement not checked because of previous errors

**** 2 ERROR(S) 0 WARNING(S)


COMPILATION TIME = 0.063 SECONDS 2 MB 31.1.0 r55b6ce3 WEX-WEI


USER: GAMS Demo license for ANIL EROGLU G200516|0002CO-GEN
Halic Universitesi, Turkey DL009985


**** FILE SUMMARY

Input C:\Users\anil.eroglu\Desktop\�a�r�\END316\Gams Deneme1.gms
Output C:\Users\anil.eroglu\Desktop\�a�r�\END316\Gams Deneme1.lst

**** USER ERROR(S) ENCOUNTERED
gams error.JPG
Attachments
Math Model.jpeg
English Exam.JPG

User avatar
Renger
Posts: 547
Joined: 3 years ago

Re: Error in the constraint writing

Post by Renger » 2 weeks ago

Hi
You should end code lines with a semicolon (there are a few lines without).
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Post Reply