-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variation conditionals #91
Comments
A few things need to come together for this feature:
|
Some minor corrections to the JSON format: "conditions": { // Variation-level condition
"Black": { "include_when": { "Colour": "Green"} }, // "Black" variation for this layer is included if the "Colour" layer variation is Green
"Blue": { "exclude_when": { "Colour": "Orange" } }, // "Blue" variation for this layer is excluded if the "Colour" layer variation is Orange
"Brown": { "exclude_when": { "NOT": { "Colour": "Blue" } } }, // "Brown" variation for this layer is excluded if the "Colour" variation is NOT Blue
"Green": {
"include_when": { "AND": { "Colour": "Yellow" }, { "Hat": "Beret" } }, // "Green" variation for this layer is included if Colour is Yellow AND Hat is Beret
"exclude_when": { "OR": { "Colour": "Yellow" }, { "Hat": "Cowboy" } } // "Green" variation for this layer is excluded if Colour is Yellow OR Hat is Cowboy
}
} |
Proof of concept of the variation conditionals working with the new random sampler is here 10c3633 Example of a validation callback for the random sampler: rs = RandomSampler(weights)
rs.set_validation_callback( # layer["Color"] == 'Blue' and layer["Landscape"] == 'Tunnel' is invalid
lambda pick: True if len(pick) < 2 else not (pick[0] == 2 and pick[1] == 2),
validate_each_layer=True
) No parsing of the conditions from JSON or UI yet. |
Turns out, we don't need to re-invent the wheel! To keep it JSON compatible, we can keep using dictionaries to represent the tree in Python and in JSON.
Unary operators (only
Leaves "operators" (used to parse values):
(node['layer'] in layers) and (layers[node['layer']] == node['variation']) Each layer variation that needs a conditional will follow the same basic syntax: "conditions": { // Variation-level conditions (a binary expression tree per variation)
"VARIATION_NAME1": {
"op": "AND",
"left": {
// `include_when` binary expression tree
},
"right": {
"op": "NOT",
"left": {
// `exclude_when` binary expression tree
}
}
},
"VARIATION_NAME2": {
// ...
}
} Example for "conditions": { // Variation-level conditions (a binary expression tree per variation)
"Black": {
"op": "AND",
"left": { // `include_when` binary expression tree
"op": "VARIATION",
"layer": "Colour",
"variation": "Green"
},
"right": { // `NOT exclude_when` binary expression tree
"op": "NOT",
"left": { "op": "VALUE", "value": false }
}
},
"Green": {
"op": "AND",
"left": { // `include_when` binary expression tree
"op": "AND",
"left": {
"op": "VARIATION",
"layer": "Colour",
"variation": "Yellow"
},
"right": {
"op": "VARIATION",
"layer": "Hat",
"variation": "Beret"
}
},
"right": { // `NOT exclude_when` binary expression tree
"op": "NOT",
"left": { // `exclude_when` binary expression tree
"op": "OR",
"left": {
"op": "VARIATION",
"layer": "Colour",
"variation": "Red"
},
"right": {
"op": "VARIATION",
"layer": "Hat",
"variation": "Cowboy"
}
}
}
}
} |
Examples:
The text was updated successfully, but these errors were encountered: