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.
Related
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 5 years ago.
Improve this question
I'm developing this for Bukkit, but I am open to porting a java-only solution.
Now, I have a character in a room with an opening exposed to the outside for radiation to seep in like this:
(sorry for terrible paint skills) In this picture the algorithm should return false, however if that white bit was covered, it would return true.
I need a way of detecting whether the character is inside a room or not. Please remember that a room can be any size, and does not have to be a cuboid.
The way I'd like it to work is that I'd have an arbitrary position above the roof, and if this maze algorithm would be able to reach this position, I'd know that the character is not completely covered.
EDIT: Actually if the exit was 20+ units away, I wouldn't mind the algorithm timing out.
This is not an answer per se, but it may be a good point to move on from.
The definition for room:
a part or division of a building enclosed by walls, floor, and
ceiling.
The definition for building:
a structure with a roof and walls
The definition of a structure:
a building or other object constructed from several parts
Can you see how poorly defined these are? (The definitions for building and structure are recursive!) Until you can come up with a clear cut, black and white definition for what you consider to be a room, you (and us) have very little hope of coming up with a good solution.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am trying to find a way to calculate the strength of a hand, specifically how many unique hands (of the 169 starting hands) have a higher chance of winning at showdown given a complete or incomplete board (holdem).
I've tried to do this a few ways and have been somewhat successful but it takes an obnoxious amount of time for my program to run given that i'm essentially branching out for every possible hand combo, and comparing aggregate results for every scenario to find how many hands are better than hero's. TLDR it's terribly inefficient and it takes an unrealistic amount of time to run.
However there are tools like this one http://www.cardplayer.com/poker-tools/odds-calculator/texas-holdem that seem to do the calculation a lot faster. The above program seems to do calculations for all possible future board combinations, so it can give you the better hand for incomplete boards. Although, for my particular program i'd like to find the number of hands ahead of hero's at any given point, which would require me to run the program above for each of the 52*51 non-unique starting hands, and find my hand's place among the rest and once the number of better hands have been gotten, i'll have to reduce those to unqique starting hands (ie 8c7h and 8h7c would be reduced to 87o)
So my question is, are there any tools/frameworks/references (preferably in Java) out there for calculating the strength of hero's hand vs an anonymous hand given any complete or incomplete board that also doesn't take a day to run?
I am not much of a poker kind of guy, but you may find ThePokerBank site interesting, what about a whole course dedicated at poker theory from MIT, a bonus infographic to help you out too.
There are different strategies that you can take to try to tackle this issue, all of them involving quite some knowledge on Statiscal analysis, I would say that one of the reason other poker algorithm work a bit better is that they are using a form of vectorization math instead of a series of for loop. I know that language like octave/MatLab/R take this strategy to do bulk operation.
Good luck and have fun!!
This thread has much information Stack Overflow Evaluation Algorithms
Also at Code Project and a tutorial on an algorithm and Java source: at Github and in different languages at rosettacode.
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.
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)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm working on a academic project: writing a library for finding the shortest path on large, weighted, directed graphs.
Specifications are:
The example data set is a graph of 1500 vertices with an average of 5.68 edges per node. Specification may vary up to 20.000 nodes.
Moreover I'm working in a cpu / memory bound, environment: Android.
Edge weight is not trivial, nor costant. It depends on variable states of the graph.
We must work offline.
I face several difficulties:
I need an efficient way to store, retrive and update data of the graph. Should I use a SQLite object with queries from the Java classes, a large custom java object on the heap, or what? I think this is the most performance-critical aspect.
I need an efficient way to implement some kind of short path algorithm. Since all the weight are positive, should I apply the Dijikstra algorithm with an ArrayList as the container of the visited nodes?
Is this a good case to use the NDK? The task is CPU intensive, but it also make frequent access to the memory, so I don't think so, but I'm open to contribution.
Always remember that resources are scarce, ram is insufficient, disk is slow, cpu is precious (battery - wise).
Any advice is wellcome, cheers :)
For these many nodes I would suggest to aquire some Cloud-computing service and let the android app communicate with it.
How about Hadoop's MapReduce on Amazon's Cloud, there are many graph frameworks such as Mahout and it is really fast. And at least very scalable if there would be more nodes and edges.
linked list is best data structure for storing big sparse graphs.