shukdevdatta123 commited on
Commit
0cb1c8f
·
verified ·
1 Parent(s): ba1f6f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -25,6 +25,8 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
25
  nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
26
  st.pyplot(plt)
27
 
 
 
28
  # Function to display Traveling Salesman Problem
29
  def display_tsp():
30
  st.title("Drawing: Traveling Salesman Problem")
@@ -48,7 +50,8 @@ def display_tsp():
48
  dist = dist
49
  G.add_edge(i, j, weight=dist)
50
 
51
- cycle = nx.christofides(G, weight="weight")
 
52
  edge_list = list(nx.utils.pairwise(cycle))
53
 
54
  # Draw closest edges on each node only
@@ -90,7 +93,7 @@ def display_tsp():
90
  G_custom.add_edge(i, j, weight=dist)
91
 
92
  # Find TSP cycle using Christofides' approximation
93
- cycle = nx_app.christofides(G_custom, weight="weight")
94
  edge_list = list(nx.utils.pairwise(cycle))
95
 
96
  # Draw closest edges on each node only
 
25
  nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
26
  st.pyplot(plt)
27
 
28
+ from networkx.algorithms.approximation import christofides
29
+
30
  # Function to display Traveling Salesman Problem
31
  def display_tsp():
32
  st.title("Drawing: Traveling Salesman Problem")
 
50
  dist = dist
51
  G.add_edge(i, j, weight=dist)
52
 
53
+ # Find TSP cycle using Christofides' approximation
54
+ cycle = christofides(G, weight="weight")
55
  edge_list = list(nx.utils.pairwise(cycle))
56
 
57
  # Draw closest edges on each node only
 
93
  G_custom.add_edge(i, j, weight=dist)
94
 
95
  # Find TSP cycle using Christofides' approximation
96
+ cycle = christofides(G_custom, weight="weight")
97
  edge_list = list(nx.utils.pairwise(cycle))
98
 
99
  # Draw closest edges on each node only