Hi,
Let’s say I have a set consisting of 5 elements such that: Set1 = {‘A’,‘B’,‘C’,‘D’,‘E’}.
How can I move some elements to the end of the set. For example:
Set1 = {‘A’, ‘D’,’E’,’B’,’C’}
Thanks!
Hi,
Let’s say I have a set consisting of 5 elements such that: Set1 = {‘A’,‘B’,‘C’,‘D’,‘E’}.
How can I move some elements to the end of the set. For example:
Set1 = {‘A’, ‘D’,’E’,’B’,’C’}
Thanks!
In AIMMS, this transformation can be achieved by creating a new set where the order of elements is specified dynamically. A structured approach is as follows:
Define the Original Set: Create the initial set (e.g., Set1
) and populate it with the predefined elements: {'A', 'B', 'C', 'D', 'E'}
.
Create a Parameter: Define a parameter to represent the new order. Assign indices to rearrange the elements. For instance, define a parameter p_NewOrder(i)
where i
represents the elements of Set1
. Assign values corresponding to the target order: {'A': 1, 'D': 2, 'E': 3, 'B': 4, 'C': 5}
.
Sort Dynamically: Utilize the indexing capabilities to sort the set dynamically based on the parameter values. AIMMS allows reorganization of sets using such logical parameters.
Thank you so much for your detailed response.
I got a bit lost on the third step. Would you mind sharing the code you would use to do this on your end?
Thanks a lot.
Below is a step-by-step example with some code to implement!
Define the original set:
Set Set1 {
Index : i;
Members : {'A', 'B', 'C', 'D', 'E'};
}
Create a parameter to define the sorting order:
Parameter p_NewOrder {
IndexDomain : i;
Definition : Data { 'A': 1, 'D': 2, 'E': 3, 'B': 4, 'C': 5 };
}
Define a new set with the OrderBy
attribute:
Set OrderedSet1 {
SubsetOf : Set1;
OrderBy : p_NewOrder(i);
}
By executing this code, OrderedSet1
will be automatically sorted based on the values defined in p_NewOrder
.
Already have an account? Login
Please use your business or academic e-mail address to register
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Didn't find what you were looking for? Try searching on our documentation pages: