Page 1 of 1

Enter cyclic parameters

Posted: Wed May 20, 2020 6:37 pm
by Damaskinos
Hi,

I am modelling electricity consumption of a household during three month long period. Daily consumption is assumed to be the same every day. I import data from excel file, where the data are like c(1) - 0.2 (kWh), c(2) - 0.2 (kWh),..., c(24) - 0.1 (kWh). So I've currently imported a vector of 24 parameters, but i need to 'copy' them consecutively. Like this way: cc(1) = c(1), ..., cc(24) = c(24), cc(25) = c(1), cc(26) = c(2) and so on, to get vector of 24*90(hours*days) hours long. I've tried combination of loop and mod function, but it didnt worked. Can anybody please help? Thanks. :)

Re: Enter cyclic parameters

Posted: Sat May 23, 2020 9:16 am
by Renger
Hi
Take a look at these loops. I believe they are doing what you try to achieve (I initialized the first 24 values with the numbers 1 to 24 to easily check the results):

Code: Select all

set i /1*2160/, l /1*90/, k(i) /1*24/;
parameter c(i);

* Values for the first 24 hours
c(i)$(i.val < 25) = ord(i);
display c;

loop(i, 
    loop(l,
        loop(k$(k.val = i.val - l.val*24), 
            c(i) = c(k);
       );
    );
);

display c;
Cheers
Renger

Re: Enter cyclic parameters

Posted: Sat May 23, 2020 1:26 pm
by Damaskinos
Hi Renger,

first of all, thanks for your quick reply. It looks pretty accurate and works well. I'm glad you understood although my description was pretty weird. The question is following, is there any possibility to manage situation, when I have data, let's say for (n+1/2) of days? Because if I understand well, your code would work for complete days only. I've tried using "mod" function, but I had a lot of problems as rewriting parameter requires to have index of a set in the argument. Assume the following example:

Sets t /1*3649/
tt(t) /1*3649/
ttt(t) /1*24/;

Parameters D(tt)
DD(ttt); - i write data from excel spreadsheet to parameter DD(ttt)

and then I wanted to use something like

loop(tt,
D(tt) = D(mod(ord(tt-1),24)+1)
);

It would work perfectly, because it shifts argument and doesn't leave any empty parameter D(tt) for arbitrary tt value, except it doesn't work as I expected... Well... It doesn't work at all. :D My point is - what to do If I don't have nice data that can be divided exactly into whole days like you did?

Re: Enter cyclic parameters

Posted: Mon May 25, 2020 10:07 am
by Renger
Hi
Could you make a small example with numbers and (to keep it simple) a repeating week and daily values (e.g. you have the values for one week and want to have them for all weeks)? It is not clear to me what you want to do with the half days.
Cheers
Renger

Re: Enter cyclic parameters

Posted: Mon May 25, 2020 10:54 am
by Damaskinos
Hi,

of course. Let's say, I have hourly data of consumption for 54 hours (like 2.25 days), hence set i / 1*55/ (including consumption from 0.00 to 1.00); and hourly data of production for 24 hours only, hence probably ii(i) /1*25/. What I need is to extend production data to have the same length as a consumption data. Both starting at the same time at time 0.00.

Re: Enter cyclic parameters

Posted: Mon May 25, 2020 3:58 pm
by Renger
Hi
Is this what you are looking for:

Code: Select all

Sets t /1*55/
     k(t) /1*24/
;
Parameter
    c(t),s(t);
s(k) = k.val;
c(t) = t.val;

loop(t,
    s(t) = sum(k$(mod(t.val,24) = k.val), s(k));
);

display s;
Cheers
Renger

Re: Enter cyclic parameters

Posted: Wed Jul 29, 2020 9:08 am
by Damaskinos
Hi Renger,

I had to left this project for a while, so sorry for not replying. It's almost what I am looking for, but there is problem with the right index definition. Using your code, I get 24th value equal to zero, hence if I want to use this way for parameter definiton, as the value is zero, I can only assign parameter to "t" values from 1 to 23, then it's equal to zero and then from 25...

To demonstrate the problem, I attached the code below. I store daily data in D like /1 230, ...., 24 125/. Using the following code, the problem is that I get 24th value = 125 (correct), 25th value = 0 (incorrect), 26th value = 230 (but this should be 25th value). Hope you understand my weird description and you could help. :roll:

Code: Select all

Sets t /1*55/
     k(t) /1*24/;

Parameters
D(t) the aggregate energy demand at time t;

loop(t,
    D(t) = sum(k$(mod(t.val,25)= k.val), D(k));
);

display D;

Re: Enter cyclic parameters

Posted: Wed Jul 29, 2020 10:57 am
by Renger
Hi Damaskinos

Just go back to using 24 for the mod function, and add another loop (probably could be done in a more efficient way...):

Code: Select all

loop(t,
    D(t) = sum(k$(mod(t.val,24)  = k.val), D(k));
    if((mod(t.val,24) = 0),
        loop(k$(k.val = card(k)),
            D(t) = D(k););    
);
Cheers
Renger

Re: Enter cyclic parameters

Posted: Wed Jul 29, 2020 4:23 pm
by Damaskinos
Hi Renger,

I've tried your suggested code, but it's still the same. 25th value is assigned to zero. :(

Cheers,
Damaskinos

Re: Enter cyclic parameters

Posted: Wed Jul 29, 2020 4:42 pm
by Renger
Hi Damaskinos
THis works.

Code: Select all

Sets t /1*55/
     k(t) /1*24/
;
Parameter
    c(t),s(t);
s(k) = k.val;
c(t) = t.val;
display s;
display s;

loop(t,
    s(t) = sum(k$(mod(t.val,24)  = k.val), s(k));
    if((mod(t.val,24) = 0),
        loop(k$(k.val = card(k)),
            s(t) = k.val););
);

display s;

Cheers
Re ger