(self, graph: nx.Graph = None, file_name = None)
| 7 | random.seed(0) |
| 8 | class GraphSampler: |
| 9 | def __init__(self, graph: nx.Graph = None, file_name = None): |
| 10 | if file_name: |
| 11 | with open(file_name, "r") as f: |
| 12 | data = json.load(f) |
| 13 | |
| 14 | # Represent your graph in NetworkX |
| 15 | graph = nx.DiGraph() |
| 16 | |
| 17 | # Add nodes to the graph |
| 18 | if "input-type" in data["nodes"][0]: |
| 19 | for node in data["nodes"]: |
| 20 | graph.add_node(node["id"], desc=node["desc"], input_type=node["input-type"], output_type=node["output-type"]) |
| 21 | else: |
| 22 | for node in data["nodes"]: |
| 23 | graph.add_node(node["id"], desc=node["desc"], parameters=node["parameters"]) |
| 24 | |
| 25 | # Add edges to the graph |
| 26 | for link in data["links"]: |
| 27 | graph.add_edge(link["source"], link["target"], type=link["type"]) |
| 28 | |
| 29 | self.graph = graph |
| 30 | |
| 31 | def sample_subgraph_by_weight(self, number_weights, method_weights): |
| 32 | method = random.choices(list(method_weights.keys()), weights=list(method_weights.values()))[0] |
nothing calls this directly
no outgoing calls
no test coverage detected