Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed Jun 26, 2024
2 parents 226257c + aeda373 commit c9acad0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
45 changes: 34 additions & 11 deletions ndlib/models/compartments/EdgeCategoricalAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,47 @@ def __init__(

def execute(self, node, graph, status, status_map, *args, **kwargs):
neighbors = list(graph.neighbors(node))
isDiGraph = False #true if the current graph is directed

if isinstance(graph, nx.DiGraph):
neighbors = list(graph.predecessors(node))
isDiGraph = False

edge_attr = graph.get_edge_attributes(self.attribute)

if self.trigger is not None:
triggered = [
v
for v in neighbors
if status[v] == status_map[self.trigger]
and edge_attr[(min([node, v]), max([node, v]))] == self.attribute_value
]
if(isDiGraph):
triggered = [
v
for v in neighbors
if status[v] == status_map[self.trigger]
and edge_attr[(min([node, v]), max([node, v]))] == self.attribute_value
]
else:
triggered = []
for v in neighbors:
if((node, v) in edge_attr):
check = edge_attr[(node, v)]
else: #then graph.has_edge(v, node) is True because v is given as neighbor of node
check = edge_attr[(v, node)]
if status[v] == status_map[self.trigger] and check == self.attribute_value:
triggered.append(v)
else:
triggered = [
v
for v in neighbors
if edge_attr[(min([node, v]), max([node, v]))] == self.attribute_value
]
if(isDiGraph):
triggered = [
v
for v in neighbors
if edge_attr[(min([node, v]), max([node, v]))] == self.attribute_value
]
else:
triggered = []
for v in neighbors:
if((node, v) in edge_attr):
check = edge_attr[(node, v)]
else:
check = edge_attr[(v, node)]
if check == self.attribute_value:
triggered.append(v)

for _ in triggered:
p = np.random.random_sample()
Expand Down
10 changes: 8 additions & 2 deletions ndlib/models/compartments/EdgeNumericalAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def execute(self, node, graph, status, status_map, *args, **kwargs):
if self.trigger is not None:
for v in neighbors:
if status[v] == status_map[self.trigger]:
val = edge_attr[(min([node, v]), max([node, v]))]
if((node, v) in edge_attr):
val = edge_attr[(node, v)]
else:
val = edge_attr[(v, node)]
if self.operator == "IN":
if self.__available_operators[self.operator][0](
val, self.attribute_range[0]
Expand All @@ -82,7 +85,10 @@ def execute(self, node, graph, status, status_map, *args, **kwargs):
triggered.append(v)
else:
for v in neighbors:
val = edge_attr[(min([node, v]), max([node, v]))]
if((node, v) in edge_attr):
val = edge_attr[(node, v)]
else:
val = edge_attr[(v, node)]
if self.operator == "IN":
if self.__available_operators[self.operator][0](
val, self.attribute_range[0]
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
url='https://github.com/GiulioRossetti/ndlib',
author='Giulio Rossetti',
author_email='[email protected]',
use_2to3=True,
entry_points={
'console_scripts': [
'NDQL_translate = scripts.NDQL_translate:translate',
Expand Down

0 comments on commit c9acad0

Please sign in to comment.