In GAMS, I am reading in two sets from data via $gdxIn and $load. But I want to do a…
- User
In GAMS, I am reading in two sets from data via load. But I want to do a one-to-one-mapping between the two sets. The two sets are actually supposed to be mapped to each other. For example "Port 1" and "1" are the same, where "Port 1" is in the first set and "1" is in the second set. In examples given the pairing
pair(i,j)is explicitly provided, but I would like to create the pairing without needing to write it out. How can I achieve this? - Assistant
In GAMS, you can solve this problem using the
$mapoperator. The$mapoperator allows you to perform a one-to-one mapping between two sets of indices. To achieve the desired one-to-one mapping between the two sets, you can use the following syntax:$map(i,j) = ...This syntax sets up a mapping between the indices
ifrom the first set andjfrom the second set. Replace...with the desired mapping.For example, if you have two sets:
i = 1 2 3 j = a b cAnd you want to create a one-to-one mapping between them, you can use the
$mapoperator as follows:$map(i,j) = (i,j)This will set up the following mapping:
i = 1 2 3 j = a b cNow, when you use
$gdxInand$load, the indices will be automatically mapped according to the one-to-one mapping you defined.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.