Since manually creating large instance models requires a lot of effort, we developed a CPS Model Generator that executes a number of generation phases defined in a plan and based on simple configuration can output arbitrarily large CPS models. The model generator is built in Xtend and uses VIATRA Query patterns for gathering elements for complex operations.

The model generator aims to output models that are similar in fine structure but have different number of elements (to generate scaled-up models) and allow some randomization (e.g. to create state machines with different number of states for different application types).

Randomization is controlled by min-max and percentage type parameters and ratio maps:

The fine structure is specified with host and application classes:

Based on a list of host and application classes as input, the CPS model generator outputs an instance model that satisfies the constraints of the classes. While min-max parameters are always satisfied, percentage and ratio map parameters may not be precisely followed (e.g. allocating 35% of 10 applications may be 3 or 4). However, for larger sizes and in general, the generated model will have the structure specified in the classes.

The model generator component is able to generate CyberPhysicalSystem models with the specified properties. The generator is built on top of the PlanExecutor and implements specific plans, phases, operations, initializer and fragment objects. The generation process is based on pseudo-random actions which means the output is deterministic according to the input parameters.

ModelGenerator

Preferences of the model are declared in ICPSConstraints objects. The following constraints are available:

CPS model generation plan

Plan of the CPS model generation

The CPS plan consists of seven phases and eight operations.

  • Prepare: prepare the IncQueryEngine

  • SignalSet: Generate signals

  • Types: Generate Host and Application types (include StateMachines) according to the Classes

  • Instances: Generate Host and Application instances according to the Classes

  • Host Communication: Add communication lines to HostInstances

  • Allocations: Allocate ApplicationInstances to HostInstances

  • Actions: Generate actions to Transitions

Usage example

First, the ICPSConstraints interface shall be implemented.

class SimpleCPSConstraints implements ICPSConstraints {

    override getName() {
        "Simple"
    }

    val hostClass1 = new HostClass(
        "FirstHostClass",
        new MinMaxData(1, 3), // HostTypes
        new MinMaxData(2, 5), // HostInstances
        new MinMaxData(1, 2), // CommLines
        new HashMap // CommRatios
    )
    val hostClass2 = new HostClass(
        "OtherHostClass",
        new MinMaxData(1, 1), // HostTypes
        new MinMaxData(2, 2), // HostInstances
        new MinMaxData(1, 1), // CommLines
        new HashMap // CommRatios
    )

    new() {
        for (class1 : hostClasses) {
            for (class2 : hostClasses) {
                class1.communicationRatios.put(class2, 1)
            }
        }
    }

    override getHostClasses() {
        #[hostClass1, hostClass2];
    }

    override getNumberOfSignals() {
        new MinMaxData(1, 10);
    }

    override getApplicationClasses() {
        val firstAppClassAllocations = new HashMap();
        firstAppClassAllocations.put(hostClass1, 1);
        firstAppClassAllocations.put(hostClass2, 2);

        #[
            new AppClass(
                "FirstAppClass",
                new MinMaxData(1, 3), // AppTypes
                new MinMaxData(1, 2), // AppInstances
                new MinMaxData(2, 4), // States
                new MinMaxData(1, 2), // Transitions
                new Percentage(100), // PercentageOfAllocatedInstances
                firstAppClassAllocations, // allocationRatios
                new Percentage(95), // probabilityOfActionGeneration
                new Percentage(60) // probabilityOfSendAction
            )
        ];
    }
}

This model shall contain least one and maximum three HostTypes of FirstHostClass and exactly one of the OtherHostClass. Each HostType of the FirstHostClass shall be instantiated minimum two and maximum five times and the HostInstances shall communicate with one or two other instances. The OtherHostClass is more stringent, it specifies the exact number of types, instances and communication lines (1,2,1). Instances can communicate with other instances from both HostClasses with equal possibility. Number of the generated signals shall be in range of 1 to 10. The SimpleCPSConstraints specifies only one ApplicationClass, the FirstAppClass. Least one and maximum three ApplicationType shall be created for this class. Each types of FirstAppClass shall be instantiated one or two times and the StateMachine of the types shall contain minimum two and maximum four States with one or two Transactions. Every ApplicationInstance shall be allocated (PercentageOfAllocatedInstances ). Two times more application instances shall be allocated on the instances of the OtherHostClass than the FirstHostClass (allocationRatios). Transitions contain actions with 95% and the probability of the "sendSignal" is 60%.

Then the CPSGeneratorBuilder.buildAndGenerateModel(long seed, ICPSConstraints constraints) : CPSFragment should be called.