Skip to main content

Hello AIMMS community,

 

I am trying to create a mapping file to read a JSON file using Data Exchange Library. The JSON file is structured as follows:

Data: {

"CaseTable"

        {

            "Case"1,

            "Specification""Specification 1"

  },

        {

            "Case"2,

            "Specification""Specification 2"

  }]’

 

"PriceTable": n

        {

            "Contract""X",

            "Specification""Specification 1",

            "Price"100

  },

        {

            "Contract""X",

            "Specification""Specification 2",

            "Price"200

  }]

}

As can be seen, the JSON file includes two tables: "CaseTable" and "PriceTable". I want to read price from PriceTable and assign it to the Price_Parameter(i_case, i_contract) which is indexed over “Case” and “Contract”. For example the value of this parameter should be 200 if the Case 2 and Contract “X” is selected:

Price_Parameter(2, X)=200.

Case 2 is related to the Specification 2 (according to the CaseTable) and the price for Specification 2 is 200 (according to the PriceTable).

 

Could you please let me know how can I create a mapping file to read this parameter? 

 

 

Hi @Sajad.Karimi 

If I understand you correctly, the price table vector in the json file could also easily contain 6 objects, holding the prices for case 1 and 2, and contracts X, Y and Z. 

I'm a little confused why you want to refer to cases by number in your model, while the prices are in the price table refer to cases by specification. For AIMMS it then makes much more sense to also refer to cases by their specification labels, instead of by number. 

For that case, the mapping becomes extremely straightforward: 

<AimmsJSONMapping>

    <ObjectMapping>

        <ObjectMapping name="Data">

            <ArrayMapping name="CaseTable">

                <ObjectMapping>

                    <ValueMapping name="Specification" binds-to="case"/>

                    <ValueMapping name="Case" maps-to="CaseNumber(case)"/>

                </ObjectMapping>

            </ArrayMapping>

            <ArrayMapping name="PriceTable">

                <ObjectMapping>

                    <ValueMapping name="Specification" binds-to="case"/>

                    <ValueMapping name="Contract" binds-to="contract"/>

                    <ValueMapping name="Price" maps-to="ContractPrice(case,contract)"/>

                </ObjectMapping>

            </ArrayMapping>

        </ObjectMapping>

    </ObjectMapping>

</AimmsJSONMapping>

 

The attached model brings it all together. 

If you are really after numbered cases, then I would just read in the prices using a separate index, filled by employing an iterative-binds-to attribute in the mapping file, and map the contract prices obtained in this way onto case numbers by comparing the specification value associated with all prices with the specification value of the cases inside the model. There is no way to do that on-the-fly specification-to-case-number mapping directly using the DEX library.

 


Reply


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

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