### logical condition with equation definitions and variables

Posted:

**Mon Mar 12, 2018 2:05 pm**Hi guys,

I got another question about logical conditions for equations. As I saw in the documentation it is illegal to use if-else operations for the definition of equations.

That's why I wanted to use the $ operator to put logical conditions into account.

This is the important code:

sets i time steps /0*720/;

variables

m_rc_ts(i) mass flow from receiver to thermal energy storage

m_pb_ts(i) mass flow from power block to thermal energy storage

dec(i) decision variable stating the mode of storage operation;

equations

e_charge setting decision variable for charging tank operation mode

e_discharge settings decision variable for discharging tank operation mode

e_no_use setting decision variable for no use tank operation mode

e_m_rc_ts_restrict restrict the mass flow from receiver for discharging mode

e_m_pb_ts_restrict restrict the mass flow from power block for charging mode

e_T_ti_charge equ for inlet temperature of thermal energy storage for charging mode

e_T_ti_discharge equ for inlet temperature of thermal energy storage for discharging mode;

e_charge(i+1) .. dec(i+1)$(m_rc_ts(i+1) > 0) =e= 1;

e_discharge(i+1) .. dec(i+1)$(m_pb_ts(i+1)) =e= 2;

e_no_use(i+1) .. dec(i+1)$(m_rc_ts(i+1) = 0 and m_pb_ts(i+1) = 0) =e= dec(i);

e_m_rc_ts_restrict(i+1) .. m_rc_ts(i+1)$(dec(i+1) = 2) =e= 0;

e_m_pb_ts_restrict(i+1) .. m_pb_ts(i+1)$(dec(i+1) = 1) =e= 0;

e_T_ti_charge(nfirst,i+1) .. T_fl(nfirst,i+1)$(dec(i+1)= 1) =e= T_ro;

e_T_ti_discharge(nfirst,i+1) .. T_fl(nfirst,i+1)$(dec(i+1)= 2) =e= T_po(i+1);

When I run the model I get the compilation error 53 and 256:

*** Error 53 in 180312_decision_model.gms

Endogenous $ operation not allowed

*** Error 256 in 180312_decision_model.gms

Error(s) in analyzing solve statement. More detail appears

Below the solve statement above

Out of research I found some people saying, that you can't use variables with logical conditions, and that's why this error pops up.

My question would be, how to use equations and variables with logical conditions, since this is an essential part of my model.

For better understanding: The model is about a thermal energy storage. The storage can be run in 3 stages: charge, discharge and no use. For charge and discharge mode the inlet temperature is different and the massflow enter from a different direction. That's why I need to involve logical conditions.

I hope, that you guys understand my problem. I would be glad, if you could give me some tips about it.

Anyway thanks in advance!

Cheers

Max

I got another question about logical conditions for equations. As I saw in the documentation it is illegal to use if-else operations for the definition of equations.

That's why I wanted to use the $ operator to put logical conditions into account.

This is the important code:

sets i time steps /0*720/;

variables

m_rc_ts(i) mass flow from receiver to thermal energy storage

m_pb_ts(i) mass flow from power block to thermal energy storage

dec(i) decision variable stating the mode of storage operation;

equations

e_charge setting decision variable for charging tank operation mode

e_discharge settings decision variable for discharging tank operation mode

e_no_use setting decision variable for no use tank operation mode

e_m_rc_ts_restrict restrict the mass flow from receiver for discharging mode

e_m_pb_ts_restrict restrict the mass flow from power block for charging mode

e_T_ti_charge equ for inlet temperature of thermal energy storage for charging mode

e_T_ti_discharge equ for inlet temperature of thermal energy storage for discharging mode;

e_charge(i+1) .. dec(i+1)$(m_rc_ts(i+1) > 0) =e= 1;

e_discharge(i+1) .. dec(i+1)$(m_pb_ts(i+1)) =e= 2;

e_no_use(i+1) .. dec(i+1)$(m_rc_ts(i+1) = 0 and m_pb_ts(i+1) = 0) =e= dec(i);

e_m_rc_ts_restrict(i+1) .. m_rc_ts(i+1)$(dec(i+1) = 2) =e= 0;

e_m_pb_ts_restrict(i+1) .. m_pb_ts(i+1)$(dec(i+1) = 1) =e= 0;

e_T_ti_charge(nfirst,i+1) .. T_fl(nfirst,i+1)$(dec(i+1)= 1) =e= T_ro;

e_T_ti_discharge(nfirst,i+1) .. T_fl(nfirst,i+1)$(dec(i+1)= 2) =e= T_po(i+1);

When I run the model I get the compilation error 53 and 256:

*** Error 53 in 180312_decision_model.gms

Endogenous $ operation not allowed

*** Error 256 in 180312_decision_model.gms

Error(s) in analyzing solve statement. More detail appears

Below the solve statement above

Out of research I found some people saying, that you can't use variables with logical conditions, and that's why this error pops up.

My question would be, how to use equations and variables with logical conditions, since this is an essential part of my model.

For better understanding: The model is about a thermal energy storage. The storage can be run in 3 stages: charge, discharge and no use. For charge and discharge mode the inlet temperature is different and the massflow enter from a different direction. That's why I need to involve logical conditions.

I hope, that you guys understand my problem. I would be glad, if you could give me some tips about it.

Anyway thanks in advance!

Cheers

Max