Category Driven Defaults

This topic is focuses on adding multiple defaults to items and is a continuation of the Expanding The Role of Categories

The basic concept is to allow an item’s Default Value depend on the set of active categories in the Attribute Resource. For example an Integer Item foo could have the following defaults:

  • 1- If the Heat Transfer Category is preset
  • 10 - If the Heat Transfer and CFD Categories are present
  • 100 - If Induction Heating is present
  • 0 - If none of the category defaults match. Basically this would be the current Default Behavior

There also need to be a difference between the Item using its default vs the user setting the Item to a value that happens to match the default.

Lets expand on the above example and assume that foo is using the default and the active category is Heat Transfer. The following would be results based on changes on active categories and the item’s value:

  1. foo is 1
  2. Active Categories changed to both CFD and Heat Transfer: foo is now 10
  3. User explicitly sets foo to 1 (foo is no longer using the default)
  4. Active Categories changed to Heat Transfer: foo is 1 (foo still not using its default)
  5. Active Categories changed to Induction Transfer: foo is still 1
  6. foo is told to use its default: foo is 100

Impact on Items

Currently default values are treated like any other value with the exception that the default value is assigned when the item is constructed or if the Item is reset. The UI code colors the value if the item is using the default but that is about it. For example there is no mechanism to explicitly the item to its default.

In order to support this new functionality, Items will need to have a method to explicitly tell the item to use its default for its value.

API Changes

ItemDefinition refers to DoubleItemDefinition, InItemDefinition, StringItemDefinition, FileSystemItemDefinition
Item refers to DoubleItem, InItem, StringItem, FileSystemItem

  • ItemDefinition ::addDefaultValue(val, set of categories) - this would include
  • Item ::setToDefault(int ith) - Set the ith value to use the default

GUI Changes

Need to provide an icon to reset an item’s value back to its default.

Possible XML format

Here is an example of an existing specification for a DoubleItem:

<Double Name="void-temperature" Label="Temperature">

My intent is to still support this format, where the category independent default is 0.0.

<Double Name="void-temperature" Label="Temperature">
      <Value> 10.0 </Value>
      <CategoryInfo Combination="All">
        <Include Combination="All">
        <Exclude Combination="All">

Dealing with Ambiguity

In the original example, if CFD and Heat Transfer are both on, technically, both of foo’s default rules would match. We do need to have a process to deal with reducing the possibility of ambiguity.

Possible Approach: Precedence is based on order

This is the simplest approach, where the defaults are checked in order and the first match is used but can be pretty tedious to the designer.

Possible Approach: Using Specificity

In this approach, the more specific match would win out. Let assume we have the following default category rules for an IntItem:

  • 1: [a]
  • 2: [a | b]
  • 3: [a & b]
  • 4: [a & b & c]
  • 5: [a | b] | ![d | e]
  • 6: [a | b] | ! [d & e]
  • 7: [a | b] & ! [d | e]
  • 8: [a | b] & ! [d & e]
  • 9: [a & b] | ! [d | e]
  • 10: [a & b] | ! [d & e]
  • 11: [a & b] & ! [d | e] <— Most Restrictive
  • 12: [a & b] & ! [d & e]

Lets also assume that & (and) is more restrictive that | (or). One possible specification rating would be to simply count the number of category hits on the inclusion set and the number of “misses” in the exclusion set. Based on this rule, and an active category set of {a, b, c} we would have the following ranking:

  • Rule 1: 1
  • Rules 2,3: 2
  • Rule 4: 3
  • Rules 5, 6, 7, 8, 9, 10, 11, 12: 4

The problems I have with this ordering are the following:

  • a & b and a | b have the same specification though a & b is more restrictive
  • [a & b] & ! [d | e] is the most restrictive since a and b must be present and d and e must not be present. Yet it has the same ranking as less specific constraints.

So I propose the following Specificity Rule:

  • If the inclusion set combination is All then the specificity of the inclusion set is the number of categories in the set, else it is 1.
  • If the exclusion set combination is Any then the specificity of the exclusion set is the number of categories in the set, else it is 1.
  • If the overall combination is All, then the specificity of the category expression is the sum of the specificity of the inclusion and exclusion sets. Else, the specificity of the category expression is the min of the specificity of the inclusion and exclusion sets.

Based on the above rule we would now get the following ranking:

  • Rules 1, 2, 5, 6, 10: 1
  • Rules 3, 8, 9: 2
  • Rules 4, 7, 12: 3
  • Rule 11: 4

The rule is actually calculating the minimum number of categories that must be present for the rule to match as shown in the table below:

Rule Category Condition
1 a
2 a or b
3 a, b
4 a,b,c
5 a or b or (!d,!e)
6 a or b or !d or !e
7 a,!d,!e, or b,!d,!e
8 a,!d or b!d, or a!e, or b!e
9 a,b or !d,!e
10 a,b or !d or !e
11 a,b,!d,!e
12 a,b,!d or a,b,!e

Note that we may still have ambiguity. In that case we would use the order in which the rules are specified to rule out ties. The first rule with the highest specificity rating would win.

@johnt, @chart3388, @amuhsin - Let me know what you think.

I think this is obvious, but just to make sure: this feature does NOT apply to discrete items (which use a default index in lieu of a default value).

Would a <DefaultValue> (aka the “default default”) be required for an item definition that includes <DefaultInfo> ? Conceptually I presume not, but if there is no <DefaultValue>, we’ll need to decide what to do with the reset icon if none of the category cases are active, either (i) hide the reset icon (my preference) or (ii) clear the item’s value when the reset icon is clicked (making it invalid).

As for ambiguity resolution, I vote for the simple order-based precedence. I like to think we have enough generality in category specification thanks to Bob’s recent updates, and I think the implicit, subtle logic in specificity-based resolution could making debugging quite difficult.

In theory, yes discrete values could have category dependent default indices.

In terms of DefaultValue (the default default) , you are correct, it is not required. If you don’t include it, it means that if none of the category dependent default match, then there is no default.

Privacy Notice