I've just now started reading an Algorithms book that defined Graphs as follows:
Graphs – which represent relationships
between arbitrary pairs of objects.
Figure 1.8(b) models a network of
roads as a graph, where the vertices
are cities and the edges are roads
connecting pairs of cities. Graphs are
likely the object in question whenever
you seek a “network,” “circuit,”
“web,” or “relationship.”
Figure 1.8(b) is this:
What confuses me here is the following line:
... where the vertices are cities and the
edges are roads connecting pairs of
cities ...
Vertices are the dots, edges are the lines. Hence cities and roads.
I'm not sure what confuses you, but in general graphs are indeed used to model connections between objects.
If you have a bunch of objects (vertices) that may be "connected" to one another, a Graph would be the high level data structure to maintain it. I'm saying "high level" because in practice you will probably need supporting data structures to maintain a graph in memory/database/file: matrices, lists of links, many-to-many tables etc.
If the "direction" is not important, like in the case of the plot above (i.e. all roads are bidirectional), you have an "undirected graph". If the connection direction does have an importance (for example if there are unidirectional roads between cities), you'll have a "directed graph", where every edge is actually an "arrow", pointing at a certain direction.
If you're very new to this, I recommend reading the relevant Wikipedia entry. For some "real" studying, I recommend Cormen et al's Introduction to Algorithms, the book I studied from, which is in my opinion one of the best computer science books ever written.
Vertices are the nodes of the graph.
Edges are the arcs that connect pairs of nodes.
if u count every line u see,thats the vertices.edges are the corners[eg-a sphere has no corners and no vertices but has i face.if u wanna know about all the properties of 3D shapes search 3D shapes on your computer.u will get more explanation.
Related
I've got a DAG of around 3.300 vertices which can be laid out quite successfully by dot as a more or less simple tree (things get complicated because vertices can have more than one predecessor from a whole different rank, so crossovers are frequent). Each vertex in the graph came into being at a specific time in the original process and I want one axis in the layout to represent time: An edge relation like a -> v, b -> v means that a and b came into being at some specific time before v.
Is there a layout algorithm for DAGs which would allow me to specify the positions (or at least the distances) on one axis and come up with an optimal layout regarding edge crossovers on the other?
You can make a topological sorting of the DAG to have the vertices sorted in a way that for every edge x->y, vertex x comes before than y.
Therefore, if you have a -> v, b -> v, you will get something like a, b, v or b, a, v.
Using this you can easily represents DAGs like this:
Yes, as #Arturo-Menchaca said a topological sorting may help to reduce overlapping count of edges. But it may be not optimal. There is no good algorithm for edge crossing minimization. Problem for crossing minimization is NP-complete. The heuristics are applied for solving this problem.
This StackOverflow link may help you: Drawing Directed Acyclic Graphs: Minimizing edge crossing?
I suppose your problem is related to an aesthetically pleasing way of the graph layout. Some heuristics are described in the articles Overview of algorithms for graph drawing, Force-Directed Drawing Algorithms. May be information about planar graph or almost planar graph can help you also.
Some review of the algorithms for checking and drawing planar graphs are described in the Wiki pages Planar graph, Crossing number (graph theory). The libraries and algorithms for planar graph drawing are described in the StackOverflow question How to check if a Graph is a Planar Graph or not? For example the author in the article GA for straight-line grid drawings of maximal planar graphs uses genetic algorithms for straight-line grid drawing.
Good descriptions for almost planar graphs are given in the articles Straight-Line Drawability of a Planar Graph Plus an Edge, On the Crossing Number of Almost Planar Graphs.
Try to modify the original algoritms using your condition with one axis alignment.
If I understood you correctly then you want to minimize the number of edge-crossings in your graph layout. If so, then the answer is "No", because this problem is proved to be NP-complete in the general case. See this, "Crossing Number is NP-Complete, Garey, Johnson".
If you need a not an optimal but just good enough solution, there are multiple articles on this topic because it is heavily related with circuit layouts. Probably googling "crossing number heuristics" and looking through the abstracts of some papers will solve your task better then me trying to guess blindly your requirements.
I have searched related issues about subgraph enumeration. However, they didn't meet my requirement(*). (If I misunderstood something, please tell me.)
Is there an efficient algorithm or tools for the enumeration of all "connected, and unlabelled" subgraphs of a undirected parent graph.
In my case, the parent graph is an Internet topology so the amount of nodes could be large. And I would like to enumerate all of the connected unlabelled patterns (i.e. subgraphs) of the parent graph.
(*) I have searched Efficiently find all connected subgraphs and Subgraph enumeration but both of them were targeting on vertex-labelled induced and complete subgraphs respectively. But all I want is just the connected unlabelled subgraphs.
A topic name that might be helpful is "frequent subgraph mining", which is what it seems to be one name for this. There are various tools and algorithms in this area, although they may not do exactly what you want, of course.
As other point out in the answers to the two questions in your links, the number of subgraphs of large graphs can be very large. Assuming you actually want to list them, not just count them then it might take a long time.
Edit : OP has pointed out that the input here is ONE large graph, not a set of smaller ones, which will not work with standard graph mining
I still think the general approach can work here. The input set of graphs for mining is some subset of the subgraphs of your data graph. But that subgraph-set is what you want in the first place!
So lets say you pick a size of subgraph that you want (let's say 6 vertices) then you randomly pick starting vertices in your parent (the internet topology) and 'grow' these seeds, weeding out at each growth step those that don't match. Then repeat for different sizes of subgraph.
Of course, this is a probabilistic algorithm, but it could give you some idea.
Am doing some research on traffic flow and such , am having some troubles in representing a two way road on the network ... first though was to use directed graphs and this means I'll be having two directed edges between two nodes , I want to know if this is a good representation and if graph analysis(centrality,betweenness etc...) would apply to such graph
Virtually all researchers concentrate on directed and undirected graphs, and not on the more general model - mixed graph. This is since directed graph can theoretically represent mixed graphs by adding any bi-directed (or non-directed, depending on your semantics) relationship as two directed edges.
However, this attitude is far from optimal for some applications, where the mixed model is much more practical, such as street networks (e.g. supporting both one-way and two-way streets), M*3 networks (e.g. multi-relational social networks), and many other use cases.
Nothing stops one for developing algorithms, metrics (e.g. centrality metrics), libraries, etc. that support mixed graphs directly. Nevertheless, mixed graphs never gained popularity. Take for example the most popular C++ graph libraries - The Boost Graph Library, LEMON Graph Library, STINGER, MTGL and igraph - none of these support mixed graphs natively. Even most graph databases don't support mixed graphs, but there are exceptions - Sparsity DEX for example.
In most cases, if you're looking for some metrics or algorithms - you'll have to implement from scratch - due to the lack of both theory and practical implementations. I hope we'll see some change in the near future.
Representation
Consider representing a road network with a directed graph in the following way.
Road segments are nodes in your graph.
If a road segment is 2-way, there are 2 nodes for each direction.
If a road segment is 1-way, there is only 1 node.
There is an edge from road segment A to road segment B if and only if:
The end of A is the start of B.
Proceeding from A to B makes sense physically.
This let's you model things such as intersections where a left turn is not allowed, or the inability at a T junction to make a U-turn.
Example
Consider the following example. Here there are 5 road segments shown and 1 intersection. Coming from below is a 1-way street, and only right turns are allowed at the end. Drivers drive on the right side of the roadway.
The blue dots are the 5 nodes in the directed graph - one for each road segment. The orange arrows are the 3 possible transitions from road segment to road segment that are permissible.
Road networks can be represented as a graph. One could see a map as a graph where the nodes are places which can be visited (towns, buildings, etc) and the edges are roads.
That being said, the effectiveness of your approach would depend on what type of information you include in your graph, for instance, an edge between nodes N1 and N2 would mean that there is a path between N1 and N2, however, that information on its own does not provide any insight on how much heavy traffic does the particular street see.
To go round this problem, you could use weighted directed graphs, in which you could use the weights of the edges to determine the traffic on the roads and thus being able to yield a more complete analysis.
Someone asked about overlapping subclusters in GraphViz and got the following response:
Sorry, no. General subgraphs can share nodes without implying subset
containment but not clusters. The problem is in the drawing.
If clusters can overlap arbitrarily, drawing them becomes the problem
of drawing Venn diagrams, for which there are no good algorithms.
What is a formal definition or example of the "problem of drawing Venn diagrams"?, and why is it (I assume NP-complete/hard) hard ? (Extra points: Sketch a reduction to a well-known NP-complete problem)
You have N points and a binary relation R on them, and you need to represent the relation graphically so that every node is represented by a circle on Euclidean plane so that two circles overlap if and only if for the corresponding nodes n and n' it holds that n R n'.
Instead of a Venn diagram as such, we can in many cases use GraphViz for the same purpose using the dual graph, which is the Boolean lattice of the intersections of the sets. Each node represents a unique choice of sets to include and sets to exclude. Nodes that differ only by the inclusion/exclusion of a single set are connected.
For increasing numbers of sets, of course there are in general many, many nodes and edges. But in many practical settings there will be many sets that do not intersect at all, so that those intersection nodes and any edges from them to other nodes may be omitted. By this method the number of nodes and edges may be reduced to a practical number.
When laying out the resulting graph it may be best to select the GraphViz algorithm "neato" and to ask to avoid overlapping the nodes. One way to make those settings is by writing, inside the opening curly brace for the graph, layout=neato,overlap=prism; .
In Algorithm Design Manual, page 178 describes some properties of Graph, and one of them is embedded and Topological:
Embedded vs. Topological
A graph is embedded if the vertices and
edges are assigned geometric positions. Thus, any drawing of a graph
is an embedding, which may or may not have algorithmic significance.
Occasionally, the structure of a graph is completely defined by the
geometry of its embedding. For example, if we are given a collection
of points in the plane, and seek the minimum cost tour visiting all of
them (i.e., the traveling salesman problem), the underlying topology
is the complete graph connecting each pair of vertices. The weights
are typically defined by the Euclidean distance between each pair of
points.
Grids of points are another example of topology from geometry.
Many problems on an n × m grid involve walking between neighboring
points, so the edges are implicitly defined from the geometry.
I quite don't understand it:
First of all, what exactly does embedded mean here? As long as the vertices have their own geometric positions, then can I call the graph embedded?
What does any drawing of a graph is an embedding mean? Does it mean what I said in point 1?
What does Topological mean? I don't think it is explained in this description.
The examples in this description really confused me a lot. Could someone please use simplest words to let me understand these two terms for graph?
Is it really important to get these two term understood?
Thanks
I remind you that a graph is just a set of vertices and a set of edges defined on them, so the vertices don't have a geometric position of their own. A drawing of a graph is called an embedding, a drawn graph is called embedded.
It means that any way of drawing a graph is called an embedding of that graph.
A topological graph is a graph whose vertices and edges are points and arcs, respectively.
In addition to msj's answer.
Graph = G(V, E), where V is set of vertex and and E is set pair of vertices from V. This is definition of graph as per Skiena. Note how there is no mention of how this graph visually appear (i.e no mention of its topology).
Example (note that it doesn't define where a, b are located in say X,Y coordinate system)
V = { a, b, c, d, e, f } and E = { (a,b), (b,c), (a,e) }
To 'draw' a graph you assign it geometric positions e.g. in X,Y coordinate systems.
|
| b (2,3)
| a(1,2)
|
|
|____________________________
Fig 1
Fig 1 is simply an embedding where we are drawing vertex pairs specified in E
Difference between embedded and topological graph is how does the "topology" comes to be. In any "embedding" you manually assign geometric locations as explained above, but in topological graph you define a "rule" based on which topology of a graph defines itself. e.g. you specify a G(V,E) and define a rule, say "visit each node exactly once" defines the topology which is called "complete graph".
Skiena uses geographical friendship graph as an example for embedded graph because each vertex is associated with a geographical point in this world where friends live.
Excerpt from the book -
Do my friends live near me? – Social networks are not divorced from geography. Many of your friends are your friends only because they happen to live near you (e.g., neighbors) or used to live near you (e.g., college roommates).
Thus, a full understanding of social networks requires an embedded graph, where each vertex is associated with the point in this world where they live. This geographic information may not be explicitly encoded, but the fact that the graph is inherently embedded in the plane shapes our interpretation of any analysis.