Variability

  • It is common in domain modeling and domain engineering to focus on narrow domains. This helps to avoid scope creep and exploit commonality. Managing **variability* is the price we have to pay for being able to support more than one product, but we want to keep the variability possible low (as a cost).

  • In this tutorial, we will concentrate our model on small regional stations. We scope our model to:

    • allow single or dual main tracks,
    • one or two input tracks,
    • and one or two output tracks.
  • Finally, we observe that some stations (and only some) also have a side track, also known as a parking track, were trains can be stopped for longer periods.

Let’s reflect these changes in our feature model:

abstract RegionalStationConf
xor main_tracks
single 0..1
dual 0..1
1..1 tracks_in
single ?// shortcut for 0..1
dual ?
xor tracks_out
single// '?' is default for grouped clafers
dual// so we omit it.
parking_track ?// this clafer is not grouped, so '?' cannot be omitted
MyConfiguration : RegionalStationConf

A few observations about this model

  • Recall that the symbol ? is a handy notation for 0..1 cardinality and we will use it from now onwards. This cardinality represents optional features, so this is one way we introduce variability in the model.

  • Cardinality constraints that are written to the left of the clafer name restrict the cardinality of the set of all children. We call such a cardinality constraint a group cardinality (as opposed to clafer cardinality)

  • xor is a shortcut for 1..1 again, but traditionally used for group cardinality describing a choice of an alternative. It means that only one of the children can be selected at a time. Think of this group as ‘Radio Buttons’.

  • other useful group cardinalities include mux (which stands for 0..1), and or (which stands for 1..*). The former means that at most one sub-clafer can be instantiated, but perhaps none. This is a classic mutual exclusion requirement (an exclusion group). The latter, defining so called or-groups, means that at least one sub-clafer must be instantiated. This captures a common pattern of a required subsystem, that has a number of variations, which can coexist; for instance, different compression algorithms or different authentication protocols in software applications.

More information: Tutorial: Group Cardinalities

  • If the group cardinality constraint is anything else than 0..* (which is the default one, corresponding to no restriction), then the default cardinality for each of the children is ? (otherwise 1 as explained in the previous page). This is natural, as mandatory features do not make sense in groups with restricted cardinality – they would immediately produce an inconsistency in the model.

  • Clafers can be arbitrarily nested. Thus our mandatory clafers (first level of nesting) still are mandatory, but their subclafers are optional.

More information: Tutorial: Cardinality

How many model instances are possible now?

Let’s use another tool, ClaferConfigurator, to generate all instances.


Task 2:

  • Press the button to open the model from this page in the configurator and press the button Run in the Instance Generator window – it will try to generate 10 instances. Make sure that you are using an Alloy based generator, not the choco and not the Z3 based.

  • The green tick green tick indicates the presence of a clafer in a given instance, the red crossed circle red crossed circle its absence. All mandatory clafers are also present in every instance as indicated by gray checked checkboxes always checked checkbox in the left column.

  • Note that, in general, making a clafer mandatory does not guarantee that it will be present in all instances, since it can be a child of an optional clafer.

  • Close the configurator

For completeness we include the same model in the popular FODA [FODA] notation:

Small train stations, variability in the FODA feature modeling syntax

Clafer also has a simple visualization tool translating models to the VSpec notation of Common Variability Language (CVL). This is very similar to FODA feature models:

display:block;width:100%;border:solid lightgray 1px;overflow-x:auto; display:block;width:100%;border:solid lightgray 1px;overflow-x:auto; -4,4 -4,-172 640.07,-172 640.07,4 -4,4 c0_RegionalStationConf RegionalStationConf 14.00 c0_main_tracks main_tracks 14.00 c0_main_tracks->c0_RegionalStationConf M123.4,-116.85C140.23,-121.53 160.79,-127.25 179.89,-132.56 gc0_main_tracks 1..1 10.00 gc0_main_tracks->c0_main_tracks M88,-80.57C88,-82.91 88,-85.3 88,-87.64 c0_single single 14.00 c0_single->gc0_main_tracks M52.16,-36.33C60.3,-41.93 68.96,-47.89 75.73,-52.55 c0_dual dual 14.00 c0_dual->gc0_main_tracks M88,-36.08C88,-41.9 88,-48.13 88,-52.9 c0_tracks_in tracks_in 14.00 c0_tracks_in->c0_RegionalStationConf M220.02,-124.08C221.88,-126.54 223.81,-129.06 225.68,-131.52 gc0_tracks_in 1..1 10.00 gc0_tracks_in->c0_tracks_in M207,-80.57C207,-82.91 207,-85.3 207,-87.64 c1_single single 14.00 c1_single->gc0_tracks_in M172.93,-36.33C180.66,-41.93 188.9,-47.89 195.34,-52.55 c1_dual dual 14.00 c1_dual->gc0_tracks_in M208.78,-36.08C208.36,-41.9 207.92,-48.13 207.58,-52.9 c0_tracks_out tracks_out 14.00 c0_tracks_out->c0_RegionalStationConf M257.98,-124.08C256.12,-126.54 254.19,-129.06 252.32,-131.52 gc0_tracks_out 1..1 10.00 gc0_tracks_out->c0_tracks_out M271,-80.57C271,-82.91 271,-85.3 271,-87.64 c2_single single 14.00 c2_single->gc0_tracks_out M271,-36.08C271,-41.9 271,-48.13 271,-52.9 c2_dual dual 14.00 c2_dual->gc0_tracks_out M306.84,-36.33C298.7,-41.93 290.04,-47.89 283.27,-52.55 c0_parking_track parking_track 14.00 c0_parking_track->c0_RegionalStationConf M308.19,-122.38C306.77,-122.93 305.38,-123.47 304,-124 297.68,-126.44 291.02,-129 284.46,-131.52 c0_MyConfiguration MyConfiguration:c0_RegionalStationConf

Previous
  1. Commonality.