Single Associations

We need to calculate the number of instances to generate for each element. In other words, we have a number of associated classes. How do we find out how many instances to generate for each one, with each generation? The next problem is, having generated instances, how do we correlate them.

This figure shows a simple problem: two associated classes:

Figure 1: Two Associated Classes

Their association can be written as A[0..2]-B[1..3], meaning:

  • Each instance of A can reference anywhere from 1 to 3 instances of B, and
  • Each instance of B can reference anywhere from 0 to 2 instances of A.

Now, how many instances of each class should we generate with each generation?

One answer is: calculate a value (i.e. the current cardinality) for each multiplicity, and generate that number of instances of each class. For this example, we'll use the maximum multiplicity, A=2 and B=3. So we'll generate two instances of A and three of B. Each value of A is correlated with all 3 values of B, and each B is correlated with all 2 of A. The total number of correlations is card(A)*card(B)=2*3=6. If the indexes of A and B are integer-valued and zero-based, then the correlations are:

    A  B
    ----
    0  0
    0  1
    0  2
    1  0
    1  1
    1  2