Solved

wrong rank in Set element


Badge +4

I use AXLL::ReadSet to read the set element from Excel:

And in excel the rank is 

 

However, the data in the set looks like this (the data is in a wrong ranking):

Sometimes, it ranks like this:

Even though I define the elements directly:

Still, the data looks like this:

I have ever encountered this problem before, and I was told to define the set as a subset of Integers and use Order by. However, I hope the data in the set is treated as element rather than value. So for a set Time := {1,3,5}, Time(1+1) := 3.

What wrong with this?

icon

Best answer by Chris Kuip 17 May 2024, 08:42

View original

3 replies

Userlevel 5
Badge +7

I am assuming below that you want a subset of integers, and be able to control the size easily, whereby this subset follows the same ordering as the set integers.


To achieve an ordered subset of integers of flexible size, you can declare it as follows:

 

Set Time {
    SubsetOf: Integers;
    Index: t;
    Definition: {
        { 1 .. p_noPeriods }
    }
}

 

See also the enclosed project: 


When you open this project, and show the data, it will show:
 

The set time, where number of periods is 5

as the initial value of the parameter p_noPeriods is 5.
 

Subsequently, you can change the parameter p_noPeriods to a different value, say 25.  The data page will then show:

 

The set time, where number of periods is 25.

 

Does this mechanism provide you with the set time as you need it?

Userlevel 5
Badge +7

Hello Chunyang,

To understand the ordening of elements in an AIMMS set, 
it helps to know how AIMMS constructs the ordening.

A root set is a one-dimensional set that is not a sub set of another set.
AIMMS associates with each root set an element space.
An element space maps each element to an element number.
Whenever a new element is added to a root set, it gets the next available element number in the element space.
Removing an element from a root set, will not result in removing that element from the element space; unless you are using CleanDepedents, 
see also https://documentation.aimms.com/language-reference/data-communication-components/data-initialization-verification-and-control/data-control.html

The elements in a set are presented by default with increasing element numbers; 
this may not coincide with the presentation you may have expected as you clearly demonstrate.
You can override the order of presentation via the order by attribute, 
see https://documentation.aimms.com/language-reference/non-procedural-language-components/set-declaration/set-declaration-and-attributes.html#set-declaration-and-attributes

A special root set is the predeclared set Integers. 
The element space associated with this root set does not maintain an mapping stored in memory, 
but rather a function that maps each element to an integer.
Thus the set Integers, and all its subsets, present their elements by default in increasing order.

During one session while developing an AIMMS project; elements may be added to a root set in an unexpected order,
and during that same session this unexpected order will be kept. 
This may explain the behavior you reported.

That is why, during testing, I always start AIMMS sessions afresh, such that I know that behaviour observed, can be reproduced.

To fill the set Time with elements 1 to 24, presented in increasing order, I attached two small AIMMS projects to this reply.

In the first project, ElementRange, the AIMMS function ElementRange is used, see https://documentation.aimms.com/functionreference/elementary-computational-operations/set-related-functions/elementrange.html
In this project, the set Time is defined as ElementRange(1,24,fill:0)

In the second project, AXLLRead, the axll::readset procedure is used. 

Does the above help you understand ordering and enable you to work with AIMMS' set ordenings?

With kind regards,

Chris.

Badge +4

Hello Chunyang,

To understand the ordening of elements in an AIMMS set, 
it helps to know how AIMMS constructs the ordening.

A root set is a one-dimensional set that is not a sub set of another set.
AIMMS associates with each root set an element space.
An element space maps each element to an element number.
Whenever a new element is added to a root set, it gets the next available element number in the element space.
Removing an element from a root set, will not result in removing that element from the element space; unless you are using CleanDepedents, 
see also https://documentation.aimms.com/language-reference/data-communication-components/data-initialization-verification-and-control/data-control.html

The elements in a set are presented by default with increasing element numbers; 
this may not coincide with the presentation you may have expected as you clearly demonstrate.
You can override the order of presentation via the order by attribute, 
see https://documentation.aimms.com/language-reference/non-procedural-language-components/set-declaration/set-declaration-and-attributes.html#set-declaration-and-attributes

A special root set is the predeclared set Integers. 
The element space associated with this root set does not maintain an mapping stored in memory, 
but rather a function that maps each element to an integer.
Thus the set Integers, and all its subsets, present their elements by default in increasing order.

During one session while developing an AIMMS project; elements may be added to a root set in an unexpected order,
and during that same session this unexpected order will be kept. 
This may explain the behavior you reported.

That is why, during testing, I always start AIMMS sessions afresh, such that I know that behaviour observed, can be reproduced.

To fill the set Time with elements 1 to 24, presented in increasing order, I attached two small AIMMS projects to this reply.

In the first project, ElementRange, the AIMMS function ElementRange is used, see https://documentation.aimms.com/functionreference/elementary-computational-operations/set-related-functions/elementrange.html
In this project, the set Time is defined as ElementRange(1,24,fill:0)

In the second project, AXLLRead, the axll::readset procedure is used. 

Does the above help you understand ordering and enable you to work with AIMMS' set ordenings?

With kind regards,

Chris.

Hi Chris,

Thank you so much for this detailed reply! I definitely understand more about how the set elements are tackled in AIMMS now!

To make sure I totally understand them correctly, I want to replicate your expression further with my words:

So for a root set, the element number is the reference label for each element. The elements of the set will be given (mapped to) a reference label (element number) one by one and the reference label is given in increasing way.

However, sometimes, the elemnts of the set are not given a reference label in order or the elemnts are not saved into the space the same order as they are. This might happen during the whole session. So, in order to avoid this unexpected case, order by attribute is suggested to force the order of the elements.

Hope I understand you correctly.

I have also downloaded the two projects you attached. Unfortunately, I tried to use the two ways as you showed me, and use the order by attribute, the wrong rank can still happen… Please see the order I got in the pictures.

By afresh, do you mean close the software and open it again? I also tried and like you said, the order can change. Combined with order by attribute, it showed as the second picture, I was given an order of 1, 10, 11 …...

 

As this is the time set, it has to be in correct order so the whole optimization can work. So the way I am finding now is using Subset of Integers and give definition ElementRange(1,24,fill:0) directly. It works, however, it forced me to predefine the elements in advance rather than interacting with the Excel, which is a little bit annoying.

Reply


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

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