开发者

Optimizing a 2 parameter distance function on line segments (ACM ICPC Regionals Elim.)

开发者 https://www.devze.com 2023-01-22 23:20 出处:网络
This problem is a sub开发者_运维问答problem of a problem posed in the ACM ICPC Kanpur Regionals Elimination Round:

This problem is a sub开发者_运维问答problem of a problem posed in the ACM ICPC Kanpur Regionals Elimination Round:

Given 2 line segments bounded by the 2D points (Pa, Pb) and (Pc, Pd) respectively, find p and q (in the range [0,1]) that minimizes the function

f(p, q) = D(Px, Pa) + D(Py, Pd) + k D(Px, Py) where 
                                2 <= k <= 5, 
                                Px = p Pa + (1-p) Pb, 
                                Py = q Pc + (1-q) Pd and 
 D(x, y) is the euclidean distance between points x and y

(effectively, Px and Py are points on the line segments and the function encodes the cost of going from Pa to Pd through a connecting link of a cost that is k times the euclidean distance)

Some observations regarding this function:

  1. Parallel line segments will always cause atleast one of p and q to be either 0 or 1
  2. Intersecting line segments will always cause p and q to locate the point of intersection of the line segments (the triangle inequality can be applied to prove this)

The question: In the general case where the lines are inclined and potentially separated, how do we minimize this function?


I think you should be able to take the partial derivatives of f with respect to p and q, set them to 0, and solve for p and q. That will give you a (local) minimum. If the minimum has 0 <= p <= 1 and 0 <= q <= 1, you're done, otherwise check the four endpoints (p=0,q=1, and so on).

I'm not positive that this will handle all degenerate conditions, but it should be a good start.

0

精彩评论

暂无评论...
验证码 换一张
取 消