Hi @Lawrence, you can write the definition of StateofCharge as follows:

`if ( t = '01' ) then`

if (Charging_Power_kW(t) + SoCMin > SoCMax) then

SocMax

else

Charging_Power_kW(t) + SoCMin

endif

elseif (Energy_Difference_kW(t) > 0) then

if (StateofCharge(t-1) + Charging_Power_kW(t) > SoCMax) then

SoCMax

else

StateofCharge(t-1) + Charging_Power_kW(t)

endif

elseif (Energy_Difference_kW(t) < 0) then

if (StateofCharge(t-1) - SoCMin > Discharging_Power_kW(t)) then

StateofCharge(t-1) - SoCMin

else

SoCMin

endif

endif;

Or even better, use First(t) instead of ‘01’. That way you do not have to change this defintion if for some reason the first element changes (e.g., from ‘01’ to ‘1’ or ‘001’).

You should use single quotes if you want to refer to set elements: P(‘2’,’4’).

Hi @Lawrence. The second conditional statement for StateofCharge(t) at t = 2,….24 is also handled in my answer. Note that the definition contains three blocks. The first block

`if ( t = '01' ) then`

if (Charging_Power_kW(t) + SoCMin > SoCMax) then

SocMax

else

Charging_Power_kW(t) + SoCMin

endif

handles the situation for t=01. For *t* unequal to ‘01’ the other two blocks will be used:

`elseif (Energy_Difference_kW(t) > 0) then`

if (StateofCharge(t-1) + Charging_Power_kW(t) > SoCMax) then

SoCMax

else

StateofCharge(t-1) + Charging_Power_kW(t)

endif

elseif (Energy_Difference_kW(t) < 0) then

if (StateofCharge(t-1) - SoCMin > Discharging_Power_kW(t)) then

StateofCharge(t-1) - SoCMin

else

SoCMin

endif

endif;

Dear AIMMS Team,

Trust this meets you well? Kindly assist on the problem explained below and find attached the AIMMS file I am working with.

I have a variable StateofCharge(t) in which t is 1 to 24.

I want to place StateofCharge(t) at t = 1 or StateofCharge(01) on the conditional statement below.

*if ( (Charging_Power_kW(01) + SoCMin) > SoCMax) then*

SocMax

else

*Charging_Power_kW(01) + SoCMin*

endif;

**Note: Charging_Power_kW(01) is put as the value of variable Charging_Power_kW(t) at t=1**

While StateofCharge(t) at t = 2,….24 should have the conditional statement below. The index t in the statement applies only from t = 2,….24.

*If Energy_Difference_kW(t) > 0 then*

if (StateofCharge(t-1) + Charging_Power_kW(t)) > SoCMax

SoCMax

else

StateofCharge(t-1) + Charging_Power_kW(t)

elseif (Energy_Difference_kW(t)) < 0 then

if (StateofCharge(t-1) - SoCMin) > Discharging_Power_kW(t)

else

SoCMin

endif;

Also, if I have a parameter/variable, P(t), t=1,...24, how can I extract a cell? For example: P(5) or a parameter/variable with a double index P(t, k), t=1,..24 and k=1,...5, how can I write the value in cell P(2,4)?

Thank you.

Kind regards.

Hello @Marcel Hunting,

Thank you for your response. Most of the questions have been answered from the program you wrote.

However, there is still an issue I am trying to address.

I want the first conditional statement below to hold only for StateofCharge(t) at t = 1 only

*if ( (Charging_Power_kW(01) + SoCMin) > SoCMax) then*

SocMax

else

*Charging_Power_kW(01) + SoCMin*

endif;

*Note: This has been answered from your reply. *

……………………………………………………………………………………………………………………

So here is the issue….

However, I want the second conditional statement below to hold only for StateofCharge(t) at t = 2,….24 (or at t= 2 to the end) only

*If Energy_Difference_kW(t) > 0 then*

if (StateofCharge(t-1) + Charging_Power_kW(t)) > SoCMax

SoCMax

else

StateofCharge(t-1) + Charging_Power_kW(t)

elseif (Energy_Difference_kW(t)) < 0 then

if (StateofCharge(t-1) - SoCMin) > Discharging_Power_kW(t)

else

SoCMin

endif;

Thank you once again.