New to GAMS, Can't find solution, please HELP!

Dear All,

I am new to GAMS, and I am not sure how to overcome this problem, I
have searched a lot, and would be really appreciate any help:
What I am trying to do ultimately is to maximize mttfTest, where:
(this is not GAMS syntax)

mttfTest = sum [ from i = 1 to Nq , i * (Rq ** i) * (1 -
Rq) ] , in other words, i * (Rq ** i) * (1 - Rq) is
performed for index i which takes on values from 1 to Nq, and all
results are summed.

I wasn’t sure how to model the iterations from 1 to Nq so I attempted
to do it through creating a set J which has [1 to Nq] elements, and
iterated the equation over J (you can see this in the code below),
this is not working, as Nq is a variable which gets its value from an
equation, and I get this error → " Could not extract number in

  • list" .
    I am not sure if I have modeled the eMttf equation below (in code) to
    match the logic of the equation above, I cannot seem to use the Nq
    value to subsequently find the mttfTest

This is part of the code, if needed I can include the full code:
Thanks in advance,
Hamid

Variables
ms(s)
mp(s)
Rq
Eq
Nq
mttfTest ;

Binary variable ms(s);
Binary variable mp(s);

Equations eEq
eRq
eRqConstraint
eNq
eDisjoint
eMttf ;

eEq… Eq =e= sum(s, ep(s)*mp(s)) + sum(s, es(s)*ms(s)) +
ech;
eRq… Rq =e= (1 - prod(s, (1 - ms(s) + qfs(s)*ms(s)) )) * (1

  • prod(s, (1 - mp(s) + qfp(s)*mp(s)) ));
    eRqConstraint… rreq =l= Rq;
  • the Nq variable below is need for eMttf equation
    eNq… Nq =e= ceil(hqeon/(hq*Eq + Ec/Tc));

  •    line below  produces   error  " Could not extract number in
    
  • list"
    SET J / 1 * Nq/;

  • This is the objective function, ord(J) is simply the i index which
    spans from 1 to Nq
    eMttf… mttfTest =e= sum{J, ord(J) * (Rq** ord(J))*(1-
    Rq)};

eDisjoint… 0 =e= sum(s, mp(s)*ms(s));

mp.l(s) = 1;
ms.l(s) = 1;

Model energyCost /all/;

Solve energyCost using minlp maximizing mttfTest;
option decimals=8;
display ms.l, mp.l, Eq.l, Rq.l, Nq.l, mttfTest.l;


\

Could anybody please reply, I desperately need help, solution is most
likely easy, I just don’t have a clue …

\

Hamid,

Your model is not a mathematical program (MP) in the classical sense
and that’s why you have difficulties implementing this in GAMS. Your
summation index depends on a variable. MP does not allow this, this
has nothing to do with GAMS. You need to reformulate your problem in
to a proper MP. For example, you could make a set j that goes from 1
to NqMAX which is number you need to calculate just based on data. I
don’t understand the model enough to give suggestions, but I am sure
you can come up with some upper bound for Nq. Now you could introduce
a binary variable inNq for each j. You would need to enforce that only
the first Nq variables of inNq are set to one. This can be done with
constraints like this:

  • some tight upper bound on Nq
    $set NqMax 100
    set j / 1*%NqMax%/

e1… sum(j, inNq(j)) =e= Nq;
e2(j)… ord(j)*inNq(q) =l= Nq;

Now you can write down mttfTest like this:

e3… mttfTest =e= sum(j, ord(j)inNq(j)(Rq**ord(j))*(1-Rq));

I am not sure if this is a good reformulation (it introduces some non-
convexities), but that’s a start and you can probably improve on this.

Hope this helps,
Michael Bussieck - GAMS World Coordinator

On Jun 29, 3:31 pm, Hamid wrote:

Could anybody please reply, I desperately need help, solution is most
likely easy, I just don’t have a clue …

\

Thank you Michael for your prompt response, I really appreciate your
help, I had to try it out thoroughly before replying (reply might look
big below but thats just to make it easier to understand), somethings
wrong,
its not giving correct/meaningful results, my NqMax is high in my
calculations, can go up to 2,000,000, so when I try it with the code
that I’ve modified and added it takes a very long time to execute, as
the inNq and j
sizes are dependent on this NqMax and the results do not make sense:

  • A simple workaround and solution that would work for my purposes is
    if I can export results (without specifying maximizing/minimizing a
    variable), and then do the actual eMttf
    equation above using some programming language.

to be more exact, in my program, every combination of the binary
variables mp(s) and ms(s) would result in a different Eq and Rq value
(found in eEq and eRq equations respectively),

The relevant code:

Sets
s sensors / s1*s24 /;

Binary variable ms(s);
Binary variable mp(s);

eEq… Eq =e= sum(s, ep(s)*mp(s)) + sum(s, es(s)*ms(s)) + ech;
eRq… Rq =e= (1 - prod(s, (1 - ms(s) + qfs(s)*ms(s)) )) * (1 -
prod(s, (1 - mp(s) + qfp(s)*mp(s)) ));

Aim: I would want the output to be something like a table format with
all combinations of mp(s) and ms(s) explored , for instance:



ms(s) , mp(s) , resuling Eq, resulting Rq
{s1} {s2} someValue someValue
{s1} {s3} someValue someValue
{s1,s2} {s3} someValue someValue
{s1,s2,s3} {s4,s5} someValue someValue
… … … … …
(and so on …)

I can compute the rest offline (using “resulting Eq” and “resulting
Rq” columns above), is there a way to tell GAMS to do this?=> give the
Rq and Eq values for all
combinations of ms(s) and mp(s) and print these results (to a file),
I think you would only need to analyze the “relevant code” above.
(This would be irrelevant of minimizing or maximizing anything in the
solve statement- I won’t do that in GAMS anymore).

Thank you for your time,
Hamid



On Jun 30, 3:28 am, Gamsworld Admin wrote:

Hamid,

Your model is not a mathematical program (MP) in the classical sense
and that’s why you have difficulties implementing this in GAMS. Your
summation index depends on a variable. MP does not allow this, this
has nothing to do with GAMS. You need to reformulate your problem in
to a proper MP. For example, you could make a set j that goes from 1
to NqMAX which is number you need to calculate just based on data. I
don’t understand the model enough to give suggestions, but I am sure
you can come up with some upper bound for Nq. Now you could introduce
a binary variable inNq for each j. You would need to enforce that only
the first Nq variables of inNq are set to one. This can be done with
constraints like this:

  • some tight upper bound on Nq
    $set NqMax 100
    set j / 1*%NqMax%/

e1… sum(j, inNq(j)) =e= Nq;
e2(j)… ord(j)*inNq(q) =l= Nq;

Now you can write down mttfTest like this:

e3… mttfTest =e= sum(j, ord(j)inNq(j)(Rq**ord(j))*(1-Rq));

I am not sure if this is a good reformulation (it introduces some non-
convexities), but that’s a start and you can probably improve on this.

Hope this helps,
Michael Bussieck - GAMS World Coordinator

On Jun 29, 3:31 pm, Hamid wrote:

Could anybody please reply, I desperately need help, solution is most
likely easy, I just don’t have a clue …

\