Group Abstract Group Abstract

Message Boards Message Boards

Strong Graph product between two C_5 graphs?

Posted 9 years ago
POSTED BY: Alessio Lapolla
4 Replies
POSTED BY: Alessio Lapolla
Posted 9 years ago

This is a nice solution!

POSTED BY: Greg Hurst
Posted 9 years ago

You can get around 1.5 times faster if you avoid the pattern matcher by replacing the lines containing ReplacePart with the following:

Change

ajm1G = ReplacePart[ajmG, {i_, i_} -> 1];
ajm1H = ReplacePart[ajmH, {i_, i_} -> 1];

to

ajm1G = Unitize[ajmG + IdentityMatrix[Length[ajmG]]];
ajm1H = Unitize[ajmH + IdentityMatrix[Length[ajmH]]];

and

ajmGH = ReplacePart[P, {i_, i_} -> 0];

to

ajmGH = P (1 - IdentityMatrix[Length[P]]);
POSTED BY: Greg Hurst
Posted 9 years ago

You could always implement your own, based on the definition of a strong graph product.

strongGraphProduct[g_, h_] :=
    Block[{mg, mh, vj, n, mj},
       mg = AdjacencyMatrix[g];
       mh = AdjacencyMatrix[h];

       vj = Tuples[{Range[VertexCount[g]], Range[VertexCount[h]]}];
       n = Length[vj];

       mj = SparseArray[{{i_, j_} /; strongCondition[vj, mg, mh, i, j] -> 1}, {n, n}];

       AdjacencyGraph[mj]
    ]

strongCondition[vj_, mg_, mh_, i_, j_] :=
    Block[{u1, u2, v1, v2},
       {u1, u2} = vj[[i]];
       {v1, v2} = vj[[j]];

       Or[
         u1 === v1 && (mh[[u2, v2]] != 0 || mh[[v2, u2]] != 0),
         u2 === v2 && (mg[[u1, v1]] != 0 || mg[[v1, u1]] != 0),
         (mg[[u1, v1]] != 0 || mg[[v1, u1]] != 0) && (mh[[u2, v2]] != 0 || mh[[v2, u2]] != 0)
       ]
    ]

Then test it:

g = h = CycleGraph[5];
j = strongGraphProduct[g, h]

enter image description here

Some properties:

{VertexCount[j], EdgeCount[j]}
(* {25, 100} *)
POSTED BY: Greg Hurst
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard