Generator Engine Utilities

 

 

Adjust Precision :

 

This function is used to round the numbers generated by the engine to the specified number of decimals. Truncate remove only keeps the requested number of decimals after the integer part. Note that no decimal is created if fewer decimals are present in the number. The numbers can be either rounded up or down according to the situation.

 

Partition :

 

The partition function is the most used function of the generator. Thanks to the services of partition, the generated systems will respect all of the constraints of LMP systems. Basically, partition is used to split a x number (integer or double) in n parts (xi). The sum of all parts must be equal to n.


Here is the algorithm used for the partition method splitting an real number into n real parts.

 

PARTITION (n, p)

(L shall contain the chosen numbers)

L nil

(sum will contain the sum of all the numbers)

sum 0

(we shall generate p different numbers)

FOR i 1 TO p

(A random number is put into L and the sum is updated)

L[i] random( ]0, n[ )

sum sum + L[i]

END FOR

(We shall adjust these numbers in order for their sum to be equal to n)

FOR ii TO p

L[i] L[i] / sum * n

END FOR

 

RETURN X

END

 

We first generate several random numbers between 0 and n. We then calculate their sum and divide each of them by their sum. Thus, every number will be included between 0 and 1. By multiplying these coefficients by n, we are sure their sum is n. This algorithm may seem somewhat complicated, but has the advantage of generating random numbers that don’t depend on previously generated numbers. This algorithm is also reasonably efficient with a Θ(p) efficiency.

Partition Integer :

 

A second version of partition is needed in order to split integer numbers. The simplest solution is to round all the numbers returned by the original version of partition. However, the problem is that if we round all the numbers down to the nearest integer, their sum is no longer n. If we round them up, then their sum is greater than n. Since the second solution is clearly more problematic, we will round them down, then distribute the missing integers.

 

PARTITIONINTEGER (n, p)

 

(Calling the original Partition algorthm)

LPartition(n, p)

(We will calculate the number of integer left to distribute)

remainn

(We shall round each real number to the nearest smaller integer)

FOR i1 TO p

remainremainL[i]

FIN FOR

(remain contains the number of integers left to distribute)

WHILE ( remain > 0 )

rrandom( [1, p] )

L[r]L[r] + 1

remainremain – 1

END WHILE

 

RETURN L

END