Please read the new rule regarding the restriction on the use of AI tools. ×

Lagrange Multipliers forМетод множителей Лагранжа для "Core Training" (Code Jam 2017, RoundРаунд 1C)
Difference between en1 and ru1, changed 2,673 character(s)
I found the following derivation using Lagrange multipliers for the solution of theЯ нашел следующее решение с методом множителей Лагранжа задачи [Core Training](https://code.google.com/codejam/contest/3274486/dashboard#s=p2&a=2) problem in Code Jam this year. I liked this approach particularly because I don't get to use Lagrange multipliers very often in programming competitions.↵

Let $ \mathbf{p^0} = (p^0_1, p^0_2, \ldots, p^0_n) $ denote the initial vector of success probabilities that we are given, and let $ \mathbf{p} = (p_1, p_2, \ldots, p_n) $ be an arbitrary vector of success probabilities. Let $ S(i, \mathbf{p}) $ denote the probability of exactly $ i $ cores succeeding given that the success probabilities in $ \mathbf{p} $. Then we are trying to maximise
в этом раунде Code Jam. Мне понравилось это решение в частности потому, что в соревнованиях по программированию очень редко встречается задачи со множителями Лагранжа.↵

Пусть $ \mathbf{p^0} = (p^0_1, p^0_2, \ldots, p^0_n) $ -- заданный вектор вероятностей успеха ядр и $ \mathbf{p} = (p_1, p_2, \ldots, p_n) $ -- другой вектор вероятностей. Пусть $ S(i, \mathbf{p}) $ -- вероятность, что точно $ i $ ядр будут успешными, допустя что ядро $ i $ будет успешным с вероятностей $ p_i $. Тогда мы хотим найти максимум функции

$$ f(\mathbf{p}) = \sum_{i \geq K} S(i, \mathbf{p}) $$↵

subject toс ограничением
$$ g(\mathbf{p}) = \sum_{i} p_i = u + \sum_{i} p^0_i $$↵

By using the Lagrangian method, we get that an optimal solution must satisfyПо методу множителей Лагранжа, мы знаем что любой максимум $ \mathbf{p} $ должен удовлетворить условию 
$$ \nabla_{\mathbf{p}} f(\mathbf{p}) = \lambda \cdot \nabla_{\mathbf{p}} \left(\sum_{i} p_i\right) = \lambda \cdot (1, 1, \ldots, 1) $$↵
or it must be on the boundary (but we'll get to that laterили лежить на границе множества решений (но мы сочтем этот случай попозже).↵

#### 
LemmaЛемма
$$ \frac{\partial f}{\partial p_i} = S(K - 1, \mathbf{p}_{-i}) $$↵
whereгде $ \mathbf{p}_{-i} $ is the vector of probabilities with $ p_i $ removed, i.e-- вектор вероятностей без $ p_i $, т.е. $ (p_1, p_2, \ldots, p_{i - 1}, p_{i + 1}, \ldots, p_{n}) $. That is, the partial derivative of $ f $ with respect to $ p_i $ is the probability that exactly $ K - 1 $ of the cores succeed, not including core $ i $ itself.↵

#### Proof of Lemma↵
This is a somewhat well-known derivation, but I have included it for completeness. By expanding the terms,
Иными словами, частная производная $ f $ по переменной $ p_i $ -- это вероятность, что $ K - 1 $ других ядр будут успешными (без ядра $ i $).↵

#### Доказательство Леммы↵
Разложим члены уравнения:

$$ \frac{\partial f}{\partial p_i} = \frac{\partial}{\partial p_i} \left[ p_i \left( \sum_{i \geq K - 1} S(i, \mathbf{p}_{-i}) \right) + (1 - p_i) \left( \sum_{i \geq K} S(i, \mathbf{p}_{-i}) \right) \right] $$↵
which simplifies toУпростим выражение:
$$ \frac{\partial f}{\partial p_i} = \left( \sum_{i \geq K - 1} S(i, \mathbf{p}_{-i}) \right) - \left( \sum_{i \geq K} S(i, \mathbf{p}_{-i}) \right) = S(K - 1, \mathbf{p}_{-i}) $$↵
(
End proof.)↵

In order to have
Конец доказательства.)↵

Наивное решение
 $ \nabla_{\mathbf{p}} f(\mathbf{p}) = \lambda \cdot (1, 1, \ldots, 1) $, then the most obvious thing to do is to set all the $ p_i $ equal to each other. However this is not possible, since we cannot reduce $ p_i $ below $ p^0_i $. By taking into account boundary conditions, this then gives us three choices for each core $ i $:↵

1. We leave $ p_i $ at its initial value
 -- установить все $ p_i $ равные друг друга. Ну это невозможно потому, что мы не можем уменьшить $ p_i $ меньше чем $ p^0_i $. С учетом граничных условий, мы имеем для каждого ядра $ i $ три вариантов:↵

1. Оставим $ p_i $ как
 $ p^0_i $.↵
2. 
We increaseУвеличим $ p_i $ toдо $ 1 $.↵
3. 
We try to equalise $ p_i $ with the some other $ p_j $ that are not on the boundary.↵

This observation is sufficient to restrict the solution space to the point where we can search over it. (Well, we still need to make some efficiency arguments, like "only increase $ p_i $ up to 1 if it is already big", and "only try to equalize $ p_i $'s that are close to each other", etc..., but you get the idea
Установим $ p_i $ равные каких-то других $ p_j $.↵

Это наблюдение ограничает множесвто решений до такой степени, что мы можем его перебрать. (Ну, еще нужно несколько оптимизаий, например "увеличить $ p_i $ до $ 1 $ только если $ p_i $ уже велик", но это главная идея
.)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English choice 2017-05-02 02:34:16 5 Tiny change: 'g given that the succe' -> 'g given the succe'
en2 English choice 2017-05-01 01:51:06 6 Tiny change: 'e other $ p_j $ that ar' -> 'e other $ \{ p_j \} $ that ar'
ru2 Russian choice 2017-05-01 01:49:40 8
ru1 Russian choice 2017-05-01 01:44:53 2673 Первая редакция перевода на Русский
en1 English choice 2017-05-01 00:41:47 2982 Initial revision (published)