Concatenating arrays or sets

Skip to first unread message

Carl Örnberg

Nov 9, 2023, 6:14:02 PM11/9/23
to MiniZinc
I have two questions for a beginner of minizinc:

 1. if we have A =  [1,2,3,3,4,5,6]; B = [2,3,1,4,5,6,4]; How do I create 7x2 matrix in minizinc that has A has first column and B as second column? 

2. How do I make an array of length 6 (nbr of unique entries)  which has sets representing the vertices from each node from A and B in a undirected graph? for example I seek an array like [{2,1,3},{3},{1,4,2},{4,5,6},{5,6},{4}] 

I have trouble with the syntax...

Jip Dekker

Nov 9, 2023, 6:23:52 PM11/9/23
to MiniZinc
I can answer your first question. You can write an array comprehension that transposes and concatenates the columns:
any: A = [1,2,3,3,4,5,6];
any: B = [2,3,1,4,5,6,4];
any: C ::output = [(i,j): if j == 1 then A[i] else B[i] endif | i in 1..7, j in 1..2];

I'm not sure about how the arrays represent undirected graphs, and cannot relate the example output and input, so hopefully someone else can fill in those details.

Mohamed H. Ibrahim

Nov 23, 2023, 7:49:11 PM11/23/23
to MiniZinc
For the second question, I think you can use an adjacency matrix with zeros to represent no connection.
Reply all
Reply to author
0 new messages