'Concatenate 2 Enumerated type variable sets

enum sup;
sup=['a','b','c'];


enum sup2;
 sup2=['d','e','f'];

enum sup3;
sup3=sup++sup2;

I want to get an new enumerated type sup3 with all a,b,c,d,e,f.Is there any way in minizinc we can do this.



Solution 1:[1]

The short answer is no, this is currently not supported. The main issue with the concatenation of enumerated types comes from the fact we are not just concatenating two lists of things, but we are combining types. Take your example:

enum sup = {A, B, C};
enum sup2 = {D, E, F};
enum sup3 = sup ++ sup2;

When I now write E somewhere in an expression, I no longer know if it has type sup2 or sup3. As you might imagine, there is no guarantee that E would have the same value (for the solver) in the two enumerated types, so this can be a big problem.

To shine a glimmer of hope, the MiniZinc team has been working on a similar approach to make this possible (but not yet formally announced). Instead of your syntax, one would write:

enum X = {A, B, C};
enum Y = {D, E, F} ++ F(X);

The idea behind this is that F(X) now gives a constructor for the usage of X in Y. This means that if we see just A, we know it's of type X, but if we see F(A), then it's of type Y. Again, this is not yet possible, but will hopefully end up in the language soon.

Solution 2:[2]

More of a comment but here is my example of my need. When doing code coverage and FSM transition analysis I am forced to use exclusion to not analyze some transitions for the return_to_state, in the code below. If instead I could use concatenated types as shown, I would have more control over the tools reporting missing transitions.

type Read_states  is (ST1);
type Write_states  is (ST2, ST3, ST4);
type SPI_states  is (SPI_write);
type All_States is Read_states  & Write_states & SPI_states;

I could make return_to_state of type Write_states and FRAM_state of type All_states and then not have to put in exclusions in my FSM analysis.

Here is an illustrative example of the original problem

State transition diagram

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dekker1
Solution 2