AI/ML

Jan 2026

Testing an SCND Cost Function Before Optimization

How I used a five-year supply-chain network demo to test CAPEX, fixed OPEX, transport cost, opening time, and capacity tradeoffs before building the optimizer.

2 min read

M.Behbahani

Optimization Starts with the Cost Function

Before I wrote the full supply-chain network optimizer, I implemented the objective as a standalone scenario evaluator. That let me test units, timing, capacity bands, allocation logic, and cost dominance without involving solver behavior.

A solver can minimize a function exactly as written and still produce the wrong business decision. The evaluator made the economic assumptions visible first.

Model the objective as an independent component

I built scnd.oploy.eu as an interactive evaluator for a Netherlands network over 2026 to 2030. A scenario chooses fulfillment-center opening periods and capacity levels. The evaluation layer allocates demand to the nearest open facility, checks capacity and shortfall, and aggregates the cost by half-year period.

The implemented objective has four parts:

textCopied!
total_cost = opening_capex
           + fixed_facility_opex
           + hub_to_facility_transport
           + facility_to_demand_transport

Opening CAPEX is charged once in the selected period. Fixed OPEX repeats while a facility is active and depends on its capacity band. Transport OPEX depends on both network geometry and allocated flow. The user interface exposes these terms separately so one large component cannot hide a modeling error in another.

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#111827', 'primaryTextColor': '#F9FAFB', 'primaryBorderColor': '#60A5FA', 'lineColor': '#94A3B8', 'secondaryColor': '#1F2937', 'tertiaryColor': '#0F172A', 'fontSize': '15px'}}}%% flowchart LR classDef store fill:#111827,stroke:#F59E0B,color:#F8FAFC,stroke-width:2px; classDef runtime fill:#111827,stroke:#34D399,color:#F8FAFC,stroke-width:2px; A[One-time CAPEX at opening] --> E[Total objective] B[Recurring facility OPEX] --> E C[Hub to facility transport] --> E D[Facility to demand transport] --> E class A,B,C,D store; class E runtime;
Picture 1

Scenario A: 107.9 M€

Picture2

Scenario B: 105.2 M€

Both networks satisfy the same feasibility checks, but Scenario B evaluates 2.7 million euros lower. The opening schedule and selected capacity bands change when CAPEX begins, how many periods incur fixed OPEX, and how far demand travels.

This comparison is a unit test for the decision logic. I expect an earlier opening to increase facility cost and possibly reduce transport cost. If the component table does not move in that direction, I inspect period indexing, distance units, cost multipliers, and facility activation before trusting an optimizer.

Checks I run before solver integration

  • A facility pays opening CAPEX exactly once.
  • Fixed OPEX starts in the opening period and continues only while active.
  • Capacity is compared with flow in the same unit and time period.
  • Transport costs use the intended distance and load units.
  • Infeasible shortfall is reported separately from economic cost.
  • Identical scenarios return identical component totals.
  • Small changes in timing produce explainable changes in the breakdown.

Once these checks pass, the same evaluator can become the objective for a MILP, genetic algorithm, particle-swarm method, or another search procedure. The optimization method can change without changing the business accounting.

Test the evaluator

Open the SCND demo, change opening periods and capacity choices, then compare the cost components rather than only the final total. That is the fastest way to see which assumption drives the decision.

Share this post http://www.oploy.eu/blog/optimization-starts-with-the-cost-function/ Copied!