yohandi
A recent graduate with a strong interest in algorithms and data structures.

[Tutorial] Lagrange Relaxation

In solving a problem, it is often difficult to obtain the optimal solution due to strict constraints, making it computationally expensive. Lagrange Relaxation is a method that loosens some particular constraints of the problem with the objective to optimize the findings. This is done by introducing Lagrange multipliers for those relaxed constraints. The solution to the problem with the relaxed constraints is then used as the boundary (both upper and lower) for the original problem.

The Aliens problem from IOI 2016 brought significant attention for this method, making it also known as Aliens' Trick. Ever since, this method has started to gain popularity among competitive programmers. In this blog, we will delve deeper into this method; especially in solving the Aliens problem. If you are not familiar with the Convex Hull Trick yet, I suggest you to read my blog here.

Motivational Problem: IOI 2016 - Aliens

We have a low-resolution photo of a remote planet's area, which is divided into an

KaTeX can only parse string typed expression
grid consisting of
KaTeX can only parse string typed expression
points that we are interested in. Our satellite, passing over the main diagonal of the grid, can take high-resolution photos of square areas. Each square's opposite corners must be on the grid's main diagonal. The satellite can take at most
KaTeX can only parse string typed expression
high-resolution photos. Our task is to choose up to
KaTeX can only parse string typed expression
square areas to photograph ensuring:

  1. Every cell with a point of interest is captured.
  2. The total number of photographed cells is minimized.

We want to find the smallest possible total number of photographed cells.

Constraints

  • KaTeX can only parse string typed expression
  • KaTeX can only parse string typed expression

Subtasks

no.points
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
1 - 3
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
4
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
5
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
6
KaTeX can only parse string typed expression

On contest score distribution

Naive Dynamic Programming (25 points)

Notice that due to constraint of "each square's opposite corners must be on the grid's main diagonal", we can always interchange the value of

KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
as the new point is a reflection point across the main diagonal. As a result, the order of
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
is irrelevant. For each point
KaTeX can only parse string typed expression
, visualize it as a segment that spans the range
KaTeX can only parse string typed expression
. Consequently, a photo that covers a point
KaTeX can only parse string typed expression
to
KaTeX can only parse string typed expression
will capture point
KaTeX can only parse string typed expression
if and only if
KaTeX can only parse string typed expression
.

Further, this observation indicates that capturing a point

KaTeX can only parse string typed expression
(
KaTeX can only parse string typed expression
) will also encompass point
KaTeX can only parse string typed expression
if
KaTeX can only parse string typed expression
. With that, we may simply discard point
KaTeX can only parse string typed expression
. After such eliminations, all remaining points will have the property: for points
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
(
KaTeX can only parse string typed expression
),
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
.

Let

KaTeX can only parse string typed expression
denotes the minimum cost to cover first
KaTeX can only parse string typed expression
points with at most
KaTeX can only parse string typed expression
photos. Then,

KaTeX can only parse string typed expression

Here is a breakdown of the components:

  • The
    KaTeX can only parse string typed expression
    represents the cost of capturing the first
    KaTeX can only parse string typed expression
    points using
    KaTeX can only parse string typed expression
    photos. Then, we aim to cover the point
    KaTeX can only parse string typed expression
    up to point
    KaTeX can only parse string typed expression
    using
    KaTeX can only parse string typed expression
    photo.
  • The expression
    KaTeX can only parse string typed expression
    calculates the cost of capturing the point
    KaTeX can only parse string typed expression
    up to point
    KaTeX can only parse string typed expression
    using
    KaTeX can only parse string typed expression
    photo.
  • The
    KaTeX can only parse string typed expression
    part is accounted to an overcharging cost due to the overlap between point
    KaTeX can only parse string typed expression
    and point
    KaTeX can only parse string typed expression
    . Hence, it is substracted to correct the cost.

This dynamic programming solution works in

KaTeX can only parse string typed expression
.

Convex Hull Trick (60 points)

We had:

KaTeX can only parse string typed expression

Our dynamic programming can be expressed as:

KaTeX can only parse string typed expression

where:

  • KaTeX can only parse string typed expression
  • KaTeX can only parse string typed expression
  • KaTeX can only parse string typed expression
  • KaTeX can only parse string typed expression

This Convex Hull Trick approach runs about an

KaTeX can only parse string typed expression
armortized time. Note that it is not
KaTeX can only parse string typed expression
as we can use a
KaTeX can only parse string typed expression
instead of a
KaTeX can only parse string typed expression
here, given that the point queries are in increasing order.

Lagrange Relaxation (100 points)

The following solution idea is inspired by and adapted from the official solution.

Denote

KaTeX can only parse string typed expression
to be a function that represents our dynamic programming solution, i.e.
KaTeX can only parse string typed expression
. We want to relax the constraints on the number of photos taken. Let's assume we don't have the
KaTeX can only parse string typed expression
constraint and we want to apply a cost on each photo taken to make up for it. Define
KaTeX can only parse string typed expression
to be
KaTeX can only parse string typed expression
, implying an additional cost of
KaTeX can only parse string typed expression
for each photo taken.

For a

KaTeX can only parse string typed expression
, we may define
KaTeX can only parse string typed expression
to represent another optimization problem that satisfies the following:

KaTeX can only parse string typed expression

Solving

KaTeX can only parse string typed expression
for a given
KaTeX can only parse string typed expression
allows us to obtain the minimum number of photos required to capture all
KaTeX can only parse string typed expression
points and achieve the minimum cost when each photo is charged
KaTeX can only parse string typed expression
cost, let's define it as
KaTeX can only parse string typed expression
.

A function

KaTeX can only parse string typed expression
is said to be convex if it satisfies:
KaTeX can only parse string typed expression
. Alternatively, we may conclude a function
KaTeX can only parse string typed expression
to be convex if it is in the form:

KaTeX can only parse string typed expression

and

KaTeX can only parse string typed expression
is a Monge Array, i.e.
KaTeX can only parse string typed expression
, it holds
KaTeX can only parse string typed expression
. Claim that
KaTeX can only parse string typed expression
is convex; then, we want to prove that
KaTeX can only parse string typed expression
is a Monge Array.

Convexity of f(i, j)

Based on the previous observations, we have

KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
for points
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
when
KaTeX can only parse string typed expression
holds.

KaTeX can only parse string typed expression

It is shown that

KaTeX can only parse string typed expression
is a Monge Array; hence,
KaTeX can only parse string typed expression
is convex.

Given that

KaTeX can only parse string typed expression
is convex, so is
KaTeX can only parse string typed expression
. This implies:

KaTeX can only parse string typed expression

With that we may find

KaTeX can only parse string typed expression
that satisfies
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
. This can be done using binary search with
KaTeX can only parse string typed expression
time complexity (the linear
KaTeX can only parse string typed expression
is obtained from computing
KaTeX can only parse string typed expression
using Convex Hull Trick).

Last, we only need to find the exact value of

KaTeX can only parse string typed expression
, which is our original objective. The interval
KaTeX can only parse string typed expression
signifies the range we are interested in. Considering that
KaTeX can only parse string typed expression
remains constant (slope is constant), we may use linear interpolation to calculate our answer to the original problem. Let
KaTeX can only parse string typed expression
; then,

KaTeX can only parse string typed expression

The overall solution operates in

KaTeX can only parse string typed expression
.

Lagrange Relaxation in General

Basic Idea

  1. Decomposition of the Original Problem: Decompose the original problem into a blend of a simpler optimization problem and an added term to penalize constraint violations.

  2. Lagrange Function Formulation: In the equation below,

    KaTeX can only parse string typed expression
    represents the objective function,
    KaTeX can only parse string typed expression
    denotes the constraint equations,
    KaTeX can only parse string typed expression
    stands for their boundaries, and
    KaTeX can only parse string typed expression
    acts as the Lagrange multiplier:

    KaTeX can only parse string typed expression
  3. Bounds Identification: Establish both the lower and upper bounds wherein the solution to the original problem lies within the defined interval.

Importance of Convexity

  1. Guaranteed Global Optima: Convexity ensures that the solution obtained from the relaxed problem, supported by Lagrange multipliers, offers a valid and global optimum bound.

  2. Optimization Simplification: A convex optimization landscape simplifies the process, reducing potential local minima or maxima that can complicate the search for an optimal solution.

  3. Efficient Solutions: When the Lagrange function is convex, it facilitates the efficient determination of the solution for the relaxed problem. This is important since Lagrange relaxation primarily aims to transform intricate problems into manageable sub-problems.

References

  1. Chethiya Abeysinghe, "IOI 2016 - Solutions," International Olympiad in Informatics.

  2. Mamnoon Siam, "Attack on Aliens," Siam's Blog. https://mamnoonsiam.github.io/posts/attack-on-aliens.html.

  3. upobir, "Quadrangle Inequality Properties," Codeforces. https://codeforces.com/blog/entry/86306.

© 2023 Yohandi. All rights reserved.