Блог пользователя ClosetNarcissist

Автор ClosetNarcissist, история, 13 месяцев назад, По-английски

Given n 3D vectors e_i, 1 <= i <= n, and a 3D vector vector v, find the value of the coefficients c_i such that v is described as a linear combination of the n vectors

v = c_0*e_0 + c_1*e_1 + ... + c_n*e_n

but the twist is to calculate c_i such that abs(c_i) <= a_i, where a_i will be given, 1 <= i <= n.

Print the coefficients c_i or print that it's impossible. (If possible print the answer that minimizes the sum of c_i). I have been pondering this question for quite some days and I still have zero idea how to approach this, will it be DP or greedy with some heuristics. I did not add any constraints since I don't really know what the time complexity will be. Any help will be appreciated. Thank you.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

This problem can be formulated as a linear programming task:

We aim to find coefficients c_i such that
     v = c₀·e₀ + c₁·e₁ + ... + cₙ₋₁·eₙ₋₁
with constraints |cᵢ| ≤ aᵢ, and minimize the objective S = c₀ + c₁ + ... + cₙ₋₁.

This fits well into the standard LP form: - The objective is linear (minimize the sum of cᵢ), - There are equality constraints to match all 3 coordinates of v, - And bounds: -aᵢ ≤ cᵢ ≤ aᵢ.

We can solve it using scipy.optimize.linprog (with HiGHS method). The matrix of constraints is just the transpose of the list of 3D vectors.
If linprog returns a valid solution under the given bounds, we print the coefficients; otherwise, it's impossible.