How can you describe this kind of graph? - networking

I know for sure that this is a simple directed graph. But I cannot say that this is a ring graph/network, because node 3 has a degree of 4. But as I imagine this, you cannot go to node 7 from node 3 if the preceding node is node 2, and you cannot go to node 4 from node 3 if the preceding node is node 6. That means the only way to traverse this graph is to start from one node and then go to the adjacent node that has a number greater than the current node (except for node 7 to node 1). What kind of graph is this? Thanks in advance!
http://img231.imageshack.us/img231/5492/graphl.jpg

Yes, it is a simple directed graph. It is also an Eulerian graph with exactly one Eulerian circuit. That's probably its most interesting property.

You could redraw the graph as a standard Eulerian Graph without the addition rules by dividing node 3 into two nodes, node 3 and node 6A, where 2-3-4 and 6-6A-7 are the only valid paths through the two nodes. At this point the graph would look like a figure eight. The nodes could then be rearranged in a circle while maintaining the topology.

Related

Graph traversal with a minimum number of "steps" (steps based on edge parameters)

There is a bidirectional graph. The graph edges have parameters (let it be a color). A step is a transition from one vertex to another. If at a certain moment the already visited vertices have unvisited edges with the same parameters, then in 1 step it is possible to go through all the edges with the same parameters. Edges can have multiple parameters.
I need to find a traversal algorithm to visit all the vertices with a minimum number of "steps".
Example graph (1 and 2 are starting (visited) vertices):
graph example
Expected result: 6, 3 and 5, 4 and 7 (3 steps)
I want to iterate over all graph traversal options to find the best. But maybe there is any better algorithm for this task? If not, what is the best way to find all traversal options?

How to efficiently determine which nodes can leave a graph while maintaining connectedness?

Suppose I have a graph with node weights, for example:
If a node has weight -1, it is "happy". If a node has positive weight, it is "unhappy", and wants to leave the graph.
How do I efficiently calculate which nodes I should kick out of the graph in order to minimize unhappiness (i.e., total graph weight), while making sure that the graph remains connected?
For instance, in this case, I can't get rid of the 10, 8, and 10 nodes, since that would disconnect the graph. The optimal solution in this case seems to be 10 + 8 + 5 = 23.
Small correction : the optimal solution in your example is 2 + 10 + 8 + 5 = 25. Nothing prevents you from removing all but connecting "unhappy" nodes.
On the discussion about bridge : bridge are edges, here you remove nodes. This makes a big difference : when removing edges, the nodes remains, and thus you cannot remove too many of them. When removing nodes, their attached edges are removed too, and you can be much more aggressive. So much that you only need to keep path between clusters of "happy" nodes. Everything else is removed.
How do you do that ?
Replace each cluster of happy nodes (happy nodes that are connected) by one happy node. (keep track of the replaced nodes)
For each edge between an happy and an unhappy node in the starting graph, make an edge between the node representing the cluster of the happy node, and the same unhappy node. The weight is the same as the original weight.
For each pair of happy nodes (representing the original clusters), find the shortest path between them. If this path pass through a third happy node, ignore it. Else, make an edge between the two happy nodes, with a weight equal to the total weight of the shortest path. (keep track of the nodes making the path)
Remove every unhappy node
Find the MST (minimum spanning tree) of the graph. Only keep the selected edges.
Replace each remaining edge of your graph by the path it represents
Replace each happy node by the cluster of happy nodes it represents
I tried to keep this solution in a high language, I can edit it to be more rigorous if needed.

Implementing BFS on same level vertexes of a graph data structure

I'm trying to understand graphs in data structures and got struck here in understanding. can anyone help in understanding this approach. Graphs allow multiple vertexes to connect to any arbitrary vertex without any constraints. while inserting edges, it is possible the vertex to be connected may be on the same level or at any below levels.
In the above figure, BFS through graphs gives 5,6,7 in one and 5,7,6 in another. There is no constraint to get the same level vertexes on graph. How is this identified?
Please let me know as none of the resources point that differenece. Both 6,7 are unvisited from 5,if one refers to 7 and adds to queue(image-1). BFS will be violated.
EDIT:
In the above BFS Example image we have 5 vertexes and if we start from 5 we can either traverse to 6,7 as adjacent nodes. if we are trying to implement BFS here then we can either add 6 or 7 to queue but 7 is the valid one as it is at the same level. How is this identified?
The two drawings you posted show identical graphs: the same three vertices are connected with the same three edges. Graphs don't have levels. They don't keep track of any type of edge ordering, nor the horizontal or vertical layout of the vertices when the graph is drawn.
A BFS starting from vertex 5 could visit either 6 or 7 next. Either order is a valid BFS traversal.

Sequence of number of vertices in a graph

I want to generate a sequence of the number of vertices in all graphs which each edge has the same number of leaving edges. I dont have to generate the whole sequence. Let's say the first 50 if exists.
I want:
Input: the number of edges leaving each vertex
Output: a sequence of the number of vertices
So far, I have looked at complete graphs. Complete graphs with n vertices always have n-1 edges leaving each vertex. But there are other kinds of graphs that have this property. For example, some polyhedrons, such as snub dodecahedron and truncated icosidodecahedron have this property.
How should I approach my problem?
I think you mean regular graphs:
http://en.wikipedia.org/wiki/Regular_graph
http://mathworld.wolfram.com/RegularGraph.html
I made a regular graph generator which isn't flawless by the way:
once you generate the nodes, say from 1 to n. You want regularity r.
For node 1, make connections to the following nodes until you reach degree r for node 1.
For node 2 you already have degree 1 (because of node 1), you connect again to further nodes until you reach degree r for node 2 too. And this way till the last node.
The flaw is that you can't define an r-regular graph for any number of nodes. The algorithm mentioned doesn't detect that, so some errors may occur. Also, this isn't a random r-regular graph generator, but instead give one possible solution.
I'm not much of an explainer, so please ask if the description lacks somewhere.

Node layering in Graphviz

I'm creating a graph using Graphviz (compiled with neato). This graph contains many overlapping nodes which is perfectly fine. However, there is a group of large nodes which I prefer to always be on top of other small nodes - even-though I prefer to define the large nodes first in the graph (which makes them get painted at the very bottom).
Any way I can force this?
Edit:
Here's a small example, just to clarify what I mean:
graph G {
node [style=filled,fillcolor=black];
BigNode [fillcolor=skyblue,shape=Msquare];
node [style=filled,fillcolor=red,shape=circle];
edge [style=invis]
1 -- BigNode[len=0.5];
2 -- BigNode[len=1];
}
I'd like for BigNode to be painted over node 1.
I did find one (sort of) solution...
I found that if you postpone only the node definition to the end, even if you defined edges for this node earlier, it will be painted top-most.
I realize this contradicts what I defined earlier, but this was the only possible solution in this case and it was the one I eventually had to use.
In my short example, you would do this:
graph G {
node[style=filled,fillcolor=black];
// Definition of BigNode moved to the end of the file
/*BigNode [fillcolor=skyblue,shape=Msquare];*/
node[style=filled,fillcolor=red,shape=circle];
edge[style=invis]
1 -- BigNode[len=0.5];
2 -- BigNode[len=1];
// Defined after already defining edges for BigNode
BigNode [fillcolor=skyblue,shape=Msquare];
}
In the resulting graph, BigNode is painted over node 1
I don't think it's possible. The official neato guide talks about node layering on pages 6 through 9. It looks like the most you can do is adjust the length of edges and pin down nodes: you can't actually control how nodes layer over each other.

Resources