# Decision variablesbudget = VectorVariable("budget", len(roads), lb=0.0, ub=max_per_road)# Non-linear models as optyx expressions# These functions work element-wise on VectorVariablesdef repair_model(spend):"""Diminishing returns: Gain = 40 * (1 - exp(-0.5 * spend))"""return40.0* (1- exp(-0.5* spend))def satisfaction_model(pci):"""S-curve: S = 100 / (1 + exp(-0.12 * (pci - 50)))"""return100.0/ (1+ exp(-0.12* (pci -50)))# Build objective: maximize total weighted satisfaction# Vectorized operations:future_pci = current_pci - decay_rate + repair_model(budget)user_sat = satisfaction_model(future_pci)total_utility = traffic @ user_satprint("✓ Symbolic model built with vectorized operations")
✓ Symbolic model built with vectorized operations
6 Inspecting the Automatic Gradient
# Compile the gradient functiongrad_fn = compile_gradient(total_utility, budget)# Evaluate at uniform $1M allocationtest_point = np.ones(len(roads))grad_values = grad_fn(test_point)print("Marginal Utility at $1M uniform allocation:")print("-"*45)for i, road inenumerate(roads):print(f"∂U/∂{road:<10}: {grad_values[i]:>12,.0f}")print("-"*45)print("Higher gradient = more value from additional spending")
Marginal Utility at $1M uniform allocation:
---------------------------------------------
∂U/∂Hwy 101 : 1,619,833
∂U/∂Route 66 : 100,521
∂U/∂I-95 : 2,573,190
∂U/∂Main St : 12,266
∂U/∂Broadway : 227,747
---------------------------------------------
Higher gradient = more value from additional spending
The gradient shows I-95 has 25× higher marginal utility than Main St — the optimizer should allocate accordingly.
I-95 gets the maximum ($5M) — highest traffic volume
Hwy 101 gets significant funding — high traffic and improvable condition
Main St gets $0 — already in good condition (diminishing returns on S-curve)
Route 66 and Broadway get modest allocations
This matches the gradient predictions perfectly. The optimizer uses the exact symbolic derivatives computed by Optyx to navigate the complex objective landscape efficiently.
10 Extensions
This model can be extended with:
Multi-year planning horizons
Different repair action types (patching vs. resurfacing vs. reconstruction)
Stochastic deterioration models
Network connectivity weights (critical routes)
Equity constraints (minimum service levels for all roads)