# Energy optimization from scipy-optimize on a sub-graph

Hi all,

I'm using graph-tool to represent a living tissue. The tissue grows and
changes shape through successive local changes.

For each of those changes, I need to optimize graph energy (as defined
by a non trivial relation between graphs edge and vertices coordinates
in 3D).

My question is the following:

Before the optimization, is it better to

attachment.html (7.65 KB)

Hi Guillaume,

Hi all,

I'm using graph-tool to represent a living tissue. The tissue grows and
changes shape through successive local changes.

For each of those changes, I need to optimize graph energy (as defined
by a non trivial relation between graphs edge and vertices coordinates
in 3D).

My question is the following:

Before the optimization, is it better to

*

Take a GraphView of the graph masked by filters:

> local_view = gt.GrahView(graph, vfilt=is_local_v, efilt=is_local_e)
### ... optimize on local_view ...|

*

Work on the filtered graph:

> graph.set_vertex_filter(is_local_v)
graph.set_vertex_filter(efilt=is_local_e)
### optimize on local
graph.set_vertex_filter(None)
graph.set_vertex_filter(None)|

*

Do a copy of the local graph,

> local_view = gt.GrahView(graph, vfilt=is_local_v, efilt=is_local_e)
local = Graph(local_view, prune=True)
### ...optimize on local...
graph.set_vertex_filter(is_local_v)
graph.set_vertex_filter(efilt=is_local_e)
for key, prop in graph.vertex_properties:
prop.fa = local.vertex_properties[key].fa|

For now, I am doing it the second way... I suspect it's not the best,
but don't have clue on which of the others is better. Any comments

welcome!

The relative performance of both approaches depend on what exactly you
are doing with the graphs, however the second approach will tend to be
faster on most cases. On a filtered graph, an O(N) operation will depend
on the size of the _unfiltered_ graph, since the filtered vertices/edges
will simply be skipped over during iterations. Furthermore, many
operations will be slower on filtered graphs, since the filter needs to
be applied every time a vertex/edge is touched, which can lead to a
performance drop in tight loops. Thus, if your filtered graph is much
smaller than your main graph, or if you are performing very
time-consuming operations, the second approach will be probably better,
since most of the time will be spent on an unfiltered, possibly much
smaller graph.

Cheers,
Tiago

Ok I'll implement the last solution, thanks a lot!

attachment.html (3.08 KB)