0

Is there a way to instantiate multiple processes obtained from the same Template in Uppaal?

For example currently I write (in the System declarations file):

// Template instantiations
P1 = Template(var1);
P2 = Template(var2);
P3 = Template(var3);
P4 = Template(var4);
// Processes into the system
system P1, P2, P3, P4;

But I would like to obtain a more compact form to do so (maybe into an array?) since I actually have to create 50 processes (not just 4). How can I do that?

Note: the variables are of type int[0,1] and I currently define them in the Declarations file as follows:

int[0,1] var1, var2, var3, var4;
Robb1
  • 4,587
  • 6
  • 31
  • 60

1 Answers1

1

Yes, through partial instantiation, here is an example:

const int N=50; // number of items
typedef int[1,N] id_t; // bounded integer type with values [1..N]
int[0,1] var[id_t]; // array of bounded integers indexed by id_t range [1..N]
P(const id_t id) = Template(var[id]); // template P with argument id
system P; // instantiate P(1)..P(N) by filling the constant values from id_t range

On the last line Uppaal will auto-fill the constant integer arguments resulting in N processes.

Note that bool can be used instead of int[0,1].

mariusm
  • 1,483
  • 1
  • 11
  • 26
  • Thanks for your answer! Can you please comment the code to help my understanding? Also, I added in the OP a specification about the type of variables I'm using (and I think your answer does not take it in consideration, but I'm really new to Uppaal so I may be wrong!) Thanks again :) – Robb1 Jul 16 '21 at 14:27
  • 1
    @Robb1 partial template instantiation is an advanced feature. Also the treatment of ranged integer types is an extra feature (which is not in C), so it may look confusing, but I do recommend using bounded integer types as much as possible just to avoid indexing bugs. For example, one can write a loops just like logic quantifiers: `for(i:id_t) { /* do something with i */ }`, more: `sum(i:id_t) var[i]`, `forall(i:id_t) var[i]==1`, `exists(i:id_t) var[i]==1` – mariusm Jul 17 '21 at 16:26