I have a bunch of nodes that may have dependencies, for example A, B, C, with connections A <- B, and B <-C. I would like to lay them out in a list (listview/treeview in a gui), and draw a nice diagram showing the relations in one column. I am thinking of something like what some git tools give you.
(See this thread for more examples).
I managed to sketch my own algorithm for this, but I'm not sure I got all corner cases. This seems to be a Solved Problem, so I thought I'd ask here for any standard algorithm. My requirements are:
Lines can leave and arrive at each row.
Lines may pass by a row.
The rows have a natural order. For now, the dependencies only go in one direction (later lines may depend on previous ones), but I'd like to drop that requirement if possible. (My made up algorithm doesn't allow that.)
I don't need the lines to merge as in the above image. If several lines arrive at or leave from the same point, they may merge for cosmetic reasons. I don't want to merge a passing with an arrival though, as in line 3 in above image. (So there would be two passings, and one end point there.)
Again, for cosmetic reasons, the algorithm may "compactify" the tree, and bend the lines to save space. But it would also suffice if it only had straight lines.
I want to start with the list of dependencies, and get out instructions what to draw in each cell to create the tree.
Any references / code examples for such an algorithm? Of course there's the source of various git clients, but they do things slightly differently to what I'm looking for (I have no merges).
Related
I was wondering if there's an efficient and easy way to determine waves in MQL4, just like zigzag indicator does it.
I was asked to help automate indicator, for that I need to determine 'waves', essentially max and min of a graph over some period of time (which is vague and all relative).
I don't have a clear image of how I want an indicator to work, but it would be something like that:
Find the last wave, i.e. where the direction of price last changed (neglecting the noise), and then for example reflect it with a trend line.
Is it possible to use zigzag structure to find that point, where direction changed. (Possibly not the only one, might need to find more that just the last point, but the preceding one. So i will want to adopt the algorithm)
I know it's a while since you asked this question and you probably already have an answer, but if not...
I dislike Zigzag and have not found a way to do what I want to do with it, so I will the last part of your questions with no, and believe me I tried.
The way I prefer it is to find bars that conform to the classic definition of fractals/swing points (i.e. a high with two lower highs on either side, or a low with two higher lows on either side), then try to make up for the shortcomings. E.g. Often there will be two high fractals/swings/waves in a row without an intermediate low fractal/swing/wave. So I add the best intermediate low point as a wave, or remove one of the highs (E.g. if the first one wasn't as subjectively significant). Some of the swing points that are identified are 'noisy', to use your term, and not ones that a human trader would have picked. So these need to be dealt with and so on. If you go down this route it is a long one, computers make many mistakes identifying appropriate swing points, so unfortunately not what I would call easy, but it is accurate, and how many easy indicators are there that actually make money over the long run?
Trying to implement Needleman-Wunsche algorithm for biological sequences comparison. In some circumstances there exist multiple optimal edit paths.
What is the common practice in bio-seq-compare tools handling this? Any priority/preferences among substitute/insert/deletion?
If I want to keep multiple edit paths in memory, any data structure is recommended? Or generally, how to store paths with branches and merges?
Any comments appreciated.
If two paths are have identical scores, that means that the likelihood of them is the same no matter which kinds of operations they used. Priority for substitutions vs. insertions or deletions has already been handled in getting that score. So if two scores are the same, common practice is to break the tie arbitrarily.
You should be able to handle this by recording all potential cells that you could have arrived at the current one from in your traceback matrix. Then, during traceback, start a separate branch whenever you come to a branching point. In order to allow for merges too, store some additional data about each cell (how will depend on what language you're using) indicating how many different paths left from it. Then, during traceback, wait at a given cell until that number of paths have arrived back at it, and then merge them into one. You can either be following the different branches with true parallel processing, or by just alternating which one you are advancing.
Unless you have an a reason to prefer one input sequence over the other in advance it should not matter.
Otherwise you might consider seq_a as the vertical axis and seq_b as the horizontal axis then always choose to step in your preferred direction if there is a tie to break ... but I'm not convincing myself there is any difference to the to alignment assuming one favors one of the starting sequences over the other
As a lot of similar algorithms, Needleman-Wunsche one is just a task of finding the shortest way into a graph (square grid in this case). So I would use A* for defining a sequence & store the possible paths as a dictionary with nodes passes.
Are there any recommended algorithms for placing circuitry?
Restrictions:
Only perfectly vertical/horizontal lines
Can cross at right-angles, but can't run over one another in parallel.
Input:
A set of input points with output points defined. These points have a radius in which no other circuit wire can pass, except for the one going to it.
A bit left field, but check out the open source Graphviz tool. It uses some kind of spring like algorithm from memory to place nodes without overlapping connections. Not sure how suitable it would be for circuitry though: http://www.graphviz.org/Gallery/twopi/twopi2.html
The Zipper data structure is great when one wants to traverse a tree and keep the current position, but what data structure one should use if they want to track more then one position?
Let me explain with examples:
Someone on the #haskell channel has told me that zippers are used in yi editor to represent
the cursor position. This is great, but what if you want to have two
cursors. Like if you want to represent a selection, you need to know the beginning and
the end of the selection.
In the Minotaur example on wikibooks, they use Zipper to represent Minotaur's position inside the labyrinth. If I wanted to add enemy into the labyrinth, representing their position with a Zipper would make as much sense.
Last one is actualy from my mini project where it all started: As part of learning Haskell I'm trying to visualize a tree structure using cairo and gth2hs. This has gone well so far but now I would like to select one or more of the nodes and be able to e.g. move them around. Because there can be more then one of the selected nodes I can't just use
the Zipper as defined in text books.
There is a trivial (naive?) solution, similar to the one they had used in early versions of XMonad which involves finite maps as explained here.
That is, e.g. in case of my example project, I would store the selected nodes in an indexed map and replace their representation in the main structure with the indices. But this solution has plenty of disadvantages. Like the ones explained in the link above, or say, again in case of my example, unselecting all the nodes would require searching the whole tree.
Oleg's work on "concurrent" zippers via delimited continuations is the main reference.
See this paper . I seem to recall reading somewhere that the second derivative has two holes, which is probably what you want.
I was wondering, which are the most commonly used algorithms applied to finding patterns in puzzle games conformed by grids of cells.
I know that depends of many factors, like the kind of patterns You want to detect, or the rules of the game...but I wanted to know which are the most commonly used algorithms in that kind of problems...
For example, games like columns, bejeweled, even tetris.
I also want to know if detecting patterns by "brute force" ( like , scanning all the grid trying to find three adyacent cells of the same color ) is significantly worst that using particular algorithms in very small grids, like 4 X 4 for example ( and again, I know that depends of the kind of game and rules ...)
Which structures are commonly used in this kind of games ?
It's always domain-dependent. But there's also two situations where you'd do these kinds of searches. Ones situation is after a move (a change to the game field made by the player), and the other would be if/when the whole board has changed.
In Tetris, you wouldn't need to scan the whole board after a piece is dropped. You'd just have to search the rows the piece is touching.
In a match-3 games like Bejeweled, where you're swapping two adjacent pieces at a time, you'd first run a localized search in each direction around each square that changed, to see if any pieces have triggered. Then, if they have, the game will dump some new, random pieces onto the board. Now, you could run the same localized search around each square that's changed, but that might involve a lot of if statements and might actually be slower to just scanning the whole board from top left to bottom right. It depends on your implementation and would require profiling.
As Adrian says, a simple 2D array suffices. Often, though, you may add a "border" of pixels around this array, to simplify the searching-for-patterns aspect. Without a border, you'd have to have if statements along the edge squares that says "well, if you're in the top row, don't search up (and walk off the array)". With a border around it, you can safely just search through everything: saving yourself if statements, saving yourself branching, saving yourself pipeline issues, searching faster.
To Jon: these kinds of things really do matter in high-performance settings, even on modern machines, if you're making a search algorithm to play/solve the game. If you are, you want your underlying simulation to run as quickly as possible in order to search as deep as possible in the fewest cycles.
Regarding algorithms: It certainly depends on the game. For example for tetris, you'd only have to scan each row if it has the same color. I can't even think of something that would not equal the brute force approach in this case. But for most casual games brute force should be perfectly fine. Pattern recognition should be negligible in comparison to graphics and sound processing.
Regarding structures: A simple 2D-Array should suffice for representing the board.
Given the average computer speed these days, if it's real-time as the user is playing the game, it probably won't matter (EDIT: for very small game boards only). Certainly, it would depend on the complexity of the game logic, but also how fast the code is going to run on the target machine (i.e., is this a JavaScript web page game, or a Windows app written in C++).
If this is for something like simulating gameplay strategies, then use an algorithm that's more efficient.
A more efficient strategy could involve keeping track of incremental changes to the game board, instead of re-scanning the whole board every time.