Generating random roads [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to generate random roads on a swing application. However, I am unable to create the roads such that they do not over-intersect with each other. I mean one road should not cross over another unless they have a common intersection point.
I tried generating random points and connecting them using minimum spanning trees but it does not seem to work.
Do you have any ideas?

I would try the easy thing first: generate a bunch of random roads and keep only those that don't intersect any you've found so far. This has O(n^2) runtime, but it's easy to understand and implement.
In pseudocode:
points = (lots of random points)
roads = empty list
repeat n times:
r = road(pick_random(points), pick_random(points))
if r does not intersect anything in roads list:
add r to roads
This has the advantage over minimum spanning trees that it may generate cycles for you, which would make for a more interesting road network.

Related

LSH implementation for finding clusters [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hie guys.
I am very new to stack exchange and I am currently doing a research on graph theory.
The set of questions I'm going to ask are very introductory since I'm a beginner level programmer (not acquainted with hashing, buckets, vectors etc data structure wise).
My idea is to take in a dataset of the form (timestamp t, node i, node j) which says that there is an edge between i and j at time t. The idea is to search the neighborhood set of each nodes and hash them. If their "vectors" (I don't understand what that is) hash into the same bucket - they are candidates for cluster formation.
But he problem is I want to do experiments and try to run it. But have no idea how do I implement a hash function, and then bucket them together.
I'm not saying help me out with the code. But a pointer (pseudo code) would be very helpful. Like telling me to initialize a hash table etc etc
A hash code is an integer which is calculated from the properties of whatever it is you want to hash. That number is then used as an index into an array.
In this case it seems that you want to use the N dimensions of your vector to calculate this hash code. It's up to you to write a function that calculates that hash codes in a way that vectors that should be clustered all get the same hash code.
Language specific details about hash tables in Java or Python is very easy to find with a web search.

Recursive Division Random Maze Generation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm currently doing a project where I want to randomly generate mazes for a game. After studying performance levels etc for maze generation I've decided to use the Recursive Division method. Whilst the explanation of the algorithm is somewhat understandable I'm struggling to formulate the algorithm in a pseudo format so that I can understand it fully and begin coding it. Can someone help me with a detailed explanation of the process or some pseudo-code? All help is greatly appreciated.
EDIT: From what I understand I will need to decide whether to divide horizontally or vertically. How is this decision made and what is the process of this division with regards to starting point and finishing point?
Begin with an empty field.
Bisect the field with a wall, either horizontally or vertically. Add a single passage through the wall.
Repeat step #2 with the areas on either side of the wall.
Continue, recursively, until the maze reaches the desired resolution.
Jamis Buck on Maze Generation: Recursive Backtracking

Programming and evaluating Dijkstra algorithm [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have to do a project about shortest path algorithm. I am not really a professional I am just a normal student. I have to pick up first a problem ( train route, bus route, any travel route) then choose a suitable algorithm to solve it. Then I have to program it (using coding language java, python..) Then after that I should evaluate it(how speed is the algorithm, time complexity, etc) and if there is a better algorithm that I can be implement instead of what I chose first.
Choosing the problem is the hardest part as I
Don't know what kind of problem I should explore to use of the algorithm!
Regards
Let's take the city where you live in. Take any two bus stations, namely A and B, and the entire commuter network. This network is a graph. Stations are nodes, commuter connections between stations are edges (edge weight = time it takes the bus to travel between two stations).
Say, you want to travel from A to B in the shortest amount of time possible (you wont want to waste time, would you?).
Dijkstras Algorithm has as input the graph representing the commuter network and the node A and is able to deduce the shortest path from A to any other station (which includes the shortest path from A to B).
Does that help you? Wikipedia on Dijkstra has more detailed examples.

Search for a "close point" efficiently [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm asking this because I'm sure there has been brought up before but not sure how to call it.
I need an efficient way to search and store some point in a metric space. Specifically, I need to find the weather at some points in space and time. I have an API to do that, but don't want to make another request if I have already queried in the past about a point a few inches away from the new point and a few seconds before it, as the weather there would be the same.
So when I receive a new point, I need to ask - do I have in the cache a point "close enough" (whose distance from the new point is a below a threshold)?
If I do - take the data associated with that point. Otherwise, cache the new point.
This can be done easily using a serial check but I'm interested in ways to do it more efficiently.
Thanks!
Suppose your thresshold is t, you can split your search space to a grid,
with cells having width and height t.
Every cell will have a list of points that lie in it.
Now when given a new point, you compute which cell it falls into,
let this be the cell [i,j], you check this cell and all of its neigbors
(i.e. 9 cells altogether), whether they contain any points and if they do,
these are your candidates for closer-than-thresshold points.
You will now compute the distance of all of these.
Since the cells are t wide and t high, distance of all points
lying in any other cell is at least t.
You can store the grid cells in a TreeMap, with the comparator based on [i,j] pairs.
(you only store the cells which have at last one point in them).
Wouldn't you know. Going to a search engine called Google and using some time to string words together, you get Nearest neighbor search as the first result. Who'da thunk it.
Maybe what you need is a Voronoi diagram built from your cache points.

Finding inexpensive path that visits all nodes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am currently in the process of going through old programming olympiad questions, and found question 5 rather difficult. The problem is based in some category of graph theory and involves computing the most inexpensive path and visiting all nodes. Full details can be found here: problem
Would it be suitable to use A* search algorithm? What kind of algorithm would you use to solve the problem, which is fast to implement and can solve the problem in the given time period?
As #kiheru stated, A* won't work.
This is the traveling salesman problem, and it's an NP Complete problem. Replace tolls for distance traveled, and you get the same problem. The Traveling Salesman link has several of such algorithms.
Traveling Salesman
You'll find different algorithms depending on the number of cities, but it gets much more computationally expensive as you add cities to where a computer isn't the best choice for an exact solution. There are many different techniques for getting an approximation, but it's not a solvable problem.
If I were to code it, I'd use something called Linguistic Geometry (something I learned in grad school). Basically you treat the nodes as a game board, and you take one step at a time towards the answer you want and evaluate it. This won't solve it, but it will give you a good approximation in a very short amount of time.
This is known as the travelling salesman problem, and is NP-Complete. That means there is no generally-faster method of solving this problem than brute-forcing (well, there is actually a O(2^n*n^2) solution based on dynamic programming). Since you are dealing with only 6 nodes, which is 6! = 720 total possible paths to check, the simplest solution would be to just try every different ordering of cities and record which is fastest.
(Also, contrary to #kiheru's comment above, A* is not a heuristic. It uses a heuristic, but still finds an exact solution to the shortest-path problem. However, either way it does not apply to your problem)

Categories