Krishna Kumar S commited on
Commit
5c4e1e0
·
1 Parent(s): de0905d
__pycache__/solve_optimization_problem.cpython-312.pyc CHANGED
Binary files a/__pycache__/solve_optimization_problem.cpython-312.pyc and b/__pycache__/solve_optimization_problem.cpython-312.pyc differ
 
network_diagram.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import networkx as nx
2
+ import matplotlib.pyplot as plt
3
+ import matplotlib.patches as mpatches
4
+ from collections import defaultdict
5
+ from create_optimization_problem import create_sourcing_problem
6
+ from solve_optimization_problem import solve_sourcing_problem
7
+ from read_data import load_excel_data
8
+
9
+
10
+ def create_sourcing_graph(fulfillment_solution):
11
+ # Create a directed graph
12
+ G = nx.DiGraph()
13
+
14
+ # Determine warehouses and orders from shipments
15
+ warehouses = set(w for w, _, _, _ in fulfillment_solution)
16
+ orders = set(o for _, _, o, _ in fulfillment_solution)
17
+
18
+ # Add nodes to graph
19
+ G.add_nodes_from(warehouses, color='blue') # Warehouses
20
+ G.add_nodes_from(orders, color='red') # Orders
21
+
22
+ # Group shipments by (warehouse, order)
23
+ shipment_info = defaultdict(list)
24
+ for w, p, o, q in fulfillment_solution:
25
+ shipment_info[(w, o)].append(f"{p} ({q})")
26
+
27
+ # Add edges with combined product info as labels
28
+ edge_labels = {}
29
+ edge_widths = []
30
+ edge_colors = []
31
+ for (w, o), p in shipment_info.items():
32
+ label = "\n".join(p) # Combine all products for the edge
33
+ G.add_edge(w, o, label=label)
34
+ edge_labels[(w, o)] = label
35
+ total_qty = sum(int(p.split('(')[-1].strip(')')) for p in p) # Sum quantities
36
+ edge_widths.append(total_qty / 10) # Scale edge width by total quantity
37
+ edge_colors.append("black")
38
+
39
+ # Positioning the nodes
40
+ pos = nx.spectral_layout(G)
41
+
42
+ # Node colors
43
+ node_colors = ["yellow" if node in warehouses else "red" for node in G.nodes]
44
+
45
+ # Draw the network
46
+ plt.figure(figsize=(8, 6))
47
+ nx.draw(G, pos, with_labels=True, node_color=node_colors, edge_color=edge_colors,
48
+ node_size=2000, font_size=10, width=edge_widths, arrows=True)
49
+ nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8, label_pos=0.5)
50
+
51
+ # Add legend
52
+ warehouse_patch = mpatches.Patch(color="blue", label="Warehouse")
53
+ order_patch = mpatches.Patch(color="red", label="Order")
54
+ plt.legend(handles=[warehouse_patch, order_patch], loc="upper right")
55
+
56
+ plt.title("Enhanced Sourcing Network Diagram")
57
+ plt.show()
58
+
59
+ plt.savefig('sourcing_network.png')
60
+
61
+
62
+
63
+ if __name__ == "__main__":
64
+ filepath = 'Intelligent_Sourcing.xlsx' # Example file path
65
+ weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df, = load_excel_data(filepath)
66
+
67
+ # Create LP Problem
68
+ prob, Warehouses, Products, Stock, Priority, Orders, Quantity, Variable = create_sourcing_problem(weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df)
69
+ #print(prob.objective)
70
+
71
+ # Solve LP Problem
72
+ status, fulfillment_solution, warehouse_stock_status = solve_sourcing_problem(prob, Warehouses, Products, Stock, Priority, Orders, Quantity, Variable)
73
+
74
+ print(fulfillment_solution)
75
+
76
+ create_sourcing_graph(fulfillment_solution.itertuples(index=False, name=None))
solve_optimization_problem.py CHANGED
@@ -67,8 +67,6 @@ if __name__ == "__main__":
67
  filepath = 'Intelligent_Sourcing.xlsx' # Example file path
68
  weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df, = load_excel_data(filepath)
69
 
70
- prob, Warehouses, Products, Stock, Priority, Orders, Quantity, Variable = create_sourcing_problem(weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df)
71
-
72
  # Create LP Problem
73
  prob, Warehouses, Products, Stock, Priority, Orders, Quantity, Variable = create_sourcing_problem(weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df)
74
  #print(prob.objective)
 
67
  filepath = 'Intelligent_Sourcing.xlsx' # Example file path
68
  weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df, = load_excel_data(filepath)
69
 
 
 
70
  # Create LP Problem
71
  prob, Warehouses, Products, Stock, Priority, Orders, Quantity, Variable = create_sourcing_problem(weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df)
72
  #print(prob.objective)
sourcing_network.png ADDED