Let me first start with one remark: The openAPI client generation is one awesome addition!!!
With a bit of a simple workaround I was able to create relatively easy an AIMMS library that was able to import a rather large and complex JSON file that had a quite deep nested structure in it.
Now that I have the data in an AIMMS library, I know am trying to write the code that parses the information from the library into the actual AIMMS sets/parameters that I will use in a model.
For this part, one of the problems of the nesting is that the generated library works on lots of subsets of integers that restart counting from 0 every time
In the following example (that hopefully illustrates it enough)
Locations property (contains list of locations):
- Element 1 in locations list (will map to i_locations=1 in aimms library)
- LocationName: Location A
- Products (contains list of products)
- Element 1 in productions list (contains dictionary of name/color, maps to locations::product::i_product=1 in aimms library)
- name: product1 (defined over locations and product index in aimms library)
- color: green (defined over locations and product index in aimms library)
- Element 2 in productions list (contains dictionary of name/color, maps to i_product=2 in aimms library)
- Element 1 in productions list (contains dictionary of name/color, maps to locations::product::i_product=1 in aimms library)
- Element 2 in locations list (will map to i_locations=2 in aimms library)
- locationname: location B
- Products (contains list of products)
- Element 1 in productions list (maps to locations::product::i_product=1 in aimms library)
- name: product2 ((defined over locations and product index in aimms library)
- color: green (defined over locations and product index in aimms library)
- Element 1 in productions list (maps to locations::product::i_product=1 in aimms library)
My first approach was to go step by step deeper and keep on creating elements in my main model set sProducts. When doing this and creating mappings, I will always have to keep the reference to both indices locations and product because the product index just keeps on resetting to 1 for every new location.
In my particular usecase, I would rather have the index counters to never reset, but just always keep on counting. That would allow me to create easy 1 to 1 mappings from json id number to aimms set elements. That means I would basically just create a set in my main model for locations and one for products and use stringtoelement with the name/locationname property of the product and location respectively. Any duplicates (e.g. if Product 5 occurs both in location A and location will automatically be mapped from unique json array ids to the same main model product set elements (which is correct, name property is the unique identifier for the product)
I have found that if I modify the mapping file and empty the interactive-reset attribute for the ArrayMapping nodes in the generated mapping XML file, it looks like this does exactly what I need it to do.
Since i have not used the DEX library and mappings that much yet, would like to know if my above reasoning is correct or whether I am making a big mistake in my logic somewhere.