Page 1 of 1

gams programming problem

Posted: Mon Jan 15, 2018 2:33 pm
by YCF0913
Hi,ther is a gams problem,I need your help.
Table Data (seq, com)
A1 A2 A3 A4 A5
1 0 0 1 2 3
2 0 0 2 2 2
3 0 1 1 1 2
4 0 1 2 2 1
5 0 2 2 1 1
6 1 0 0 1 2
7 1 0 1 1 1
8 1 1 1 0 1
9 2 1 0 0 1
10 1 1 2 2 0
11 1 2 2 1 0
12 2 1 1 1 0
13 2 2 2 0 0
14 3 2 1 0 0
Operation logic:
A total of 14 sequences, 5 components, the five components required four points of separation to completely separate.
1. Two consecutive 0 in a row, then the first separation point must appear between these two components.
2.Only one 0 appears in a row
(1) If 0 appears at the beginning or at the end of each row, the first point of separation is the first or fourth;
(2) If 0 is not at the beginning or end, the first point of separation is on the non-beginning or non-end of this component;
3. For each determination of a separation point, the number of the remaining components other than the two components apart on both sides of the separation point is subtracted by 1, and the logic of the above-mentioned regulation 1 and 2, respectively, is re-determined. After dividing the separation points into two groups, Is tied, one after the other in random order.


I have tried to do it,but ther are some errors.
Sets
num1 /1*14/
subs /A1*A5/;
Table Data(num1,subs)
A1 A2 A3 A4 A5
1 0 0 1 2 3
2 0 0 2 2 2
3 0 1 1 1 2
4 0 1 2 2 1
5 0 2 2 1 1
6 1 0 0 1 2
7 1 0 1 1 1
8 1 1 1 0 1
9 2 1 0 0 1
10 1 1 2 2 0
11 1 2 2 1 0
12 2 1 1 1 0
13 2 2 2 0 0
14 3 2 1 0 0
;
Scalar dspt distillation point ;

loop( num1,
if( Data(num1,subs)=0 and Data(num1,subs+1)=0 ,
dspt=ord(subs) ;
elseif(Data(num1,subs)=0 and Data(num1,subs+1)>0)and ord(subs)=1,
dspt=1 ;
elseif(Data(num1,subs)=0 and ord(subs)=5 and Data(num1,subs-1)>0),
dspt=4;
elseif(Data(num1,subs)=0 and Data(num1,subs+1)>0) and ord(subs)=2,
dspt=2;
else dspt=3 ;
);
);
Display dspt;

Re: gams programming problem

Posted: Tue Jan 16, 2018 11:34 am
by Renger
Hi

You should loop over num1 and then over subs to get your code running. dspt should then be defined as dspt(num1):

Code: Select all

parameter dspt distillation point ;
loop(num1,
    loop(subs,
        if(Data(num1,subs)=0 and Data(num1,subs+1)=0 ,
            dspt(num1)=ord(subs) ;
        elseif(Data(num1,subs)=0 and Data(num1,subs+1)>0)and ord(subs)=1,
            dspt(num1)=1 ;
        elseif(Data(num1,subs)=0 and ord(subs)=5 and Data(num1,subs-1)>0),
            dspt(num1)=4;
        elseif(Data(num1,subs)=0 and Data(num1,subs+1)>0) and ord(subs)=2,
            dspt(num1)=2;
        else dspt(num1)=3 ;
        ); 
    );
);
Display dspt;
The rest is up to you. Hope this helps

Cheers
Renger

Re: gams programming problem

Posted: Tue Jan 16, 2018 2:08 pm
by YCF0913
Hi,Renger

Thanks for your kind reply. I will try the rest by myself.

Regards,
Yin