Sets for Configuration

Some sets in AIMMS are not data-driven, but represent configuration choices or application logic switches, for example:

  • steps/modes in a solution algorithm (e.g., warm start on/off, leasing allowed on/off),

  • which dataset or view to present in the UI.

If you hard-code element names like ‘boat’ throughout procedures and pages, renaming becomes tedious and causes noisy Git diffs across many files.

Tip

Consider using element parameters as named constants for configuration options.

Represent each configuration option once as an element parameter constant, and compare against that constant everywhere else. Then renaming an option requires changing only a single definition.

Example: Transport Mode

Using AIMMS’ sets and element parameters, there is an easy way to enable changing the names of elements in sets for configuration.

This is illustrated in the accompanying example.

Step 1 - Declare the Configuration Set:

First, declare the set s_config that will hold the configuration options:

1Set s_config {
2    Index: i_config;
3}

Step 2 - Declare the “Named Constants” for Each Option:

Next, declare an element parameter for each configuration option:

1ElementParameter ep_configCar {
2    Range: s_config;
3    Definition: 'car';
4}
5ElementParameter ep_configBoat {
6    Range: s_config;
7    Definition: 'boat';
8}

Step 3 - Define the Set from the Constants:

And then add the following definition to s_config:

1Definition: {
2    { ep_configCar, ep_configBoat }
3}

Compile it all and show data of s_config:

../../_images/s_config.png

Step 4 - Create an Element Parameter to Hold the Choice:

Next, we are going to introduce the element parameter ep_transportVehicle:

1ElementParameter ep_transportVehicle {
2    Range: s_config;
3    InitialData: '';
4}

Note

The initial data is assigned at the beginning; and '' denotes the empty element. This indicates that the transport vehicle is not selected.

Such an element parameter will be used throughout the application, and can take on values 'car' and 'boat'.

We will use it in code like:

1if ep_transportVehicle = '' then
2    ep_transportVehicle := ep_configCar ;
3endif ;
4if ep_transportVehicle = ep_configBoat then
5    display "Going over water" ;
6else
7    display "Going via the highway" ;
8endif ;

On line 4, the element parameter is not compared directly against 'boat' but against the element parameter. By comparing ep_transportVehicle to ep_configBoat instead of the string 'boat', your code becomes refactor-safe. If you rename 'boat' to 'vessel', you only update one definition, and the logic in your procedures remains valid and unchanged in Git.