are there ways to improve the performance of Fortune's algorithm if the sites can only be placed on integer coordinates? - computational-geometry

I'm working on a mobile game for tablets that has players strategizing about the placement of sites in a Voronoi diagram, for background. after 17 sites have been placed the game progresses to it next phase, and my code runs Fortune's algorithm to calculate the cells. all the sites must be integer coordinates between 1 and 8, and it uses Manhattan distance instead of Euclidian. can that property be used to improve the runtime of Fortune's algorithm?

Related

Non-euclidian distance Voronoi diagrams

As a CG novice I was wondering does there exist Voronoi partition that is not based solely on euclidian distance between sites but some other measure, and would such partition still conserve properties of Voronoi diagram?
Reading a textbook I've encountered an example of Voronoi diagram where sites on 2D plane represent football players, and if ball happens to be in Voronoi region of certain player it meant he should go towards it since he's closest to it. Now what if instead of just accounting for the Euclidian distance between players we also considered their speed, with faster players having a larger Voronoi cell.
Would the fact that we lose bisection ruin the structure of Voronoi diagram itself?
Take a look at Power Diagrams and Weighted Voronoï Diagrams. They are generalized Voronoï Diagrams with weights (a circle radius in the case of Power Diagrams) associated with each site.
You can use it to weigh each site with the speed or alter the notion of distance to include speed. By doing so, you will loose the straight line property of bisectors because they might become curved depending on the new distance calculation (look here).
In the case of football players, the new distance function from a point p to a site p_i with player speed v_i is:
d(p, p_i) = EuclideanDistance(p, p_i) / v_i
which can be better interpreted as the time that it takes to reach the point if the player runs at speed v_i. This can produce diagrams like this, where the displayed numbers are the weights 1/v_i:

Fast algorithm for evenly distributing points inside a closed curve with non-overlapping boundaries

The problem is that I need to allocate some people in an office room with arbitrary shape. The requirement of each person is the same: far away from the office wall and other people as much as possible.
Consider the office room as a blank image. So allocating people is like distributing points on the image.
The algorithm I figured out is slow:
for each people
do distance transform of the image
find a point that has the largest distance value
place a people here
mark the pixel where the people is as False in the image
The algorithm does distance transform several times and place people iteratively.
The algorithm becomes really slow when there are lots of people, say 500 since the iterative use of distance transform. I'm wondering if there're better algorithm or any idea I can optimize the current algorithm? Thanks
You may use a centroidal Voronoi tesselation [1,2].
The algorithm works as follows:
(1) distribute the points randomly in the office
(2) Repeat until you are satisfied:
(2.1) compute the Voronoi diagram (see [3]) of the points
(2.2) compute the barycenter of the Voronoi cell of each point
(2.3) move each point to the barycenter of its Voronoi cell
There is an implementation in the GEOGRAM library that I am developping [4]. See also the CGAL library developped by friends of mine[5].
[1] https://en.wikipedia.org/wiki/Centroidal_Voronoi_tessellation
[2] https://en.wikipedia.org/wiki/Lloyd%27s_algorithm
[3] https://en.wikipedia.org/wiki/Voronoi_diagram
[4] http://alice.loria.fr/software/geogram/doc/html/index.html
[5] http://www.cgal.org

Fire Departments covering area

Given a set of points (GPS coordinates), and a polygon that contains all those points, can one determine how well those points are covering the area or what the longest distance from any location within the polygon to the nearest point is?
For example, if I have all fire departments within the city boundary of New York, I want to know how long a fire truck has to drive (in case of an emergency) in the worst case.
Any ideas on what the name of this problem is or what this problem can be reduced to? Or are there any existing algorithms for that?
Thank you :)
First construct the Voronoi diagram of the set of sites (GPS coordinates). The Voronoi diagram is a data structure representing a partition of the plane into cells, one cell for each site, such that each site's cell consists of all the points closer to that site than to any other site.
Constructing the Voronoi diagram can be done in O(nlog(n)) using Fortune's sweep-line algorithm where n is the number of input sites.
Then iterate over the Voronoi cells. Each cell is a polygon. For each cell compute the distance between the cell's site and each of the polygon's vertices. The longest distance between a site and a vertex of the site's cell is the longest distance one would have to walk in order to reach the site.
The running time of the algorithm is O(nlog(n)) as the second phase of the algorithm (iterating over the vertices of each Voronoi cell) requires only linear time. This is because the total number of vertices in the whole diagram grows linearly with the number of sites. Namely, it's not too difficult to show using Euler's formula for planar graphs that the total number of Voronoi vertices is bounded from above by 2n-5.
You can find some open source implementations of Fortune's algorithm on the web. This one for instance.

Algorithm to minimize vertex distances - Dwarf Fortress

I play Dwarf Fortress game. And the main challenge for me is to design layout of the fortress efficiently. Meaning, that each industry flow should be as dense as possible, to minimize the travel distances.
An example could be food industry . Each grey ellipse represents a single building. Each white rectangle represents product from the building.
My goal is to find algorithm which would distribute the buildings on 2D grid in such manner that distance between those building is minimal in the sense how they are connected. Meaning that fishery and loom can be far apart, but loom and farmer's should be as close as possible.
At the moment I have considered using some ready software, to simulate the layout, but some tips for algorithm would be fine.
Currently I'm considering some force-directed algorithm, but I'm not sure about the discrete grid requirement.
Formalization of question: Is there a Force Draw Graph algorithm which works in discrete coordinates?
UPDATE: I have found implementation of the Force draw algorithm in AS3 (the web contains JS version too). I will try to convert it to discrete version. But I have some doubts it will work...
UPDATE2: Some further restrictions were requested in comments. Here they are:
Each building occupy single cell on virtual grid. Buildings can be on adjacent cells. Buildings cannot stack/overlap.
(PS: In game, each building has deifned size, usually 3x3, but I want to keep the problem more general, to allow for more approaches).
You are pretty much trying to solve an instance of a floor-planning problem where you are trying to minimize the total "connection" length. Most of these problems are instances of NP-hard problems, some of them have pseudo-polynomial run-time algorithms.
There is a special case you might be interested that is actually fully solvable in polynomial time: if the relative positions of the "boxes" or buildings you want to place are known ahead of time.
For full details on how to solve this particular case, please refer to this tutorial on geometric programming from Stanford, chapter 6, section 6.1 the first example entitled "Floor planning." Another website also includes matlab code that implements and solves the problem (under chapter 8 Geometric Programming.)
So I've managed to do some code which aproximates solution of this problem. It's not a top class product but it's working. I plan to do some updates over time, but I don't have any time frame set.
The source code is here: https://github.com/sutr90/DF-Layout
My code uses Simulated Annealing approach. Where cost function is based on total area, total length of edges and overlap. To measure distance, I use taxi-cab metric, but that is a subject to change.

Nearest trio of neighbours for non-intersecting ellipses

I'm working on a problem which is to find the closest trio of neighbours for a set of arbitrarily placed non-intersecting ellipses. As a new user I'm not allowed to include image tags but I've included the URL at the bottom of the page as I always think I'm better able to explain myself with visual aids. The picture demonstrates what I mean with Apollonius circles connecting the 3 nearest ellipses to one another.
So far I have tried using the minimum distances between the ellipses and modifying Delaunay Triangulation, via incremental and sweepline methods, used various techniques involving in circles of triangles formed between every 3 ellipse configuration etc, and attempted to estimate the neighbours with bounding boxes, and have completely run out of ideas of how to actually get this working efficiently
Although I have worked out a solution it involves exhaustively searching and comparing every trio of ellipses with every other ellipse and has a time complexity of n(n-1)(n-2)/3!. And on top of that each calculation is done iteratively rather than algebraically.
Would anyone even have an idea of how to go about this that could be done algebraically and at lower then a n^2 time complexity?
Even a suggestion of a technique would suit me to have a try at, because right now I've been working at it for nearly 3 weeks and really am no closer to a decent answer.
If you calculate a Voronoi diagram for your ellipses, then your circles center points would be placed at the intersection of the diagrams.
http://ima.umn.edu/nuggets/voronoi.html
You could pack your ellipses into an R-tree based on their bounding boxes. The R-tree is a binary-tree-like data structure for spatial objects, and supports efficient nearest-neighbour and kth nearsest neighbour queries via traversal.
For large data sets with many ellipses, use of an R-tree should reduce the number of distance tests significantly, only scanning a subset of the tree in the neighbourhood of the query.
Hope this helps.

Resources