Algorithm to computer the optimal layout of n-ary tree? - algorithm

I am looking for an algorithm that will automatically arrange all the nodes in an n-tree so that no nodes overlap, and not too much space is wasted. The user will be able to add nodes at runtime and the tree must auto arrange itself. Also note it is possible that the tree's could get fairly large ( a few thousand nodes ).
The algorithm has to work in real time, meaning the user cannot notice any pausing.
I have tried Google but I haven't found any substantial resources, any help is appreciated!

I took a look at this problem a while back and decided ultimately to change my goals from a Directed acyclic graph (DAG) to a general graph only due to complexities of what I encountered.
That being said, have you looked at the Sugiyama algorithm for graph layout?
If you're not looking to roll your own, I came across yFiles that did the job quite nicely (a bit on the pricy side though, so I did end up doing exactly that - rolling my own).

Related

How to find the quickest path between many locations which have time restrictions

I am trying to start on a personal research project that I have been brainstorming for a couple of years now. I am aware of graphs and algorithms for finding the best order in which to visit locations for the quickest time. However I am stuck on the next step of my research, are there research papers / algorithms that can solve this problem? Given a starting point and an end point with a number of "waypoints" that have to be visited. And some waypoints have time restrictions such as waypoint three has to be reached by 4:00 pm. So the algorithm will have to first sort the locations based on the time restrictions of them (if there are any) and then find the best order to visit each of the waypoints.
I have looked into many different algorithms/heuristics and I have searched for research papers on this topic but I cannot find anything definitive.
Thank you for the help in advance.
Never done anything like that but... elaborating on what has already told you BlueRaja, I have to say that most likely you already found your Grail (and, maybe, you are just not realizing it).
The time-related problem you are trying to solve looks like just another way to re-state the same space-related path-finding problem you already had to solve for travelling across your graph.
In other words, it looks like you have two graphs to traverse. The first one is the spatial one, represented by the net of waypoints you have to visit. The second one is the temporal (aka "time-related") graph of "time windows" you have to meet in order to not miss any bus/train/ship/airplane/whatever.
As long as I can see, you could use a regular path-finding/graph-crossing algorithm (Dijkstra, A*, contraction hierarchies, etc.) to traverse the spatial graph and re-use the same algorithm (or a very similar one) to traverse the time-related graph as well.
After all, both graphs are just a mathematical representation of a net of "constrains" (the points to be traversed, being them in space or in time) and can traversed using the same algorithm. Most likely, if you look at the code you are using to sort out your "time windows", you will see that it is already quite similar to a very simple space-related graph-traversing algorithm.
The main problem seems to be finding a good representation of the temporal graph (the net of "time windows" you have to respect). Most likely, it will have to be a graph of time-constrained spatial waypoints (spatial points, or "doors", with a "time window" attached to each of them).
In any case, there is no way to solve two problems with one single operation. First, you will have to find the "shortest path" that connects all of your time windows (in the required order) in the temporal graph (that is: you have to sort them out, as you are already doing). Second, you will have to find the shortest paths between any pair of time windows in the spatial graph (and check if the shortest/fastest path is fast enough to meet the next time window).

Random spanning trees of bipartite graphs

I'm working on making some code using metaheuristics for finding good solutions to the Fixed Charge Transportation Problem (FCTP).
The problem I'm having is to generate a starting solution, based on finding a spanning tree for the underlying bipartite graph.
I want it to be a random spanning tree, so that I can run the procedure on the same problem multiple times, possibly getting different solutions.
I'm having some difficulties doing this. The approach I've gone for so far is to make a random permutation of the arcs, then iterate through this list, sequentially putting them into basis if it won't create a cycle.
I need to find a fast method to check if including an arc will create a cycle. I don't want to "brute force" it, since this approach could take a large amount of time, given big problem instances.
Given that A is an array with a random permutation of the arcs, how would you go around making a selection procedure?
I've been working on this for a couple of hours now, and nothing I've tried has worked, most of it being nonsensical when it came to application...
Kruskals Algorithm is used for finding the minimum spanning tree. The fast-cycle detection is not actually part of Kruskals algorithm. The algorithm will work with a data structure that is able to find cycles fast as well as with a slow naive attempt (however the complexity will be different).
However Kruskals Algorithm is on track here, since it usually uses a so called union-find or disjoint-set datastructure for fast detection of cycles. This is the part of the Kruskals Algorithm page on wikipedia that you will need for your algorithm. This is also linked on wikipedia: http://en.wikipedia.org/wiki/Disjoint-set_data_structure
I found Kruskal's algorithm after long hours of research. I only needed to randomize the order in which I investigated the nodes of the graph.

What is a fast algorithm for finding critical nodes?

I'm looking for a quick method/algorithm for finding which nodes in a graph is critical.
For example, in this graph:
Node number 2 and 5 are critical.
My current method is to try removing one non-endpoint node from the graph at a time and then check if the entire network can be reached from all other nodes. This method is obvious not very efficient.
What are a better way?
See biconnected components. Calling them articulation points instead of critical nodes seems to yield better search results.
In any case, the algorithm consists of a simple depth first search where you maintain certain information for each node.
there are several better ways. research is always helpful
but since this is homework, the point of the exercise is likely to be to figure it out yourself
hint: how could you decorate the graph to tell you what nodes depend on what other nodes, and would this information perhaps be useful to spot the critical nodes?

A graph problem

I am struggling to solve the following problem
http://uva.onlinejudge.org/external/1/193.html
However Im not able to get a fast solution.
And as seen by the times of others, there should be a solution of maximum n^2 complexity
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problemid=129&page=problem_stats
Can I get some help?
You can only solve this in exponential complexity, but that's not as bad as it sounds, because in practice you'll be able to avoid a lot of bad decisions and thus reduce the running time of the algorithm significantly.
In short, you have to run a DF search from a node and try to color as many nodes black as you can. If you're at a node that has neighboring black nodes, that node can only be white. Keep doing this for every possibility of coloring a specific node.
If you can't figure it out, then check these two code snippets I found by googling for the problem name: one and two. The authors say they get AC, but I haven't tested them. They look correct however.
It is solving the problem called maximum clique, also called maximum independent set or maximum stable set. It is NP-Complete. Fastest code I know for small graphs is Cliquer: http://users.tkk.fi/pat/cliquer.html
If you are writing your own for educational purposes it is probably most efficient to do a depth first search coloring nodes black one at a time and retreating up the DFS if two black nodes are touching.
The easiest to code solution is implementing a binary counter and trying all 2^n possibilities.
Bron–Kerbosch algorithm
I have solved a similar problem on FaceBook puzzles, I used the B-K algo for that.

Efficient way to recursively calculate dominator tree?

I'm using the Lengauer and Tarjan algorithm with path compression to calculate the dominator tree for a graph where there are millions of nodes. The algorithm is quite complex and I have to admit I haven't taken the time to fully understand it, I'm just using it. Now I have a need to calculate the dominator trees of the direct children of the root node and possibly recurse down the graph to a certain depth repeating this operation. I.e. when I calculate the dominator tree for a child of the root node I want to pretend that the root node has been removed from the graph.
My question is whether there is an efficient solution to this that makes use of immediate dominator information already calculated in the initial dominator tree for the root node? In other words I don't want to start from scratch for each of the children because the whole process is quite time consuming.
Naively it seems it must be possible since there will be plenty of nodes deep down in the graph that have idoms just a little way above them and are unaffected by changes at the top of the graph.
BTW just as aside: it's bizarre that the subject of dominator trees is "owned" by compiler people and there is no mention of it in books on classic graph theory. The application I'm using it for - my FindRoots java heap analyzer - is not related to compiler theory.
Clarification: I'm talking about directed graphs here. The "root" I refer to is actually the node with the greatest reachability. I've updated the text above replacing references to "tree" with "graph". I tend to think of them as trees because the shape is mainly tree-like. The graph is actually of the objects in a java heap and as you can imagine is reasonably hierarchical. I have found the dominator tree useful when doing OOM leak analysis because what you are interested in is "what keeps this object alive?" and the answer ultimately is its dominator. Dominator trees allow you to <ahem> see the wood rather than the trees. But sometimes lots of junk floats to the top of the tree so you have a root with thousands of children directly below it. For such cases I would like to experiment with calculating the dominator trees rooted at each of the direct children (in the original graph) of the root and then maybe go to the next level down and so on. (I'm trying not to worry about the possibility of back links for the time being :)
boost::lengauer_tarjan_dominator_tree_without_dfs might help.
Judging by the lack of comments, I guess there aren't many people on Stackoverflow with the relevent experience to help you. I'm one of those people, but I don't want such an interesting question go down with with a dull thud so I'll try and lend a hand.
My first thought is that if this graph is generated by other compilers would it be worth taking a look at an open-source compiler, like GCC, to see how it solves this problem?
My second thought is that, the main point of your question appears to be avoiding recomputing the result for the root of the tree.
What I would do is create a wrapper around each node that contains the node itself and any pre-computed data associated with that node. A new tree would then be reconstructed from the old tree recursively using these wrapper classes. As you're constructing this tree, you'd start at the root and work your way out to the leaf nodes. For each node, you'd store the result of the computation for all the ancestory thus far. That way, you should only ever have to look at the parent node and the current node data you're processing to compute the value for your new node.
I hope that helps!
Could you elaborate on what sort of graph you're starting with? I don't see how there is any difference between a graph which is a tree, and the dominator tree of that graph. Every node's parent should be its idom, and it would of course be dominated by everything above it in the tree.
I do not fully understand your question, but it seems to me you want to have some incremental update feature. I researched a while ago what algorithms are their but it seemed to me that there's no known way for large graphs to do this quickly (at least from a theoretical standpoint).
You may just search for "incremental updates dominator tree" to find some references.
I guess you are aware the Eclipse Memory Analyzer does use dominator trees, so this topic is not completely "owned" by the compiler community anymore :)

Resources