Commit b83e67e7 authored by dirk.wintergruen's avatar dirk.wintergruen
Browse files

adding validation of multilayer and removed find

parent b4c6c4c5
__version__ = "0.9.4.0"
__version__ = "0.9.5.0"
from itertools import product
import math
import os
import sys
......@@ -273,6 +275,54 @@ class MultiLayerGraph(OrderedDict):
update=True
)
def filter_edge_by_vertices(self,start_vertex,end_vertex):
if isinstance(start_vertex,str):
start_vertex = {"label":start_vertex}
if isinstance(end_vertex,str):
end_vertex = {"label":end_vertex}
nw = self.copy()
for y, ynw in self.items():
if isinstance(ynw, MultiLayerGraph):
s_vs = ynw.multi_layer.vs.select(**start_vertex)
e_vs = ynw.multi_layer.vs.select(**end_vertex)
for s,e in product(s_vs,e_vs):
nds = ynw.multi_layer.es.select(_source=s.index,_target=e.index)
nds.delete()
for v, k in ynw.items():
try:
s_vs = k.vs.select(**start_vertex)
e_vs = k.vs.select(**end_vertex)
for s, e in product(s_vs, e_vs):
nds = k.es.select(_source=s.index, _target=e.index)
nds.delete()
except:
e = sys.exc_info()
logger.debug(e[0], e[1], e[2])
logger.warning("""Something (%s) went wrong in year %s.
Most likely one of the attributes doesn't exit in this year.""" % (
e[0], y))
else:
try:
s_vs = ynw.vs.select(**start_vertex)
e_vs = ynw.vs.select(**end_vertex)
for s, e in product(s_vs, e_vs):
nds = ynw.es.select(_source=s.index, _target=e.index)
nds.delete()
logger.debug("delete: %s" % len(nds))
except:
e = sys.exc_info()
#logger.debug(e[0], e[1], e[2])
logger.warning("""Something (%s) went wrong in year %s.
Most likely one of the attributes doesn't exit in this year.""" % (e[0], y))
return nw
def filter_es(self, *args, **kwds):
"""filter all nodes given bei args,kwargs, parameters are the same as in igraph.es.select
......@@ -1898,6 +1948,89 @@ class MultiLayerGraph(OrderedDict):
return nw
def filter_edge_by_vertices(self,start_vertex,end_vertex):
"""filter all nodes given bei args,kwargs, parameters are the same as in igraph.vs.select
(#TODO still experimental !!)
:return: MultiLayerGraph without the selected edges.
"""
nw = super().copy()
if isinstance(start_vertex, str):
start_vertex = {"label": start_vertex}
if isinstance(end_vertex, str):
end_vertex = {"label": end_vertex}
# now the layers of each year network
logger.debug("Step 1: ynws")
nw._ynws = self._ynws.filter_edge_by_vertices(start_vertex,end_vertex)
# nw._ynws = self._ynws.copy()
# for y, ynw in nw._ynws.items():
#
# if transform:
# transform(ynw.multi_layer,transform)
#
# nds = ynw.multi_layer.vs.select(*args, **kwds)
# nds.delete()
# for v, k in ynw.items():
#
# if transform:
# transform(k,transform)
# nds = k.vs.select(*args, **kwds)
# nds.delete()
# merged_networks
logger.debug("Step 2: layer")
for v, k in nw.items():
s_vs = k.vs.select(**start_vertex)
e_vs = k.vs.select(**end_vertex)
for s, e in product(s_vs, e_vs):
nds=k.es.select(_source=s.index, _target=e.index)
nds.delete()
logger.debug("Step 3: merged_ynws")
nw._merged_ynws = {}
try:
for v, w in self.merged_ynws.items():
nw._merged_ynws[v] = w.copy()
for intervall, merged_ynws in nw._merged_ynws.items():
for y, ynw in merged_ynws.ynws.items():
s_vs = ynw.multi_layer.vs.select(**start_vertex)
e_vs = ynw.multi_layer.vs.select(**end_vertex)
for s, e in product(s_vs, e_vs):
nds = ynw.multi_layer.es.select(_source=s.index, _target=e.index)
nds.delete()
for v, k in ynw.items():
try:
s_vs = k.vs.select(**start_vertex)
e_vs = k.vs.select(**end_vertex)
for s, e in product(s_vs, e_vs):
nds = k.es.select(_source=s.index, _target=e.index)
nds.delete()
except:
e = sys.exc_info()
logger.debug(e[0], e[1], e[2])
logger.warning("""Something (%s) went wrong in year %s.
Most likely one of the attributes doesn't exit in this year.""" % (e[0], y))
#if len(nds) > 0:
# print("%s %s %s del"% (v,y,intervall))
except NotCalculatedYetError:
pass # if not calculated in source ignore
nw.generateMultiLayer(v_attr_name=self._multi_layer_v_attr_name)
return nw
def indicators(self, intervall=-100):
mls = {}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment