Generating Parameters for Structured Values

In many cases, parameters of actions are not primitive values such as integers, but structured data. Examples include C# structures, compound values from the modeling library such as sequences or user-defined compound values, and bitmasks.

Parameter combinations can be controlled for those values, as well. This is made possible by the fact that the Combination.Interaction accepts, not only action parameter names, but also expressions such as field selections or bit operations.

Structures

If, instead of providing parameters one by one for the AddJob action, they are provided in a structure, the result would look like the following code example.

public struct JobInfo
{
   public string Name;
   public int Time;
   public Frequency Frequency;
}

The configuration that declares parameter generation is very similar to that in the previous section, except that the interaction declaration is now passed as structure members. A further parameter priority outside of the structure has been added to illustrate that interactions can be declared on all levels of nesting of parameter values. This is shown in the following Cord example.

config Struct 
{
   action abstract static void SUT.AddJob(JobInfo info, int priority)
   where
   {.
      Condition.In(info.Name, "t.cmd", "t.exe");
      Condition.In(info.Time, 60, 3600);
      Condition.IsTrue(priority >= 0 & priority < 3);
      Combination.Interaction(info.Name, priority);
      Combination.Interaction(info.Time, info.Frequency);
   .};
}
machine Struct() : Struct
{
   AddJob || (construct model program)
}

The following illustration shows the generated graph.

a5fe8a07-25f8-49dc-afbd-cec694794d76

Compound Values

There is no general difference between compound values and structures regarding parameter generation.

Flags

The same technique used for structures can be applied to flags. The following code example shows a flag enumeration.

[Flags]
public enum DaysOfWeek
{
   None = 0x0, Mon = 0x1, Tue = 0x2, Wed = 0x4, Thu = 0x8, Fri = 0x10,
   Sat = 0x20, Sun = 0x40,
   All = Mon|Tue|Wed|Thu|Fri|Sat|Sun
}

AddJob now allows specifying which days of the week the job should be run on. The following Cord example configures pairwise combination of different flag values. Instead of pairwise, explicit interactions could have been used, as well.

config Flags 
{
   action static void SUT.AddJob(string name, int time, DaysOfWeek days)
   where
   {.
      Condition.In(name, "t.cmd", "t.exe");
      Condition.In(time, 60, 3600);
      Condition.IsTrue(days >= DaysOfWeek.None &
                             days <= DaysOfWeek.All);
      Combination.Pairwise(name, time, days & DaysOfWeek.Mon,
                                       days & DaysOfWeek.Tue,
                                       days & DaysOfWeek.Wed,
                                       days & DaysOfWeek.Thu,
                                       days & DaysOfWeek.Fri,
                                       days & DaysOfWeek.Sat,
                                       days & DaysOfWeek.Sun);
   .};
}
machine Flags() : Flags
{
   AddJob || construct model program
}

In this example of pairwise combination, each possible value of the days parameter is selected in an expression using the bitwise AND operator, as opposed to simply specifying a parameter name, as in the case of the time and name parameters. The graph generated for the Flags machine is shown in the following illustration.

ebab42a4-dd50-404d-acd8-43e88fc13980

Instead of enumeration flags, a similar approach can be used for plain integer type enumerations by extracting the subvalue from the parameter value on which combinations interact, for example, Frequency.Weekly. Bit masks may not be restricted to a single bit, but can cover more than one bit. It is also possible to define domains or constraints on subvalues extracted with a bit mask.

See Also

Concepts

Parameter Generation

Other Resources

Modeling Toolbox