User Tools

Site Tools


tutorials:custom_storing_node

This is an old revision of the document!


Mistake: Storing Nodes outside of the graph

When developing a complex model in GroIMP, it happens that you want to “store” nodes in an “easy” to access data structure (list, array, map, …), or as fields of other objects (create a module with its parent as field). Such kind of development practice are strongly discouraged, as they are both inefficient and prone to unexpected errors in the project. This tutorial will cover what type of issues this behavior can create, and propose different approaches to properly get to the same goal.

Example of error

For this example we consider a very simple project of one rgg class with the content:

Node[] mynode = new Node[1];
 
module A;
 
protected void init ()
[
	Axiom ==> A;
]
 
public void storeNode ()
[
a:A ::> mynode[0] = a;
]
 
public void queryA() {
	reset();
	derive();
	println( (*A*));
}

When the project is initialized (either after compilation, or through manual reset) the main graph contains three nodes: the root, an rggroot, one A. (visible in the picture bellow.

As you can see, the Node A has an ID of 193. Let's store that node into the array mynode by running the method sotreNode.

Then, let's reset the project through the reset command, which will remove the RGGRoot node from the graph, as well as all its children nodes (in this case the nodes with id 191 ,and 193) will be removed. After a reset, the project automatically add a NEW RGGRoot in the graph and run the init() method. The init() method here add an NEW A in the main graph.

Thus, after reset the main graph looks like:

As you can see, the graph is very similar. It contains the same type of nodes: the root, an rggroot, one A. However, the RGGRoot and A have the ids: 194 and 196 respectively. They are different Nodes compared to the previous ones.

Now let's query all Node A in the graph and print them with println( (*A*) );. The output result is:

The main graph only contains ONE Node A (with the id 196) as displayed in the 2nd picture. Yet, the query return two A. The current one, and the one stored in the array mynode.

tutorials/custom_storing_node.1752654628.txt.gz · Last modified: 2025/07/16 10:30 by gaetan