## Synthax of binary variables

Problems with syntax of GAMS
M.Walde
User
Posts: 16
Joined: 6 months ago

### Synthax of binary variables

Hey guys,

sorry for the spaming lately, but as I said I'm quite a beginner and thus there are a lot of question, which I can't answer just with the documentary.

I'm now using binary variables in my model. But I got a problem with the execution, which I don't understand.

This is the important code:

i time steps /0*720/;

positive variable m_pb_ts(i) mass flow from power block to thermal energy storage;
positive variable m_pb_rc(i) mass flow from power block to receiver;
binary variable npb(i) not operating power block binary;

m_pb_ts.l('1') = 0;
m_pb_rc.l('1') = 0;
npb.l('1') = 1;

e_npb(i+1) .. npb(i+1) =e= (m_pb_rc(i+1) = 0 and m_pb_ts(i+1) = 0);

I'm expecting npb to be 1 in the beginning, since the mass flows should be zero.

This is what I get after executing:

---- e_npb =E= setting decision variable for not operating power block mode

e_npb(1).. (0)*m_pb_ts(1) + (0)*m_pb_rc(1) + npb(1) =E= 0 ; (LHS = 0)

e_npb(2).. (0)*m_pb_ts(2) + (0)*m_pb_rc(2) + npb(2) =E= 0 ;

(LHS = -1, INFES = 1 ****)

e_npb(3).. (0)*m_pb_ts(3) + (0)*m_pb_rc(3) + npb(3) =E= 0 ;

(LHS = -1, INFES = 1 ****)

Obviously the equation doesn't work.
That is why my question is, whether there is something wrong with my syntax in defining the equation or the variable.
I'm using minlp with scip solver.

Cheers
Max

Manassaldi
User
Posts: 65
Joined: 1 year ago
Location: Rosario - Argentina

### Re: Synthax of binary variables

e1_npb(i) .. m_pb_rc(i) =l= (1-npb(i) )*M;
e2_npb(i) .. m_pb_ts(i) =l= (1-npb(i) )*M;

With these equations when npb(i) take the value of 1, m_pb_rc (i) and m_pb_ts (i) are 0.
I can not understand the idea of the problem but this may help you.
Best

M.Walde
User
Posts: 16
Joined: 6 months ago

### Re: Synthax of binary variables

I was a little bit caught in thinking about the model, so I didn't really explain, what it's for. Sorry for that.

The idea is, that the binary variable npb(i) is set to one, when the massflows m_pb_rc and m_pb_ts both equal to zero.
I need this for the equation of the inlet temperature. First the equation looked like this:

e_T_pi(i+1) .. T_pi(i+1) =e= (m_rc_pb(i+1)*T_ro + m_ts_pb(i+1)*T_to(i+1))/(m_rc_pb(i+1)+m_ts_pb(i+1));

Physically the equation should be no problem, but when the mass flows both equal to zero I get a mathematical problem, since there would be a division by zero. To avoid this I invented the binary variable npb and modified the equation to this:

e_T_pi(i+1) .. T_pi(i+1) =e= (m_rc_pb(i+1)*T_ro + m_ts_pb(i+1)*T_to(i+1))/(m_rc_pb(i+1)+m_ts_pb(i+1)+npb(i+1))+npb(i+1)*T_pi(i);

As you can see by adding the npb into the denominator should equal to 1 now, if the mass flows both equal to zero. I also added another term at the end, which sets the value to the temparature of the time step before, if the mass flows equal to zero, so the temperature term doesn't extend the set boundaries for the variable T_pi.

The equation should work like this, but as I told in the post above, the first equation for npb doesn't seem to work. So my question would be, if the synthax of the equation e_npb(i+1) .. npb(i+1) =e= (m_pb_rc(i+1) = 0 and m_pb_ts(i+1) = 0); really says, that the binary variable npb(i+1) is set to 1, if both mass flows equal to zero.

Hope you better understand, what I'm trying to do, now. Sorry again for my incomplete explanation of the problem.

Cheers
Max

Manassaldi
User
Posts: 65
Joined: 1 year ago
Location: Rosario - Argentina

### Re: Synthax of binary variables

I think this can work. I do not understand why you use (i + 1) instead of (i)

e_T_pi(i+1) .. T_pi(i+1)*(m_rc_pb(i+1)+m_ts_pb(i+1)) =e= (m_rc_pb(i+1)*T_ro + m_ts_pb(i+1)*T_to(i+1));

If you want to avoid the first value of i, you can use this equation.
e_T_pi(i)\$(ord(i) ne 1).. T_pi(i)*(m_rc_pb(i)+m_ts_pb(i)) =e= (m_rc_pb(i)*T_ro + m_ts_pb(i)*T_to(i));

Best!