How to Map String Name to AIMMS Variable in a Procedure similar to globals()["x"] in Python
Hi,
Here is the set that I have and is a subset of AllVariables with the index i_DistWeightVar. Note that the variables in this set have exactly the same indices and in the same order, (i.e., i_period, i_Terminal, i_Source, i_Product, i_Fleet, i_Zone, i_Customer).
Here is the parameter that I create that only differs with his first index than the variables in the set above.
I am hoping to be able to make assignments by using a function like StringToVariable given below:
Anything you can give me to use on the RHS of this assignment?
Best,
Gorkem
Page 1 / 1
I am not sure if this is possible with just a simple assignment operation.
For sure it is possible in AIMMS, I have done it multiple times, but then I use the model edit functions in aimms: I write a procedure that creates a dynamic procedure (that has all of the explicit assignment statements) and then executes this dynamic procedure.
Hello @gorkem
I made an example to show what could be your approach. You can make it a lot more generic depending on your needs, but I think it illustrate the idea from @gdiepen (which I agree is the way to do this).
Hence, we want to copy the contents of param to param2, that has an index (isubset1) that is related to identifiers.
I build the following procedure to make this copy:
! we need to check if the runtime already exists and delete it if so _ep_library := StringToElement(AllIdentifiers,"CopyVariable",0); if _ep_library then me::Delete(_ep_library); endif;
And I had to add a dummy procedure that does nothing in order to use apply:
Procedure dummy;
This is what my explorer looks like:
My procedure uses the AIMMS model edit functions to create a procedure dynamically that will have a body based on the assignment of all elements from subset1 to param2.
You can even see the generated code after you run it:
Which is what I imagine you want.
If I added more element to isubset1, it would also become new lines in the procedure, like this:
And after running and applying, I do get the param2 with all the different values from all the parameters.
I attached the ams file (as a zip).
Hope it helps!
Reply
Sign up
Already have an account? Login Please use your business or academic e-mail address to register