2
$\begingroup$

I have the following sets, variables, and parameters in a GAMS model.

set \quad h/1*3/;
alias (h,t);

Positive variables are $p_d(h)$, $p_c(h)$ and $e(h)$. Parameters are $\eta = 0.9$ and $e(0) = 0$.

I want to write the following equation in GAMS: $$e(h) = e(0)-\sum_{t=1}^h p_d(t)+\eta\cdot\sum_{t=1}^hp_c(t).$$

$\endgroup$
4
  • $\begingroup$ You could try something like this: eq(h).. e(h) =e= e("0") - sum(t, pd(t)) + n*sum(t, pc(t)); but, if the element in the e(0) is a element of the $h$, you should define it and then use a filter on the other sets into the constraint. $\endgroup$ – A.Omidi Apr 25 '20 at 20:02
  • $\begingroup$ Thank you, I tried that. It throws an error that number (primary) expected. Also, it doesn't define the relationship that, when h=1, t=1; when h=2, t=1,2 etc. I think some conditional operator is required for the indexing, but not sure how to implement that. e(0) is treated as a parameter. $\endgroup$ – S_Scouse Apr 25 '20 at 23:04
  • $\begingroup$ Would you try using dollar operator to define the conditions into the statement? For example, eq(h)$(ord(h)>1)... . $\endgroup$ – A.Omidi Apr 26 '20 at 11:15
  • 1
    $\begingroup$ I think you will need to define a whole set consists of the $0$ element. Next, define a subset with your favourite elements. (E.g. set Total / 0, 1*3 /; set h(total) / 1*3 /;) $\endgroup$ – A.Omidi Apr 26 '20 at 11:23
1
$\begingroup$

Eq(h) .. e(h) =e= E0 - sum(t$(ord(t) <=Ord(h) ), pd(t)+n*sum(t, pc(t));

It's better to define E0 as a scalar in GAMS.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.