Page 3 of 4
Re: Loop for objective function
Posted: Wed Apr 22, 2020 10:18 pm
by Luqman Hakeem
Renger wrote: ↑4 years ago
Same procedure:
replace the parameter or variable with one without the index t, remove the sum and, if it is a parameter, initialize it in the loop with the value for period t
Cheers
Renger
It is basically a constraint over a binary variable 'h' as;
retro(i) .. sum(tc, h(i,tc)) =l= 1;
It should run only once (means 'sum of h < 1'). Summation is working but this summation appears in every loop for "t" which is not required.
Re: Loop for objective function
Posted: Fri Apr 24, 2020 6:19 pm
by Luqman Hakeem
Renger wrote: ↑4 years ago
Same procedure:
replace the parameter or variable with one without the index t, remove the sum and, if it is a parameter, initialize it in the loop with the value for period t
Cheers
Renger
Hi Renger!
In the attached file "HGDPwFS", 'h(i,tc)' is a binary variable for fuel switching retrofitting. Retrofitting should only be done only once in the time horizon. But it appears for every loop on "t".
Re: Loop for objective function
Posted: Fri Apr 24, 2020 6:42 pm
by Renger
Hi
I think you could do without t in H(i,t). Then, if in year x, H(i) becomes 1, you fix it to that level and it will stay like this in all t afterwards.
Cheers
Renger
Re: Loop for objective function
Posted: Fri Apr 24, 2020 7:22 pm
by Luqman Hakeem
Renger wrote: ↑4 years ago
Hi
I think you could do without t in H(i,t). Then, if in year x, H(i) becomes 1, you fix it to that level and it will stay like this in all t afterwards.
Cheers
Renger
Hi Renger,
Your idea is good as always. But it is showing following errors.
141 Symbol declared but no values have been assigned. Check for missing
data definition, assignment, data loading or implicit assignment
via a solve statement.
A wild shot: You may have spurious commas in the explanatory
text of a declaration. Check symbol reference list.
143 A suffix is missing
149 Uncontrolled set entered as constant
257 Solve statement not checked because of previous errors
Re: Loop for objective function
Posted: Sat Apr 25, 2020 8:49 am
by Renger
Hi Hakeem
I am not sure if this is what you are looking for
Cheers
Renger
Re: Loop for objective function
Posted: Sun Jan 31, 2021 10:25 am
by dasa
Renger wrote: ↑5 years ago
Hi
You should rewrite the set j from your model and treat the variables and parameters independent of j. Here an example:
Code: Select all
set j /1*2/;
parameter
p(j) Parameter defined over j,
pj Scalar to be used in the loop to replace p;
p(j) = ord(j);
variable OBJ,X;
equation objective, eq1;
objective..
OBJ =E= x;
eq1..
X=E= pj;
model test /all/;
loop(j,
pj = p(j);
solve test maximizing OBJ using nlp;
);
In your case:
Code: Select all
sum(q,(w(q)**n)*(abs(p(j,q)-c('1',q)))**n))**in
becomes
Code: Select all
sum(q,(w(q)**n)*(abs(pj(q)-c('1',q)))**n))**in
and if p(j,g) is a parameter, it is now set in the loop as
If p(j,g) is a variable, you define it as PJ(g) and save the result in a parameter results("p", j,g) = PJ.L(g);
Your distance function then becomes L("1").
Hope this helps.
Cheers
Renger
Dear Renger,
Following the question, i have some related problem. in my case, it happen in variable as my below
Code: Select all
set t /1*5/
m /1*2/;
parameter a(m) /1 2,2 3/;
parameter b(m) /1 5,2 4.5/;
variables P(m,t),z;
parameter
am
bm
Pm;
loop(m,
am=a(m);
bm=b(m);
Pm(t)=P(m,t);
);
equation o1, c1, c2;
o1.. z=e=am*sum(t,Pm(t))+bm;
c1(t).. Pm(t) =l=5;
c2(t).. Pm(t) =g= 0;
model gg/all/
loop(m,
solve gg using lp minimizaing z;
);
I don't know, what is wrong with it. please kindly help me. Thanks
Re: Loop for objective function
Posted: Sun Jan 31, 2021 12:50 pm
by Renger
Hi
It is not clear from your post what you intend to do.
You assign the value of a variable to another variable before you solved the model (Pm(t) = P(m,t)) in a loop over m which also doesn't make sense. Pm(t) would get the value of the last m.
CHeers
Renger
Re: Loop for objective function
Posted: Sun Jan 31, 2021 1:33 pm
by dasa
Renger wrote: ↑3 years ago
Hi
It is not clear from your post what you intend to do.
You assign the value of a variable to another variable before you solved the model (Pm(t) = P(m,t)) in a loop over m which also doesn't make sense. Pm(t) would get the value of the last m.
CHeers
Renger
Hello,
Thanks for your feedback. what i want to do is to solve this optimization problem for every m. However, i don't know how to do it.
Re: Loop for objective function
Posted: Sun Jan 31, 2021 1:46 pm
by Renger
Code: Select all
set t /1*5/
m /1*2/;
parameter a(m) /1 2,2 3/;
parameter b(m) /1 5,2 4.5/;
variables Pm(t),z;
parameter am, bm, resultsm, resultsmt;
equation o1, c1, c2;
o1.. z =e= am*sum(t,Pm(t))+bm;
c1(t).. Pm(t) =l= 5;
c2(t).. Pm(t) =g= 0;
model gg /all/;
loop(m,
am = a(m);
bm = b(m);
solve gg using lp minimizaing z;
resultsmt(m,t, "PM") = PM.L(t);
resultsm(m, "z") = Z.L;
);
display resultsm, resultsmt;
Cheers
Renger
Re: Loop for objective function
Posted: Sun Jan 31, 2021 1:50 pm
by dasa
Renger wrote: ↑3 years ago
Code: Select all
set t /1*5/
m /1*2/;
parameter a(m) /1 2,2 3/;
parameter b(m) /1 5,2 4.5/;
variables Pm(t),z;
parameter am, bm, resultsm, resultsmt;
equation o1, c1, c2;
o1.. z =e= am*sum(t,Pm(t))+bm;
c1(t).. Pm(t) =l= 5;
c2(t).. Pm(t) =g= 0;
model gg /all/;
loop(m,
am = a(m);
bm = b(m);
solve gg using lp minimizaing z;
resultsmt(m,t, "PM") = PM.L(t);
resultsm(m, "z") = Z.L;
);
display resultsm, resultsmt;
Cheers
Renger
Impressive!!! thanks you so much.