Technical Deep Dive

How the Retail Decision Engine works

Three models — Deep Learning forecasting, dynamic pricing, and inventory optimization — working together to tell a retailer exactly what to do this week.

Most retailers make pricing and ordering decisions based on gut feeling. This app replaces intuition with an integrated AI pipeline that optimizes every decision simultaneously.

3 AI models, 1 integrated decision

Each module solves a different business problem. The Summary Dashboard combines all three into one actionable recommendation per product, per week.

1
📈
Demand Forecasting (AI)
Temporal Fusion Transformer (TFT) learns complex seasonal patterns and predicts future demand based on price scenarios.
2
💰
Dynamic Pricing
Live slider feeds price inputs directly into the AI, while SciPy calculates the theoretical optimum benchmark.
3
📦
Inventory Optimization
OR-Tools CP-SAT solver calculates the optimal order schedule using the AI's dynamically predicted demand.

How each AI model works

Each model is chosen for a specific reason — not just because it's popular, but because it's the right tool for the problem.

📈

Module 1

Temporal Fusion Transformer — Demand Forecasting

Powered by PyTorch, the Temporal Fusion Transformer (TFT) is a state-of-the-art deep learning model for time series. Unlike traditional models, it can simultaneously ingest static metadata (product categories), known future inputs (planned price changes), and historical sales. Trained on 3 years of daily data per product, it captures the highly non-linear relationship between pricing strategies, seasonality, and consumer demand.

PyTorch · pytorch-forecasting · Deep Learning
💰

Module 2

SciPy Optimization + TFT Inference — Dynamic Pricing

This module uses a hybrid approach. SciPy's bounded scalar minimizer mathematically finds the theoretical profit-maximizing price in milliseconds, plotting a continuous baseline curve. Concurrently, the live price slider feeds user input directly into the cached TFT model to infer a highly accurate 1-point prediction. By visualizing both the AI's prediction and the theoretical benchmark together, users gain trust through transparency.

scipy.optimize · Hybrid Rendering · Real-time Inference
📦

Module 3

OR-Tools CP-SAT Solver — Inventory Optimization

The inventory problem is a discrete, multi-period decision with hard constraints. For the next 8 weeks, the solver decides: order or not, and how many? Constraints include: stock must never fall below the safety level, and there is a lead time between ordering and receiving. CP-SAT models this as a mixed-integer optimization problem. Crucially, it takes the AI-predicted demand directly from the pricing module to find the order combination that minimizes total cost.

OR-Tools CP-SAT · Multi-period planning · Integrated Data Pipeline

From data to decision in 4 steps

The three models form a fully integrated pipeline — a change in price dynamically ripples through to the inventory plan.

1

Planned Price → TFT predicts 8-week demand

When a user adjusts the price slider, the planned price is fed into the loaded Temporal Fusion Transformer (.ckpt) to dynamically infer the demand for the next 8 weeks based on historical context.

# Predict demand based on user-selected price
weekly_forecast = predict_dynamic_demand(
  model=tft_model,
  daily_df=session_data,
  planned_price=slider_price
)
2

Price elasticity → SciPy calculates optimal benchmark

Simultaneously, a mathematical profit curve is generated to find the theoretical optimal price. This serves as a continuous benchmark against the AI's specific point prediction.

# Mathematical profit maximization benchmark
def neg_profit(p):
  return -profit_at_price(p, base_price, elasticity)

result = minimize_scalar(neg_profit, bounds=(min_p, max_p))
3

Predicted demand → OR-Tools plans order schedule

The dynamic 8-week demand forecast generated by the TFT model is passed directly into the inventory optimizer. The solver determines the cheapest order schedule that keeps stock within safe levels.

# Feed AI forecast directly to CP-SAT solver
forecast_8w = weekly_forecast["forecast_sales"].tolist()

inv_result = run_inventory_optimization(
  forecast_demand=forecast_8w,
  current_stock=current_stock
)
4

Summary Dashboard integrates all 3 into one action

The Summary Dashboard fetches the user's selected price state for every product and processes the end-to-end pipeline in real time. It presents actionable insights: the demand forecast vs. last week, the recommended pricing strategy based on gap analysis, and the exact order quantity to place today.

How retailers can use this today

Every decision this system makes replaces a manual process that currently takes hours — or doesn't happen at all. Here are six concrete applications.

🥛
Grocery / Perishables

Perishable Waste Reduction

Perishable products like milk, bread, and fresh produce have a shelf life of days. Overordering leads to waste and markdowns; underordering leads to empty shelves and lost sales. The AI demand forecast tells a store manager exactly how much to order each week, accounting for complex seasonal patterns and price changes. The inventory optimizer then calculates the precise order quantity that minimizes waste while avoiding stockouts.

Expected: 15–25% reduction in perishable waste
🏷️
Grocery / Pricing

Weekly Price Optimization

Most small and mid-size grocery chains set prices once a quarter based on competitor surveys and gut feeling. The dynamic pricing module shows that even a $0.20 price adjustment on a high-velocity item like milk can shift weekly profit by hundreds of dollars. By simulating demand against a deep learning model in real time, the engine enables data-driven weekly price reviews that take minutes instead of days.

Expected: 8–15% improvement in gross margin per SKU
📅
Grocery / Operations

Seasonal Inventory Planning

Orange juice demand spikes in December and January; bread demand rises in November. Without forecasting, buyers either overstock at peak (wasting capital on inventory) or understock (missing the seasonal opportunity). The 8-week planning horizon in the inventory optimizer gives buyers enough lead time to build up stock before the seasonal peak and run it down cleanly afterward.

Expected: 20–30% reduction in peak-season overstock
🏪
Convenience Stores

Multi-SKU Category Management

A convenience store manager typically oversees hundreds of SKUs with limited time for analysis. The product-by-product tab structure of the Retail Decision Engine mirrors how a category manager thinks — one product at a time, with all the relevant data in one view. Scaling this system to cover 100 products would give a category manager a complete weekly decision brief without opening a spreadsheet.

Expected: 3–4 hours saved per buyer per week
🚚
Wholesale / Distribution

Supplier Order Consolidation

Wholesalers and distributors place orders from multiple suppliers with different lead times and minimum order quantities. The inventory optimizer's 8-week planning horizon makes it possible to consolidate orders across products supplied by the same vendor — reducing the number of individual purchase orders, qualifying for volume discounts, and smoothing delivery schedules.

Expected: 10–20% reduction in order processing costs
📊
Retail Analytics / Consulting

Data-Driven Buyer Training

The real-time price slider and live profit curve make the relationship between price, demand, and profit viscerally clear — even to non-technical buyers. Many retail organizations struggle to get buyers to adopt AI because the models feel like black boxes. The Engine's interactive visualizations make the logic transparent, building trust and accelerating adoption across the buying team.

Expected: Faster adoption of analytical decision-making across teams

What this demonstrates

🔗

Systems Thinking

Connecting three different AI models into a single coherent product requires understanding how each model's output becomes another model's input. Building this fully integrated pipeline is what separates a data scientist from a data product builder.

🧰

Right Tool for Each Problem

Deep Learning (TFT) for complex non-linear time series forecasting, SciPy for continuous optimization, and OR-Tools for discrete scheduling. Using the right tool for each problem — rather than forcing one tool to do everything — is a hallmark of experienced engineering.

🎨

UX for Non-Technical Users

The live price slider, hybrid charts, and plain-language Summary Dashboard are designed for a store manager, not a data scientist. Making complex AI outputs immediately actionable for non-technical decision-makers is a product management skill as much as an engineering one.

🌺

Directly Applicable to Hawaii Retail

Hawaii's grocery and convenience retail market operates with thin margins, high transportation costs, and unique seasonal patterns. The combination of dynamic demand forecasting and inventory minimization addresses exactly the pressures that Hawaii retailers face.

See all three models in action

Generate demo data, move the price slider, run the inventory optimizer — then check the Summary Dashboard for the integrated recommendation.

↗ Open Live App ← Back to Portfolio