2 models using the variable of the first as the set of the second Topic is solved

Problems with modeling
Post Reply
Alexanre.ito
User
User
Posts: 38
Joined: 4 years ago

2 models using the variable of the first as the set of the second

Post by Alexanre.ito »

Hi, I'm with a problem that I have a problem with 2 models.
The first is ok, my model optimize the flow at the tubes.
At the second I need to use equations, using that flow, but the tubes with no flow (zero), it shod be exclude.
But I don't know how to express this condition.

My model is showing this massage.
" **** Exec Error at line 412: division by zero (0) "

So, the problem is my model try to use the equation to my first set, that have a variable that was optimized previously equal to a zero
but at the second model, the equation use the variable that is zero, but it should be exclude and not be calculated.

Model 1
Set
n nodes / n1 * n3 /
nn(n,n) tubs...;
alias(n,np);
....
Variables
qr(n,np) (m**3 per sec) ...;
......
Model flow /consn,qin,qout,qin1,qcl,binar,binsaid,qred,minvaz/ ;

Solve flow using minlp minimizing minq;

The result:
---- VAR qr (m**3 per sec)

LOWER LEVEL UPPER MARGINAL

n1.n2 . 124.142 +INF .
n1.n3 . 14.142 +INF .
n3.n1 . . +INF .
n3.n2 . 110.000 +INF .



Model 2
SET
d diamet;
....
EQUATIONS
mann(nn);

mann(nn).. (a(nn) -sin(a(nn))**(5/3)) / a(nn)**(2/3) =n=
(qr(nn)*n* 2**(13/3) ) /( dr(nn)**(8/3) * sqrt(ir(nn)) );
....

Was the explanation clear?
could someone help me?
Thanks
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Renger »

Hi

If this means that the equation mann(n,n) is also dropped, you could add a flag for this equation

Code: Select all

parameter flag(n,n)  Flag for adding equation;
alias(n,an);
flag(n,an) = 1;
...
mann(n,an)$flag(n,an)..
  ...

solve model 1

flag(n,an)$(qr(n,an) > 0) = 1;

solve model 2;
I hope this is what you meant.

Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Alexanre.ito
User
User
Posts: 38
Joined: 4 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Alexanre.ito »

Thank you very much Roger, this is exactly what I wanted.
But I think my code is not considering my variable as a SET.
For when I insert an error is presented:

Code: Select all

     472 flag (n, np) $ (qr (n, np)> 0) = 1;
****                      $143
Did you know how to put this variable as a SET together with the value?
so that I can consider it in my second model? Or correct this error?

I insert as:

Code: Select all

$Stitle1
Parameter flag(n,np)
	flag(n,np)          = 1;
	
Variables qr,qno,ql;
...	
Equation
qred(nn(n,np))$flag(n,np).. qr(nn) =e= qno(nn) + ql(nn);
...
Solve problem 1
*====================================
$Stitle2
Parameter flag(n,np)
	flag(n,np) $ (qr (n, np)> 0) = 1         = 1;
Scalar     n;
Variables  a,dr,ir,
		
Equation	
mann1(nn))$flag(n,np)..
	(a(nn) -sin(a(nn))**(5/3)) /   a(nn)**(2/3) =n=
                (qr(nn)*n* 2**(13/3) )  /( dr(nn)**(8/3) * sqrt(ir(nn)) );
                
Solve problem 2
I tried to use the model 1 binary variable, but it didn't work. It continued to divide by zero.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Renger »

Hi
qr is a variable, so one should use qr.L in the parameter and you should stage it like this (don't repeat the line with the definition of the parameter). If you still have a division by zero, this can be caused by another parameter or variable. Make sure that your other variables are not equal to zero at the start of the solve as these are the values that Gams uses as start values (e.g. by initialising them: a.l(nn) =1; dr.l(nn) = 1

Renger

Code: Select all

$Stitle1
Parameter flag(n,np)
	flag(n,np)          = 1;
	
Variables qr,qno,ql;
...	
Equation
qred(nn(n,np))$flag(n,np).. qr(nn) =e= qno(nn) + ql(nn);
...
Solve problem 1
*====================================
flag(n,np) $ (qr.L(n, np)> 0) = 1         = 1;
Scalar     n;
Variables  a,dr,ir,
		
Equation	
mann1(nn))$flag(n,np)..
	(a(nn) -sin(a(nn))**(5/3)) /   a(nn)**(2/3) =n=
                (qr(nn)*n* 2**(13/3) )  /( dr(nn)**(8/3) * sqrt(ir(nn)) );
                
Solve problem 2


____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Alexanre.ito
User
User
Posts: 38
Joined: 4 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Alexanre.ito »

Thank you very much Renger,
it helped me a lot.
it still hasn't solved my problem, but for what I'm trying to do, it worked really well.
Last edited by Alexanre.ito 3 years ago, edited 1 time in total.
Alexanre.ito
User
User
Posts: 38
Joined: 4 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Alexanre.ito »

Hi Renger,
It it possible to do this same idea, using all the equation at the same model?

Renger wrote: 3 years ago Hi
qr is a variable, so one should use qr.L in the parameter and you should stage it like this (don't repeat the line with the definition of the parameter). If you still have a division by zero, this can be caused by another parameter or variable. Make sure that your other variables are not equal to zero at the start of the solve as these are the values that Gams uses as start values (e.g. by initialising them: a.l(nn) =1; dr.l(nn) = 1

Renger

Code: Select all

$Stitle1
Parameter flag(n,np)
	flag(n,np)          = 1;
	
Variables qr,qno,ql;
...	
Equation
qred(nn(n,np))$flag(n,np).. qr(nn) =e= qno(nn) + ql(nn);
...
Solve problem 1
*====================================
flag(n,np) $ (qr.L(n, np)> 0) = 1         = 1;
Scalar     n;
Variables  a,dr,ir,
		
Equation	
mann1(nn))$flag(n,np)..
	(a(nn) -sin(a(nn))**(5/3)) /   a(nn)**(2/3) =n=
                (qr(nn)*n* 2**(13/3) )  /( dr(nn)**(8/3) * sqrt(ir(nn)) );
                
Solve problem 2


User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Renger »

Of course
R
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Alexanre.ito
User
User
Posts: 38
Joined: 4 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Alexanre.ito »

Renger wrote: 3 years ago Of course
R
Hi Roger
I was trying to write
the Parameter flag2
flag2(nn)$(qr.l(nn) > 0 ) = flag(nn) ;

but not using different models, How I supposed to program this, in the same model?

It's indicated a error : (qr.l(nn))
*** Error 141 in D:\.....gms
Symbol neither initialized nor assigned
A wild shot: You may have spurious commas in the explanatory
text of a declaration. Check symbol reference list.

When I use this PARAMETER with 2 diferents models, it run with no error.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: 2 models using the variable of the first as the set of the second

Post by Renger »

Hi
It looks like you have assigned the values before running the model which doesn't make sense as you don't have a solution for Q available.
If you run the same model again using Q.L you should assign flag2 after the solve of the first instance.

Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply