| Data: Head model, ROI definition, desired directional field, n | |
| Result: Optimal stimulus pattern with at most n current sources | |
| 1 | ẑ ← z0 // Initialize objective |
| 2 | ℒ ← {ℱ0} //Active set |
| 3 | t ← 0 |
| 4 | while ℒ ≠ ø do |
| 5 | determination of r // Next branch |
| 6 | ℒ ← ℒ – ℱr |
| 7 | determination of p(r) |
| 8 | determination of branching |
| ℱr ⊂ ℛ1 ⋃ ℛ2 … ℛp(r) | |
| 9 | for i ← 1 to p(r) do |
| 10 | ℱt+i ← ℱr ⋂ ℛi |
| 11 | calculation of (xt+i, zt+i) |
| 12 | if zt+i > ẑ then |
| 13 | if xt+i ∈ ℱ then |
| 14 | ẑ ← zt+i |
| 15 | else |
| 16 | ℒ ← ℓ + ℱt+i |
| 17 | t ← t + p(r) |