MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: number of Trangles in a graph-network

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99376] Re: number of Trangles in a graph-network
  • From: dh <dh at metrohm.com>
  • Date: Mon, 4 May 2009 06:00:51 -0400 (EDT)
  • References: <gtefaf$197$1@smc.vnet.net>


Hi Luca,

try e.g.:

=======================

Needs["Combinatorica`"];

Needs["GraphUtilities`"]

g = RandomGraph[7, 0.5];

ShowGraph[g, VertexNumber -> True]

ad = AdjacencyMatrix[g] // Normal;

triangles = {};

Do[   (*loop over first point*)

   t = ad[[i, i + 1 ;; -1]];(*take upper half*)

   t = i + Position[t, 1] // Flatten;

   t = Subsets[t, {2}];(*possible 2. and 3. point*)

   t = Select[t,

     ad[[Sequence @@ #]] == 1 &];(*check if 2. and 3. point connected*)





   t = Prepend[#, i] & /@ t;

   triangles = Join[triangles, t];

   , {i, 1, Length[ad]}];

triangles

======================

Daniel







Luca Cinacchio wrote:

> Greetings,

> 

> having a graph (network, i.e. one created with RandomGraph) wich can have  

> not connected nodes, I would like to count the total number of triangles  

> inside the graph.

> I gave a look to Combinatorica and its related book by Pemmaraju Skiena,  

> but I did'nt find any solution (maybe I am wrong). Do you know if there is  

> a easy way to answer this problem with Mathematica and/or Combinatorica?

> Thanks in advance.

> 




  • Prev by Date: Control[], Manipulate, Why labels not showing?
  • Next by Date: Re: ListPointPlot3D colors from data
  • Previous by thread: Re: number of Trangles in a graph-network
  • Next by thread: Re: number of Trangles in a graph-network