Overview

This article shows the design pattern of using linked generators with the MultiWeightGen Generator to control the percentage of data generated from multiple lists.


Example

Simulate the use of rental cars sales by category on a weighted percentage basis.

  • There are three categories of cars being rented:
    • Luxury
    • Midsize
    • Economy
  • For each category, there must be three types of cars to rent from:
    •  Luxury
      • Mercedes E-Class, Lexus ES, Infinity Q45
    • Midsize
      • Camry, Altima, Accord
    • Economy
      • Corolla, Civic, Elantra
  • The percentage of sales each category is weighted is as follows:
    • Luxury 15% of the time
    • Midsize 35% of the time
    • Economy 50% of the time


Generation Sequence From Left To Right

  1. Randomly generates from the list of luxury cars
  2. Randomly generates from the list of midsize cars
  3. Randomly generates from the list of economy cars
  4. Return the weighted result


Object Diagram


Video Example



Step by Step Example

1. Create a new Domain and name it "RentalStats"


2. Add a new Attribute to "RentalStats" called "carRentals"


3. Add the listGen Generator to the carRentals Attribute and give it the alias "luxury"


4. Add the following values to the luxury list parameter:

  • Mercedes E-Class
  • Lexus ES
  • Infinity Q45


5. Add another listGen Generator to the carRentals Attribute and give it the alias "midsize"


6. Add the following values to the midsize list parameter:

  • Camry
  • Altima
  • Accord


7. Add another listGen Generator to the carRentals Attribute and give it the alias "economy"


8. Add the following values to the midsize list parameter:

  • Corolla
  • Civic
  • Elantra



9. Add a MultiWeightGen to the carRentals 


9. Add the following items to the car Generator valueList:

  • #{self.gen1} (This references luxury)
  • #{self.gen2} (This references midsize)
  • #{self.gen3} (This references economy)


10. Add the following items to the car Generator percentList:

  • 15
  • 35
  • 50


11. Click on the Preview tab 

You will see that:  

  • Luxury cars are selected 15% of the time
  • Midsize cars are selected 35% of the time
  • Economy cars are selected 50% of the time