Untitled
public
May 13, 2025
Never
9
1 pos = nx.planar_layout(G) 2 plt.figure(figsize=(12, 8)) 3 nx.draw(G, pos, with_labels=True, node_size=2000, node_color="lightblue", font_size=10) 4 labels = {node: f"{node}\n({data['duration']}d)" for node, data in G.nodes(data=True)} 5 nx.draw_networkx_labels(G, pos, labels=labels) 6 plt.title("Сетевой график проекта") 7 plt.axis("off") 8 plt.tight_layout() 9 plt.show() Compute earliest start and finish times using a topological sort 10 earliest_start = {} 11 earliest_finish = {} 12 13 for node in nx.topological_sort(G): 14 preds = list(G.predecessors(node)) 15 if preds: 16 earliest_start[node] = max(earliest_finish[p] for p in preds) 17 else: 18 earliest_start[node] = 0 19 earliest_finish[node] = earliest_start[node] + G.nodes[node]['duration']