## Directed Grid Graphs; All Possible Paths Through Nodes

I have a problem in which I am interested in taking a matrix of positive integer weights, including zero, where the matrix has dimensions nrow x ncol and the columns always sum to the same arbitrary number. I want to search for a list of paths (sets of edges essentially) that traverse through the grid space of the same dimension & create the paths such that the # of edges in a path going through a node is equal to the nodes weight (from the matrix). Ie: if a particular index in my matrix was "3", there would be 3 edges that would run into (and out of) this node.

Some important restrictions. Firstly, The only direction the edges can move is rightward (so vertical edges are disallowed) but only one column distance at a time. I do allow for the edges to go from any row_j (in column_i) to any other possible row_j in column_i+1, so diagonal edges (either upwards or downwards are allowed). Here’s an example of such a solution (it is non singular which is why Im interested in ALL possible paths)

Most importantly, I am interested in two things. First I want all possible paths from this process, and even more critically, I want to minimise the number of possible diagonal edges that my resulting paths will contain.

Any sort of algorithm here to solve this would be hugely helpful.

I have managed to solve the case when I don’t care about the number of diagonal edges, and just want a set of paths that match with the weights. To do that, I used the weights at adjacent columns to generate a Markov transition process. This gave me a series of transition matrices (of length ncol-1) which from there I was able to construct probabilistically what my paths through my weights were.

Let me know if anyone needs any more details/explanations here.

## Finding paths of length $n$ on a directed graph

Suppose I have the following directed graph

g = Graph[{DirectedEdge[v1, v1, a], DirectedEdge[v1, v1, OverBar[a]],     DirectedEdge[v1, v2, b], DirectedEdge[v2, v2, c],     DirectedEdge[v1, v3, OverBar[b]],     DirectedEdge[v3, v3, OverBar[c]]}, VertexLabels -> "Name",    EdgeLabels -> "Index"] 

First of all, I would prefer to label the edges with the tag of the directed edge, but I’m not sure how to do this.

The main question is, can Mathematica give me all possible paths of length $$n$$ on this graph starting from, say, $$v1$$?

## [ Movies ] Open Question : Movies Section: What if Batman & Robin was directed by Tim Burton (Instead of Joel Schumacher)?

If the movie of Batman & Robin (1997) was directed by Tim Burton (Produced, too) instead of Joel Schumacher, what do you think about this cast of characters? Cast: Michael Keaton as Bruce Wayne/Batman (Instead of George Clooney) Marlon Wayans as Dick Grayson/Robin (Instead of Chris O’Donnell) For the villains instead of Mr. Freeze, Poison Ivy, and… Bane Nicolas Cage as Dr. Jonathan Crane/Scarecrow Courtney Love as Dr. Harleen Quinn/Harley Queen And as for the last main character as a heroine character… Alicia Silverstone as Barbara Gordon/Batgirl (Not Barbara Wilson) Any thoughts?

## When using a battlemap, can a lightning bolt be directed between squares to affect both?

Lightning bolt is listed as having a width of 5 feet.

When using a battlemap, can the line of the spell be directed between squares to affect creatures on both sides with full damage?

Does Lightning Bolt affect everyone in its line of effect? suggests this would be true for Pathfinder rules. Its answer suggests that even if the lightning bolt passed a tiny corner of a square – the creature would take full damage. Does this hold true in 5e?

## Shortest path with exactly k edges in a directed and weighted graph big o

how to calculate the big O of Shortest path with exactly k edges in a directed and weighted graph big O

the algorithm is:

## How to find all paths of length up to k between two nodes in a directed graph?

Let’s say I have a directed graph represented as an adjacency matrix, and I’m given two nodes $$u,v$$ and a parameter $$k$$. Let’s also say that the maximal degree of a node in the graph is $$d$$.

What is the most efficient algorithm to find all paths of length $$<=k$$ from $$u$$ to $$v$$?

I know the number of such paths can be calculated efficiently using Dynamic Programming approach, but I’m looking for an algorithm that allows to get a set of actual paths.

It’s clear that such algorithm would have a factor of the number of paths in its time complexity, which has $$k$$ in the exponent, but still, I would like to know what is the best approach for such a problem.

## Path with maximum coins in directed graph

I am trying to solve this question:

A game has n rooms and m tunnels between them. Each room has a certain number of coins. What is the maximum number of coins you can collect while moving through the tunnels when you can freely choose your starting and ending room?

Input

The first input line has two integers n and m: the number of rooms and tunnels. The rooms are numbered $$1, 2, \dots, n$$.

Then, there are n integers $$k_1, k_2, \dots, k_n$$: the number of coins in each room.

Finally, there are m lines describing the tunnels. Each line has two integers a and b: there is a tunnel from room a to room b. Each tunnel is a one-way tunnel.

Output

Print one integer: the maximum number of coins you can collect.

Constraints $$1 \le n \le 10^5, 1 \le m \le 2 \cdot 10^5, 1 \le k_i \le 10^9 1 \le a,b \le n$$

Example:

Input: 4 4 4 5 2 7 1 2 2 1 1 3 2 4  Output: 16 

I was thinking of doing a dfs but it’s unclear to me how to go about it, given the existence of cycles.

## Shortest path using less than or equal to m edges in a directed, weighted graph with negative cycles

I’m solving a problem:

Given a directed, weighted graph $$G$$ that has $$V$$ vertices and $$E$$ edges and a positive integer $$m$$, describe an algorithm that finds the length of the shortest path using less than or equal to $$m$$ edges. Note that the graph may contain negative cycles.

First, I tried Bellman-Ford algorithm, but I cannot deal with negative cycles. Next, I tried one using recursive DFS, but it takes too much time! I think dynamic programming may solve this problem, but I don’t know how to start with DP. Is there any fancy way to solve this problem in short time?

## Identifying useless vertices in a directed graph

I have a randomly generated directed graph with 3 types of vertices: input, output, and the rest (I’ll call them hidden).

A useless vertex is a hidden vertex which:

• can’t be reached from an input vertex, OR
• can’t reach an output vertex.

For example:

• input = yellow/green
• output = blue
• hidden = white
• useless = red border

Note that:

• cycles and self-loops are allowed
• the graph may be disjoint
• inputs and output nodes are known (i.e. you can determine what type of node an edge connects to and from)

So what do you call this type of problem? Is there any algorithm for this?

I’m looking for more information about this. I have a python script which seems to work. I’m just not sure if it will work for all cases since I don’t fully understand it myself. It was a mix of DFS, trial-and-error, manual hand-checking, and a bunch of if statements.

## trouble in distinguishing between syntax directed translation and syntax directed definition

I am currently reading the dragon book ,chapter 2 is confusing me a lot according to it the definition of the two terms are:

syntax-directed translation

syntax-Directed translation is done by attaching rules or program fragments o productions in a grammar

my understanding of this is that in a production within {} we have some rules/program code that is executed(those rules/program are also known as semantic action)

syntax-directed-definition

A syntax-directed definition associates 1.with each grammar symbol, a set of attributes and 2.With each production,a set of semantic rules for computing the values of the attribute associated with the symbols appearing in the production

my understanding of this definition is that with each production we associate a action at the end of tail to compute the value of a attribute(this action are also known as semantic rules)

I have a few doubts regarding the two definitions 1. Is my understanding of this two definition correct?

1. do syntax directed translation and syntax directed definition do the same task using two different ways?

2. Is a syntax directedtranslation scheme same as syntax directed translation?

3. what is the difference between syntax directed translation scheme and just translation scheme?