tutorials:xl-queries-and-operators
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:xl-queries-and-operators [2024/12/06 00:33] – [Test model] ksmolen | tutorials:xl-queries-and-operators [2025/01/10 11:17] (current) – gaetan | ||
---|---|---|---|
Line 48: | Line 48: | ||
</ | </ | ||
- | We create a new method called '' | + | We create a new method called '' |
{{ : | {{ : | ||
Line 60: | Line 60: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | The underlying 2d graph of the generated structure given below: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Beginning from // | ||
+ | |||
==== Query examples ==== | ==== Query examples ==== | ||
- | Replace the text inside the '' | + | Replace the text (in red) inside the '' |
- | To list all the internodes in the structure: | + | Below each query, there is a result of the print command, for illustration. Note, that the ids will differ with different model execution. |
+ | |||
+ | * Find all the internodes in the structure: | ||
<code java> | <code java> | ||
Line 71: | Line 80: | ||
</ | </ | ||
+ | The query will return ids of all the internodes in the plant structure. | ||
+ | <hidden answer> | ||
+ | Model.Internode[id=1911]@ecc95fb | ||
+ | |||
+ | Model.Internode[id=1906]@7b431a06 | ||
+ | |||
+ | Model.Internode[id=1901]@5753e950 | ||
+ | |||
+ | __Note:__ | ||
+ | |||
+ | Internode with the id=1901 is the first internode from the bottom (with the highest age: 3). | ||
+ | |||
+ | Internode with the id=1911 is the top internode (with the lowest age: 1) | ||
+ | </ | ||
+ | |||
+ | Notice, that when you click with a mouse on an internode in the 3D View window, information about the selected internode will be displayed in the Attribute Editor. In the Attribute Editor, you can check the internode id (e.g. Model$Internode [Internode.1756]) and compare it with the one that was printed in the XL Console. Another option is to look at the node ids in the 2D Graph (Panels -> 2D -> Graph, in the graph window: View -> Redraw). | ||
+ | |||
+ | * Find all newly created internode(s), | ||
+ | |||
+ | <code java> | ||
+ | (* i: | ||
+ | </ | ||
+ | |||
+ | <hidden answer> | ||
+ | Model.Internode[id=1911]@ecc95fb | ||
+ | </ | ||
+ | |||
+ | * Find the internode below the bud: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <code java> | ||
+ | (* Bud < RH < Internode *) | ||
+ | </ | ||
+ | |||
+ | ''<'' | ||
+ | |||
+ | <hidden answer> | ||
+ | Model.Internode[id=1911]@ecc95fb | ||
+ | </ | ||
+ | |||
+ | * Find all leaves connected to an internode: | ||
+ | |||
+ | <code java> | ||
+ | (* Internode +> RL > Leaf *) | ||
+ | </ | ||
+ | |||
+ | This is just to illustrate how to define different edge types inside a query. '' | ||
+ | |||
+ | <hidden answer> | ||
+ | Model.Leaf[id=1913]@4b0f7bd | ||
+ | |||
+ | Model.Leaf[id=1908]@1c6dbfa5 | ||
+ | |||
+ | Model.Leaf[id=1903]@668c1f97 | ||
+ | |||
+ | __Note:__ | ||
+ | Leaf with the id=1903 is the first (and the oldest) leaf, leaf with the id=1913 is the last (and the yongest) leaf. | ||
+ | </ | ||
+ | |||
+ | ==== Aggregators ==== | ||
+ | |||
+ | Aggregate operations are used to collect multiple values when traversing the graph structure and return a single value. | ||
+ | |||
+ | Standard [[: | ||
+ | |||
+ | * Count all leaves: | ||
+ | |||
+ | <code java> | ||
+ | count((* Leaf *)) | ||
+ | </ | ||
+ | |||
+ | <hidden answer> | ||
+ | 3 | ||
+ | </ | ||
+ | |||
+ | |||
+ | * Sum up the area of all leaves: | ||
+ | |||
+ | <code java> | ||
+ | sum((* Leaf *)[area]) | ||
+ | </ | ||
+ | |||
+ | <hidden answer> | ||
+ | 6.0 | ||
+ | </ | ||
+ | |||
+ | |||
+ | * Sum up the length of internodes: | ||
+ | |||
+ | <code java> | ||
+ | sum((* Internode *)[length]) | ||
+ | </ | ||
+ | |||
+ | <hidden answer> | ||
+ | 6.0 | ||
+ | </ | ||
+ | |||
+ | In this particular example with internodes forming (only) the main stem, the query will return stem length. | ||
+ | |||
+ | * Select the leaf with the highest leaf area: | ||
+ | |||
+ | <code java> | ||
+ | selectWhereMax((* l:Leaf *), (l[area])) | ||
+ | </ | ||
+ | |||
+ | <hidden answer> | ||
+ | Model.Leaf[id=1903]@668c1f97 | ||
+ | </ | ||
+ | |||
+ | |||
+ | * Count internodes that are older than 2 (time units): | ||
+ | |||
+ | <code java> | ||
+ | count((* i: | ||
+ | </ | ||
+ | <hidden answer> | ||
+ | 2 | ||
+ | </ | ||
tutorials/xl-queries-and-operators.1733441611.txt.gz · Last modified: 2024/12/06 00:33 by ksmolen