Optimizing Vendor Selection and Monitoring Intensity in the Supply Chain
Supply chain attacks rarely start at your own perimeter. They start at a payment gateway, a SaaS provider, or a log analytics vendor that you trust. Every vendor can be assessed more deeply through questionnaires, continuous attack surface scanning, penetration test reports, and SOC 2 evidence reviews. But every extra layer of monitoring costs money and staff time.
This article formulates the trade-off as an optimization problem. It then solves it exactly in Python with dynamic programming, verifies the answer by brute force, and visualizes the result, including 3D plots.
1. Problem Setting
A company outsources $S = 5$ services (cloud hosting, payment gateway, customer CRM, HR/payroll SaaS, log analytics). For each service there are $V = 3$ candidate vendors, and exactly one vendor must be chosen per service. For each chosen vendor, a monitoring level $m \in {0,1,2,3,4}$ must be chosen. Level 0 means no monitoring, and level 4 means the most intensive monitoring.
Each vendor $v$ of service $s$ has the following attributes:
- $a_{s,v}$: annual contract cost (k$). Cheaper vendors tend to be less secure.
- $p_{s,v}$: annual breach probability without monitoring.
- $w_{s,v}$: monitoring cost per level (k$).
- $\lambda_{s,v}$: effectiveness of monitoring (how fast the risk decays).
- $I_s$: loss if the service is breached (k$).
- $f$: one-time setup cost of starting any monitoring program ($m>0$).
Risk reduction model. Monitoring reduces the breach probability exponentially, with diminishing returns:
$$
p_{s,v}(m) = p_{s,v}, e^{-\lambda_{s,v} m}
$$
Cost of one option $(v, m)$ for service $s$, and its expected loss:
$$
c_{s,v,m} = a_{s,v} + f,\mathbb{1}[m>0] + w_{s,v}, m, \qquad
\ell_{s,v,m} = I_s , p_{s,v}, e^{-\lambda_{s,v} m}
$$
Optimization problem. The goal is to minimize total expected cost, which is security spend plus expected residual loss:

Under a cash budget $B$, the constrained version is:
$$
\min \sum_{s=1}^{S} \ell_{s,v_s,m_s} \quad \text{s.t.} \quad \sum_{s=1}^{S} c_{s,v_s,m_s} \le B
$$
Continuous intuition. If the monitoring level were continuous and the vendor fixed, setting the derivative to zero gives

The optimal intensity grows logarithmically with the impact $I$. Monitor more where a breach hurts more, and where monitoring is cheap and effective.
Exact solution by dynamic programming. The budget-constrained problem is a multiple-choice knapsack. Let $F_s(b)$ be the minimum expected loss of the first $s$ services with spend at most $b$. Then

where $\mathcal{O}$ is the set of all $V \times L = 15$ (vendor, level) options. Sweeping $b$ yields the entire Pareto frontier at once, and the economically optimal budget is

2. Python Code
1 | import numpy as np |
3. Code Walkthrough
3.1 Data generation
The block under “Problem data” creates the scenario. The loss $I_s$ is set by hand to reflect business criticality. The payment gateway has the largest impact and log analytics the smallest. The breach probabilities $p_{s,v}$ are drawn uniformly. The contract cost is deliberately anti-correlated with $p_{s,v}$ through 350 * (0.30 - p), so a safer vendor costs more. This matches reality, where premium providers invest more in security and charge accordingly. The monitoring cost per level $w$ and the effectiveness $\lambda$ are random integers and floats, respectively. The fixed seed makes the article reproducible.
3.2 Option table
For every service, all $V \times L = 15$ combinations of vendor and monitoring level are enumerated with NumPy broadcasting. opt_v and opt_m list the vendor and level of each option column. The arrays cost and loss then implement $c_{s,v,m}$ and $\ell_{s,v,m}$ exactly as defined in Section 1. Costs are integers on purpose, because the dynamic program indexes an array by budget.
3.3 Dynamic programming
dp[b] stores $F_s(b)$, the minimum expected loss with spend at most $b$. It starts as zeros because with no services there is no loss. For each service, every option $o$ is tried. The candidate array cand is the shifted previous table plus the option’s loss, and the entries below the option’s cost remain infinite because they are infeasible. np.where(better, ...) keeps the elementwise minimum and records which option achieved it in choices.
The loops are only over 5 services and 15 options. The budget dimension is handled by vector operations, so the whole table is built in milliseconds. backtrack walks from the last service to the first, reading the stored choice and subtracting its cost from the remaining budget, which reconstructs the actual plan.
Since dp encodes “spend at most $b$”, the last table $F_S$ gives the whole Pareto frontier in a single pass. The economically optimal budget is the minimizer of $b + F_S(b)$, which is the point where one more dollar of security spend no longer buys a dollar of expected loss reduction.
3.4 Brute-force verification
np.add.outer repeatedly builds the cost and loss of all $15^5 = 759{,}375$ combinations without Python loops. The minimum of cost plus loss must equal the DP optimum, and the minimum loss among combinations with cost at most $b^*$ must equal the DP loss at that budget. The console prints both comparisons as True or False. This is exhaustive enumeration at a size that stays fast, so no further speed-up is required. For hundreds of vendors, where enumeration is impossible, the DP scales linearly in the number of services, which is why it is the main solver and enumeration is only the audit.
3.5 Baseline strategies
Four intuitive policies are compared against the optimum. The first picks the cheapest vendors and monitors nothing. The second picks the lowest-risk vendors without monitoring. The third picks the cheapest vendors and monitors everything at level 3. The fourth picks the safest vendors and monitors everything at level 2. These represent common real-world habits: minimize procurement cost, buy the best reputation, or apply a uniform compliance rule to every vendor.
4. Execution Results
=== Vendor candidates === Cloud hosting A p=0.226 contract= 59 w= 19 lambda=0.44 Cloud hosting B p=0.145 contract= 91 w= 17 lambda=0.62 Cloud hosting C p=0.246 contract= 50 w= 11 lambda=0.52 Payment gateway A p=0.207 contract= 72 w= 20 lambda=0.68 Payment gateway B p=0.063 contract= 121 w= 12 lambda=0.63 Payment gateway C p=0.274 contract= 48 w= 10 lambda=0.47 Customer CRM A p=0.223 contract= 61 w= 19 lambda=0.68 Customer CRM B p=0.229 contract= 67 w= 11 lambda=0.67 Customer CRM C p=0.071 contract= 121 w= 7 lambda=0.50 HR/payroll SaaS A p=0.148 contract= 93 w= 13 lambda=0.47 HR/payroll SaaS B p=0.129 contract= 92 w= 17 lambda=0.62 HR/payroll SaaS C p=0.262 contract= 49 w= 8 lambda=0.41 Log analytics A p=0.195 contract= 67 w= 12 lambda=0.43 Log analytics B p=0.237 contract= 54 w= 7 lambda=0.35 Log analytics C p=0.146 contract= 92 w= 16 lambda=0.66 Budget sweep range: 262 .. 833 (k$) Economically optimal budget b* = 496 k$ === Optimal plan === Service Vendor Level Spend Exp.loss Cloud hosting C 4 102 36.2 Payment gateway C 4 96 73.8 Customer CRM B 4 119 14.0 HR/payroll SaaS C 4 89 31.0 Log analytics B 4 90 23.1 Total spend : 496.0 k$ Total expected loss : 178.2 k$ Total expected cost : 674.2 k$ === Verification by brute force === DP optimum : 674.2009 Brute-force optimum : 674.2009 Unconstrained match : True Budget-b* loss (DP) : 178.2009 / brute force: 178.2009 Budget-b* match : True === Strategy comparison === Cheapest, no monitoring spend= 262.0 loss= 1241.6 total= 1503.6 vs cheapest: +0.0% Safest vendor, no monitoring spend= 517.0 loss= 486.7 total= 1003.7 vs cheapest: -33.2% Cheapest, level 3 all spend= 467.0 loss= 285.2 total= 752.2 vs cheapest: -50.0% Safest, level 2 all spend= 695.0 loss= 143.6 total= 838.6 vs cheapest: -44.2% Optimized spend= 496.0 loss= 178.2 total= 674.2 vs cheapest: -55.2% /tmp/ipykernel_868/1924791915.py:254: UserWarning: Tight layout not applied. tight_layout cannot make Axes width small enough to accommodate all Axes decorations fig.tight_layout(rect=[0, 0, 1, 0.95])

5. Reading the Graphs
All six panels are drawn in a single figure.
(a) Pareto frontier and optimal budget (top left). The cyan curve is $F(b)$, the lowest achievable expected loss for a given security budget. It falls steeply at first and then flattens, which is the diminishing-returns effect of the exponential risk model. The orange curve adds the spend itself, $b + F(b)$. It is U-shaped. Spending too little leaves large expected losses, and spending too much wastes money on protection that reduces little risk. The gold star marks the minimum of that curve, the economically optimal budget $b^*$. The colored markers are the four naive strategies. Points lying above the cyan curve are dominated, meaning the optimizer can achieve a lower loss for the same spend, or the same loss for less spend.
(b) Strategy comparison (top middle). Each bar is split into spend (teal) and residual expected loss (red). The cheapest-and-unmonitored policy has the lowest spend but the tallest red segment. Uniform monitoring policies shrink the red portion, but they pay the same monitoring price for a low-impact HR system as for the payment gateway. The optimized plan has the lowest total height because it shifts effort to where the loss per monitoring dollar is highest.
(c) 3D cost surface (top right). For the payment gateway vendor in the optimal plan, the surface shows total cost over monitoring intensity $m$ and breach impact $I$. At low impact the surface is lowest at $m=0$, because monitoring is not worth its price. As impact grows, a valley forms and moves toward higher $m$. The red ridge traces the cost-minimizing intensity for each impact. It follows the logarithmic law $m^{*} = \frac{1}{\lambda}\ln\frac{I p \lambda}{w}$ derived in Section 1, rising quickly at first and then slowly. This is the geometric picture of why critical vendors deserve deeper assessment while peripheral ones do not.
(d) 3D bar chart of the optimal plan (bottom left). The horizontal axes are vendors and services, and the height is the monitoring level of the selected vendor. Gray flat bars are rejected vendors. Colored towers are the selected ones, with color following the level. A well-optimized plan has uneven towers: tall for high-impact services and short or absent for low-impact ones. This shows the plan is not a uniform policy.
(e) Heatmap of total cost per level (bottom middle). Each row is a service with its selected vendor, and each column is a monitoring level. Cell values are spend plus expected loss. The cyan frame marks the chosen level, which sits at the cheapest cell of each row. The shape of each row is a convex bowl. Rows for important services have their minimum further to the right.
(f) Cost breakdown (bottom right). Contract cost, monitoring cost, and residual expected loss are stacked per service. High-impact services carry a visible monitoring share, while low-impact services are dominated by the contract cost. Residual loss is intentionally not driven to zero. Eliminating the last fraction of risk would cost more than it saves, which is the central lesson of risk-based vendor management.
6. Conclusion
Vendor risk management is often run as a checklist: every vendor gets the same questionnaire, or the cheapest vendor wins. Framing it as a multiple-choice knapsack shows that:
- The right monitoring intensity depends on impact, breach probability, monitoring cost, and monitoring effectiveness, and it grows only logarithmically with impact.
- Vendor selection and monitoring must be decided together, since a cheaper but riskier vendor may need expensive monitoring that erases its price advantage.
- The Pareto frontier gives a defensible budget conversation. Instead of arguing about a number, you can show exactly how much expected loss each additional dollar removes, and stop at the point where it no longer pays.
The same code extends naturally to more vendors, finer monitoring levels, or additional constraints such as a staff-hours budget, which would simply add another dimension to the DP table.











