Skip to content

Commit

Permalink
Update steiner tree method
Browse files Browse the repository at this point in the history
  • Loading branch information
pablormier committed Jul 30, 2024
1 parent 63231b3 commit fea0437
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions corneto/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,13 @@ def to_networkx(self):
@staticmethod
def from_networkx(G: Union[NxGraph, NxDiGraph]):
Gc = Graph()
is_directed = G.is_directed()
for edge in G.edges():
e_data = G.get_edge_data(edge[0], edge[1], default=dict())
if is_directed:
e_data[Attr.EDGE_TYPE.value] = EdgeType.DIRECTED.value
else:
e_data[Attr.EDGE_TYPE.value] = EdgeType.UNDIRECTED.value
Gc.add_edge(edge[0], edge[1], **e_data)
return Gc

Expand Down
4 changes: 2 additions & 2 deletions corneto/_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib
import pickle
import os
import pickle
from collections import OrderedDict
from itertools import filterfalse
from typing import Any, Callable, Dict, Iterable, Optional, Set, TypeVar
Expand Down Expand Up @@ -144,7 +144,7 @@ def _get_info() -> Dict[str, Dict]:
info["installed_path"] = {
"title": "Installed path",
"message": os.path.dirname(__file__),
"value": os.path.dirname(__file__)
"value": os.path.dirname(__file__),
}
info["repo_url"] = {
"title": "Repository",
Expand Down
4 changes: 3 additions & 1 deletion corneto/methods/steiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def exact_steiner_tree(
if edge_weights is None:
edge_weights = np.array([prop.get("weight", 0) for prop in Gc.get_attr_edges()])
elif isinstance(edge_weights, (list, tuple)):
edge_weights = np.array(edge_weights)
ew = np.zeros(Gc.ne)
ew[: len(edge_weights)] = np.array(edge_weights)
edge_weights = ew
else:
raise ValueError("Unknown type for edge_weights (list or tuple)")

Expand Down

0 comments on commit fea0437

Please sign in to comment.