Solved

Question about index scope not being specified

  • 21 November 2023
  • 2 replies
  • 37 views

Userlevel 5
Badge +7

Hi all,

 

I am aware that AIMMS will use all of the indices specified on the Left Hand Side of an assignment statement to loop over all combinations.

When trying out something in a test project I am working on, I wanted to use this logic, but found that this does not work anymore when you are using formatstring on the LHS. Was wondering if this is on purpose or whether this behavior should be possible

 

Example that works:

spStringParameter( StringToElement(sTargetSet, iSource, 1) ) := formatstring("Test :: element %e", iSource) ; 
 

Example that does not work:

spStringParameter( StringToElement(sTargetSet, formatstring("%e", iSource), 1) :=  formatstring("Test :: element %e", iSource) ; 

 

When running the second one, I get an error indicating that the scope of iSource has not been specified. The above is a minimal example of the problem, not completely the same as what I had. I can work around it by either putting the statement in an explicit for-loop, or create the mapping isource → itarget in an intermediate mapping parameter. Was just wondering if it should work or not 😉

icon

Best answer by gabiservidone 14 March 2024, 20:35

View original

2 replies

Userlevel 5
Badge +6

Hey @gdiepen, I’ve been testing this. I got to the same workaround as you. 

test(i_producer) := formatstring("%e", i_producer);
spStringParameter( StringToElement(s_producers, test(i_producer) , 1)):= formatstring("Test :: element %e", i_producer) ;

In my point of view, using FormatString directly should work too. Not sure it is a good idea thinking of best practices of coding, but it should work. Let me talk to backend team, and I’ll let you know. 

Userlevel 3
Badge +3

After some investigations I found that there is a combination of things that make that this is not working:

  1. There is a really simple syntax error in the statement. There is a missing ‘)’ at the LHS of the assignment (look closely 😅). The new compiler in AIMMS is noticing this, but is not showing the error, because in such a situation it leaves the statement to be handled by the old compiler. Why the old compiler does not see this missing ‘)’ is not clear to me, nor what kind of statement it is trying to create as a result.
  2. Unfortunately, when you do add the missing ‘)’, the new compiler will pick up the statement but then give an error that there is no scope for ‘i_producer’. Having the running indices so deeply nested in the LHS is rather difficult for the compiler to deal with. But I do think that this is a bug in the compiler.

One workaround for the latter problem is to place the assignment in a FOR loop.

Reply


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

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