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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
from io import StringIO
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
def generate_intelligent_sourcing_excel(
|
| 7 |
+
output_filename,
|
| 8 |
+
num_of_warehouses,
|
| 9 |
+
num_of_products,
|
| 10 |
+
num_of_orders,
|
| 11 |
+
weightage_Cost,
|
| 12 |
+
weightage_Priority,
|
| 13 |
+
weightage_distance,
|
| 14 |
+
weightage_days,
|
| 15 |
+
range_priority,
|
| 16 |
+
range_prod_stock,
|
| 17 |
+
range_order,
|
| 18 |
+
range_cost,
|
| 19 |
+
range_distance,
|
| 20 |
+
range_days
|
| 21 |
+
):
|
| 22 |
+
"""
|
| 23 |
+
Generates an Excel file containing warehouse, order, and shipping data.
|
| 24 |
+
|
| 25 |
+
Parameters:
|
| 26 |
+
output_filename (str): The name of the output Excel file.
|
| 27 |
+
num_of_warehouses (int): Number of warehouses.
|
| 28 |
+
num_of_products (int): Number of products.
|
| 29 |
+
num_of_orders (int): Number of orders.
|
| 30 |
+
weightage_Cost (float): Weightage for cost.
|
| 31 |
+
weightage_Priority (float): Weightage for priority.
|
| 32 |
+
weightage_distance (float): Weightage for distance.
|
| 33 |
+
weightage_days (float): Weightage for days.
|
| 34 |
+
range_priority (tuple): Range for priority values.
|
| 35 |
+
range_prod_stock (tuple): Range for product stock values.
|
| 36 |
+
range_order (tuple): Range for order quantities.
|
| 37 |
+
range_cost (tuple): Range for cost values.
|
| 38 |
+
range_distance (tuple): Range for distance values.
|
| 39 |
+
range_days (tuple): Range for delivery days values.
|
| 40 |
+
"""
|
| 41 |
+
rng = np.random.default_rng(seed=42) # Random number generator
|
| 42 |
+
|
| 43 |
+
# Create weightage DataFrame
|
| 44 |
+
weightage_df = pd.DataFrame({
|
| 45 |
+
'Variable': ['Cost', 'Priority', 'Distance', 'Days'],
|
| 46 |
+
'Weightage': [weightage_Cost, weightage_Priority, weightage_distance, weightage_days]
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
# Generate priority data
|
| 50 |
+
priority_df = pd.DataFrame({
|
| 51 |
+
'Warehouse': [f'Warehouse#{w}' for w in range(1, num_of_warehouses + 1)],
|
| 52 |
+
'Priority': rng.integers(*range_priority, size=num_of_warehouses)
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
# Generate warehouse stock data
|
| 56 |
+
warehouse_df = pd.DataFrame({
|
| 57 |
+
'Warehouse': [f'Warehouse#{w}' for w in range(1, num_of_warehouses + 1)]
|
| 58 |
+
})
|
| 59 |
+
for p in range(1, num_of_products + 1):
|
| 60 |
+
warehouse_df[f'Product#{p}'] = rng.integers(*range_prod_stock, size=num_of_warehouses)
|
| 61 |
+
|
| 62 |
+
# Generate order data
|
| 63 |
+
order_df = pd.DataFrame({
|
| 64 |
+
'Order': [f'Order#{o}' for o in range(1, num_of_orders + 1)]
|
| 65 |
+
})
|
| 66 |
+
for p in range(1, num_of_products + 1):
|
| 67 |
+
order_df[f'Product#{p}'] = rng.integers(*range_order, size=num_of_orders)
|
| 68 |
+
|
| 69 |
+
# Function to generate shipping data
|
| 70 |
+
def generate_shipping_data(metric_name, value_range):
|
| 71 |
+
return pd.DataFrame([
|
| 72 |
+
(w, o, p, rng.integers(*value_range))
|
| 73 |
+
for w in warehouse_df["Warehouse"]
|
| 74 |
+
for o in order_df["Order"]
|
| 75 |
+
for p in warehouse_df.columns[1:]
|
| 76 |
+
], columns=["Warehouse", "Order", "Product", metric_name])
|
| 77 |
+
|
| 78 |
+
# Generate cost, distance, and days DataFrames
|
| 79 |
+
cost_df = generate_shipping_data("Cost", range_cost)
|
| 80 |
+
distance_df = generate_shipping_data("Distance", range_distance)
|
| 81 |
+
days_df = generate_shipping_data("Days", range_days)
|
| 82 |
+
|
| 83 |
+
# Write data to Excel
|
| 84 |
+
with pd.ExcelWriter(output_filename, engine='xlsxwriter') as writer:
|
| 85 |
+
weightage_df.to_excel(writer, sheet_name='Weightage', index=False)
|
| 86 |
+
priority_df.to_excel(writer, sheet_name='Priority Data', index=False)
|
| 87 |
+
warehouse_df.to_excel(writer, sheet_name='Stock Data', index=False)
|
| 88 |
+
order_df.to_excel(writer, sheet_name='Order Data', index=False)
|
| 89 |
+
cost_df.to_excel(writer, sheet_name='Cost Data', index=False)
|
| 90 |
+
distance_df.to_excel(writer, sheet_name='Distance Data', index=False)
|
| 91 |
+
days_df.to_excel(writer, sheet_name='Days Data', index=False)
|
| 92 |
+
|
| 93 |
+
print(f"Excel file '{output_filename}' has been successfully created.")
|
| 94 |
+
return
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def plot_histograms(excel_filename):
|
| 98 |
+
"""
|
| 99 |
+
Reads the generated Excel file and plots separate histograms for relevant data columns.
|
| 100 |
+
"""
|
| 101 |
+
xls = pd.ExcelFile(excel_filename)
|
| 102 |
+
|
| 103 |
+
data_sheets = {
|
| 104 |
+
"Priority": pd.read_excel(xls, "Priority Data")["Priority"],
|
| 105 |
+
"Product Stock": pd.read_excel(xls, "Stock Data").iloc[:, 1:].values.flatten(),
|
| 106 |
+
"Order Quantity": pd.read_excel(xls, "Order Data").iloc[:, 1:].values.flatten(),
|
| 107 |
+
"Cost": pd.read_excel(xls, "Cost Data")["Cost"],
|
| 108 |
+
"Distance": pd.read_excel(xls, "Distance Data")["Distance"],
|
| 109 |
+
"Days": pd.read_excel(xls, "Days Data")["Days"]
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
fig, axes = plt.subplots(2, 3, figsize=(15, 10))
|
| 113 |
+
axes = axes.flatten()
|
| 114 |
+
|
| 115 |
+
for i, (label, data) in enumerate(data_sheets.items()):
|
| 116 |
+
axes[i].hist(data, bins=20, alpha=0.7, color='blue', edgecolor='black')
|
| 117 |
+
axes[i].set_title(label)
|
| 118 |
+
axes[i].set_xlabel("Value")
|
| 119 |
+
axes[i].set_ylabel("Frequency")
|
| 120 |
+
axes[i].grid(True)
|
| 121 |
+
|
| 122 |
+
plt.tight_layout()
|
| 123 |
+
plt.savefig("histogram_ranges.png")
|
| 124 |
+
plt.close()
|
| 125 |
+
print("Histogram saved as 'histogram_ranges.png'")
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if __name__ == "__main__":
|
| 129 |
+
# Define parameters for execution
|
| 130 |
+
output_filename = "Intelligent_Sourcing.xlsx"
|
| 131 |
+
num_of_warehouses = 10
|
| 132 |
+
num_of_products = 100
|
| 133 |
+
num_of_orders = 200
|
| 134 |
+
weightage_Cost = 1
|
| 135 |
+
weightage_Priority = 0.8
|
| 136 |
+
weightage_distance = 0.6
|
| 137 |
+
weightage_days = 0.4
|
| 138 |
+
range_priority = (1, 10)
|
| 139 |
+
range_prod_stock = (1, 100)
|
| 140 |
+
range_order = (1, 10)
|
| 141 |
+
range_cost = (1, 300)
|
| 142 |
+
range_distance = (1, 200)
|
| 143 |
+
range_days = (1, 7)
|
| 144 |
+
|
| 145 |
+
# Run function
|
| 146 |
+
generate_intelligent_sourcing_excel(
|
| 147 |
+
output_filename,
|
| 148 |
+
num_of_warehouses,
|
| 149 |
+
num_of_products,
|
| 150 |
+
num_of_orders,
|
| 151 |
+
weightage_Cost,
|
| 152 |
+
weightage_Priority,
|
| 153 |
+
weightage_distance,
|
| 154 |
+
weightage_days,
|
| 155 |
+
range_priority,
|
| 156 |
+
range_prod_stock,
|
| 157 |
+
range_order,
|
| 158 |
+
range_cost,
|
| 159 |
+
range_distance,
|
| 160 |
+
range_days
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
plot_histograms(excel_filename=output_filename)
|
Intelligent_Sourcing.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
histogram_ranges.png
ADDED
|