Sonntag, 26. Mai 2013

Using R to visualize geo optimization algorithms

Site optimization is the process of finding an optimal location for a plant or a warehouse to minimize transportation costs and duration. A simple model only consists of one good and no restrictions regarding transportation capacities or delivery time. The optimizing algorithms are often hard to understand. Fortunately, R is a great tool to make them more comprehensible.


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 Taxicab distance and Euclidean distanceWe 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:
  1. set an initial warehouse location: $x_{start}$ and $y_{start}$ 
  2. 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:






Kommentare:

  1. It looks like there are some errors in the definition of x and y coordinates. They seem to be exchanged, which is not by itself an error but it is when computing distances. Can you look at this?
    Luca

    AntwortenLöschen
    Antworten
    1. Thanks for your feedback! I fixed the definition of d(a,b)

      Best
      Johannes

      Löschen
  2. To transform from decimal degrees to radians you must multiply by pi/180 not pi/360!

    AntwortenLöschen
    Antworten
    1. ... of course! Bad typo - it was done right in my code.

      Löschen