optimization-ml-hybrid
Optimization-ML Hybrid Approaches
You are an expert in combining machine learning with mathematical optimization for supply chain. Your goal is to integrate ML predictions into optimization models, learn optimization parameters, and create end-to-end learning systems.
Key Patterns
1. Predict-Then-Optimize
# Step 1: ML predicts demand
demand_forecast = ml_model.predict(features)
# Step 2: Optimization uses forecast
optimal_production = optimize_production(demand_forecast)
2. ML for Optimization Parameters
# Learn optimal parameters from data
safety_stock = ml_model.predict([sku_features, demand_history])
# Use in inventory optimization
reorder_point = expected_demand_during_leadtime + safety_stock
3. End-to-End Learning
# Differentiable optimization layer
class OptimizationLayer(nn.Module):
def forward(self, predictions):
# Solve optimization with predictions
# Backpropagate through optimization
return optimal_decisions
Smart Predict-Then-Optimize
from sklearn.ensemble import RandomForestRegressor
from pulp import *
class PredictThenOptimize:
"""
ML forecasting + Optimization planning
"""
def __init__(self):
self.ml_model = RandomForestRegressor()
self.opt_model = None
def train_ml(self, X_train, y_train):
"""Train ML forecast model"""
self.ml_model.fit(X_train, y_train)
def optimize_with_forecast(self, features, costs):
"""Optimize using ML predictions"""
# Step 1: Predict demand
demand_forecast = self.ml_model.predict(features)
# Step 2: Optimize production
model = LpProblem("Production", LpMinimize)
products = range(len(demand_forecast))
produce = LpVariable.dicts("Prod", products, lowBound=0)
# Objective: minimize cost
model += lpSum([costs[i] * produce[i] for i in products])
# Constraints: meet forecasted demand
for i in products:
model += produce[i] >= demand_forecast[i]
model.solve()
return {i: produce[i].varValue for i in products}
Learning Optimization Heuristics
class MLOptimizationHeuristic:
"""
Learn when to apply optimization heuristics
"""
def __init__(self):
self.classifier = RandomForestClassifier()
def train(self, problem_features, best_heuristic_labels):
"""
Learn which heuristic works best for problem instance
"""
self.classifier.fit(problem_features, best_heuristic_labels)
def select_heuristic(self, problem_instance):
"""Predict best heuristic for new problem"""
features = extract_features(problem_instance)
heuristic_id = self.classifier.predict([features])[0]
return HEURISTICS[heuristic_id]
Neural Network Warm Start
def neural_warm_start(model, problem_instance):
"""
Use NN to generate initial solution for optimization
"""
# NN predicts good initial solution
features = extract_features(problem_instance)
initial_solution = nn_model.predict(features)
# Use as warm start in MIP
for var_name, value in initial_solution.items():
model.variables[var_name].setInitialValue(value)
model.solve()
Graph Neural Networks for Routing
class GNNRouter:
"""
GNN to learn routing heuristics
"""
def __init__(self):
self.gnn = GraphNeuralNetwork()
def embed_vrp_instance(self, customers, depot):
"""Convert VRP to graph"""
# Nodes: customers + depot
# Edges: distances
graph = create_graph(customers, depot)
return graph
def predict_route(self, graph):
"""
GNN predicts edge probabilities
Use to construct route
"""
edge_probs = self.gnn(graph)
route = construct_route_from_probs(edge_probs)
return route
Tools & Libraries
cvxpylayers: Differentiable optimizationOptNet: Optimization as NN layerqpth: QP layer for PyTorchSciPy + PyTorch: custom integration
Related Skills
- optimization-modeling: mathematical programming
- ml-supply-chain: machine learning
- **metaheuristic-optimization`: heuristics
- reinforcement-learning-supply-chain: RL integration
More from kishorkukreja/awesome-supply-chain
procurement-optimization
When the user wants to optimize procurement decisions, allocate orders across suppliers, or determine optimal order quantities. Also use when the user mentions "order allocation," "supplier portfolio optimization," "lot sizing," "order splitting," "purchase optimization," "EOQ," "sourcing optimization," or "multi-sourcing strategy." For supplier selection, see supplier-selection. For spend analysis, see spend-analysis.
71replenishment-strategy
When the user wants to design or optimize replenishment strategies, determine replenishment policies, or improve inventory flow between locations. Also use when the user mentions "inventory replenishment," "stock replenishment," "min-max inventory," "DRP," "auto-replenishment," "vendor-managed inventory," "forward pick replenishment," or "retail store replenishment." For safety stock calculations, see inventory-optimization. For multi-echelon networks, see multi-echelon-inventory.
37inventory-optimization
When the user wants to optimize inventory levels, calculate safety stock, determine reorder points, or minimize inventory costs. Also use when the user mentions "inventory management," "safety stock," "EOQ," "reorder point," "service level," "stockout prevention," "ABC analysis," "inventory turns," or "working capital reduction." For warehouse slotting, see warehouse-slotting-optimization. For multi-echelon systems, see multi-echelon-inventory.
33pharmaceutical-supply-chain
When the user wants to optimize pharmaceutical supply chains, manage cold chain logistics, ensure regulatory compliance, or implement serialization. Also use when the user mentions "pharma supply chain," "GMP compliance," "cold chain," "drug serialization," "clinical trials logistics," "pharmaceutical distribution," "good distribution practices," "GDP," "drug safety," or "pharmaceutical quality." For general healthcare, see hospital-logistics. For clinical trials specifically, see clinical-trial-logistics.
30supplier-selection
When the user wants to evaluate suppliers, select vendors, or perform supplier scoring and qualification. Also use when the user mentions "vendor selection," "supplier evaluation," "RFP scoring," "supplier qualification," "vendor comparison," "make vs buy," "supplier scorecard," or "bid analysis." For ongoing supplier risk monitoring, see supplier-risk-management. For contract negotiation, see contract-management.
30freight-optimization
When the user wants to optimize freight transportation, reduce shipping costs, or improve carrier selection. Also use when the user mentions "freight management," "carrier optimization," "mode selection," "LTL/TL optimization," "freight consolidation," "load planning," or "transportation procurement." For local delivery routes, see route-optimization. For last-mile, see last-mile-delivery.
28