Deserializes a Condition tree file into a Binary Tree and :
- Removes contradictive paths
- Prunes valid paths by flattening and simplifying their conditions
- Write the pruned strategies into a file
- OR conditions need to be flattened into two or more separate strategies for each possibility
- Contradictory conditions should be removed, i.e., paths like "phone=5 & phone=7" are not allowed
- Python >3.12 (new type hint annotations)
To run the program, you need to specify at least one argument:
- The path to the DV tree file using the
-for--dv-tree-file-pathargument - The path to the output strategies file using
-oor--strategies-file-pathargument. By default, the program sets this value tostrategies.txt
It is recommended to use Poetry to manage dependencies and run the program. If you don't have Poetry installed, follow the Poetry installation guide.
poetry run dv_strategies -f /path/to/your/dv_tree_file.txtIf you prefer not to use Poetry, make sure you have Python 3.12 installed.
python process_dv_tree.py -f /path/to/your/dv_tree_file.txtYou need to flatten the attached tree ( tree_to_convert.txt ) into a set of strategies.
A strategy is a combination of :
- a strategy definition : a sequence of conditions of the form "{feature} = {value}" or
"{feature} != {value}" separated with "and" operators only.
- e.g : "phone=12 & language=2 & size!=300x600"
- a leaf value
The syntax of a strategy is given by {strategy definition}:{leaf_value}.
- Your script should be coded in Python
- You have to code a function which takes the tree_to_convert.txt file as input, flattens it, and writes the output strategies into another strategies.txt file.
- Your function needs to be generic. It could take as input any tree of the same
structure. You can assume similar tree will have :
- only OR conditions
- only = != operators
- various variables names (only letters) and tree depth
- Your script shouldn’t return impossible strategies:
- "phone=5 & phone=7" is not allowed
- Your script should simplify strategies when possible :
- "value=4" is better than "value!=3 & value=4"
- The operator "&" is the only operator allowed in a strategy
Leaf 4 translates into the following strategy :
"device_type!=pc & browser!=7 & browser=8 : 0.000881108"
Which is then simplified in : "device_type!=pc & browser=8 : 0.000881108"