Solution (source code)

= Solution

The objective is <strictly convex>, so the minimizer is unique. The <Slater condition> makes the <Karush-Kuhn-Tucker conditions> necessary and sufficient. Absorb the box constraints into the <Euclidean projection onto a convex set> and attach a scalar multiplier $\nu$ to $a^Tx=b$. Stationarity over the box is equivalent to
$$
x^*=P_{[0,1]^n}(y-\nu a),
$$
while primal feasibility requires $a^Tx^*=b$. Coordinatewise, these conditions are
$$
\boxed{x_i^*=\min\{1,\max\{0,y_i-\nu a_i\}\}},
\qquad
\boxed{\sum_{i=1}^na_i
\min\{1,\max\{0,y_i-\nu a_i\}\}=b}.
$$
They are also sufficient because they minimize the <Lagrangian> over the box and satisfy the equality constraint. Thus the <projection onto a box-constrained hyperplane> reduces to solving the displayed one-dimensional continuous, nonincreasing equation for $\nu$. The multiplier need not be unique on a flat interval, but the projected vector is unique.