Error - A definition cannot as a side effect change another identifier

  • 18 February 2020
  • 2 replies

I’m trying to update our AIMMS model to the latest software version as it is long overdue - we were previously using version 4.1 and now want to update to 4.71.

I’m very new to the AIMMS language so am being stumped by the following error message that appears when I open the model in 4.71:

 “A definition cannot as a side effect change another identifier. The third argument of intrinsic function “StringToElement” should be set to 0 explicitly.”


The piece of code that relates to this error message is

{ (tpehis,pe) | FormatString("%e",pe) = StringToElement(Periods,SubString(FormatString("%e",tpehis),1,4) + "-" + SubString(FormatString("%e",tpehis),5,6) ,1)};


From what I can pick up from the manual, in the StringToElement function, a value of 1 creates the element.

This piece of code works perfectly fine in the 4.1 version of AIMMS.

Why is this error occurring and how can I fix this?




Best answer by Richard Stegeman 20 February 2020, 12:10

View original

2 replies

Userlevel 5
Badge +2

Hi, @Stephen_Powick.

Why is this error occurring 

In your declaration you are changing another identifier (set Periods) by adding elements to it (StringToElement:1). It looks like aimms doesn’t allow it anymore.


how can I fix this

Idea 1:

You can use a procedure to populate this set instead of a definition.


Idea 2:

Maybe you can add a definition to the set Periods instead:

StringToElement(Periods,SubString(FormatString("%e",tpehis),1,4) + "-" + SubString(FormatString("%e",tpehis),5,6) ,1)

and change your code to this:

{ (pe) | exists(PERI | (FormatString("%e",pe) = PERI)) };

‘PERI’ is the index of set Periods.

Userlevel 3
Badge +3

This is indeed no longer supported in AIMMS. A definition of an identifier is not allowed to change any other identifier. In earlier AIMMS versions the error was not given while it should, and thus the result could be undefined. 

Just wondering why the definition needs the StringToElement.

Is the following not doing the same?

{ (tpehis,pe) | FormatString("%e",pe) = SubString(FormatString("%e",tpehis),1,4) + "-" + SubString(FormatString("%e",tpehis),5,6) ,1)};


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator