**The basic math**

A basic contineous optimization problem is to deliver goods to $n$ customers. Every customer has a individual demand $a_j$ and is approached directly from our warehouse. The single routes have a length of $d_j$. The objective function to be minimized is:

$$min(\sum^{n}_{j=1} a_j \cdot d_j)$$

How can on calculate distances? Typical distance measures for flat surfaces most of you are probably familiar with are

How can on calculate distances? Typical distance measures for flat surfaces most of you are probably familiar with are

*Taxicab distance*and*Euclidean distance.*We will calculate spherical distances to get a better solution for large routes: $$\\d_{a,b} = arccos[sin(y_a)\cdot sin(y_b)+cos(y_a)\cdot cos(y_b)\cdot cos(x_a-x_b)] \cdot R\\$$*R*denotes the Earth radius: ~ 6,370 km.**Keep in mind:**- ...To use geographical coordinates in the form of decimal degrees
- ... To transform them to radian units (by multiplying pi/180).

**How to optimize**

We will use an iterative way for optimizing:

- set an initial warehouse location: $x_{start}$ and $y_{start}$
- for every iteration the current warehouse location $(x_w, y_w)$ is calculated by: $$x_w=\frac{\sum_{j=1}^{n}{a_j \cdot \overline{x}/d_j}}{\sum_{j=1}^{n}{a_j/d_j}} \quad \quad y_w=\frac{\sum_{j=1}^{n}{a_j \cdot \overline{y}/d_j}}{\sum_{j=1}^{n}{a_j/d_j}}$$

**Results**

Red circles are customer locations. Their surface area represents the individual demands. The single iterations start with dark blue circles and end with the final warehouse location, colored in green.

Click here to download the data file. Below the code:

Click here to download the data file. Below the code: