psycharo-zz / factor-graph

matlab/c++ factor graph framework
32 stars 8 forks source link

delete a network? #43

Closed ghost closed 11 years ago

ghost commented 11 years ago

When I run kalmanScheduleExample, I get the graph as shown below. When I run the file again, the id numbers have increased. Apparently, the network is not cleaned up after the example is done. How do I delete a set of nodes or a network. Iow, How do I run kalmanExample twice and get teh same id numbers in both cases?

2012-12-12 18-13-30_Figure 1

psycharo-zz commented 11 years ago

It is not the network that is not cleaned up, it is the counter that is static for the nodes. to get the same IDs, we could let the user set id's or simply running clear mexfactorgraph to unload the library

ghost commented 11 years ago

clear mexfactorgraph will imply a rebuild of the toolbox, right? I think that's too much.

How about this?

ffg.clearNodes(); % clears all nodes from memory (and as result, resets node id)
psycharo-zz commented 11 years ago

not, it will not. it will just unload the library from memory

ghost commented 11 years ago

2012-12-13 20-29-44_MATLAB R2012b If I do a clear mexfactorgraph and try to create a new node, then matlab crashes, see image. I'm not sure how you want to do it but as a user, I'd like to be able to delete a network completely and rest or control the id, eg

ffg.clearAllNodes()

or

a = ffg.AddNode('id',1);  
psycharo-zz commented 11 years ago

ok I will check that on windows (on my machine it works). there can be several networks, so such a function won't help. however we could make the network capable of giving away ids. e.g. a = ffg.AddNode(nwk), every node's constructor takes the network as a parameter.

ghost commented 11 years ago

I'm not sure if I get it completely, but

a = ffg.AddNode(nwk)

looks like as if a node is assigned to a network (which is probably a good thing).

Why not this:

nwk = ffg.Network();
a = nwk.AddNode();

and

nwk.delete()

clears the network. Iow, you can only create nodes as part of a network.

Anyway, maybe this is too big a deviation from the issue. I was also thinking of this (but again, probably a large change so let's not do this now; just a thought):

nwk = ffg.createNetwork(); % renamed fft.Network()
a = nwk.createNode('add', <optional name-value pairs>); % rather then a=ffg.AddNode()
b = nwk.createNode('equality');  
nwk.createEdge(a,b, <optional name-value pairs>);

and then

nwk.draw();
nwk.delete();
nwk.step();
psycharo-zz commented 11 years ago

I really don't like this:

nwk = ffg.Network();
a = nwk.AddNode();

there might be a lot of node types. in general, all the things that you proposed can be done, but they are not OOP-ish

ghost commented 11 years ago

OK, then let's not do them

psycharo-zz commented 11 years ago

Before one calls clear mexfactorgraph, it is absolutely necessary to clear all the variables that were used with it (otherwise when the object is deleted it tries to clear memory that was cleared manually by clear command). However, currently I am implementing unique ids among the network, so we should not need to call clear on a regular basis.