Recently, I tried to write a function to get the lexicographic product of two graphs.
In graph theory the lexicographic product G ∙ H of graphs G and H is a graph such that
I'm trying to write this function as defined after making sure it doesn't exist in maple. I saw a similar post by mathematica stack.
There are many answers in the post, the most interesting to me is the following code, which follows the definition of lexicographic product.
lexicographicProduct[g1_?UndirectedGraphQ, g2_?UndirectedGraphQ, opt : OptionsPattern] :=
(* two nodes are connected if their corresponding nodes in the first graph are connected *)
EdgeQ[g1, First[#1] \[UndirectedEdge] First[#2]] ||
(* or their corresponding nodes in the first graph are the same and their corresponding nodes in the second graph are connected *)
(First[#1] === First[#2] && EdgeQ[g2, Last[#1] \[UndirectedEdge] Last[#2]]) &,
(* the vertices are the cartesian product of the two vertex sets *)
(* also allow setting graph options *)
It utilizes the function
RelationGraph in Mathematica. I feel that this function is generic in nature. So here I would ask maple if they had a similar function.
RelationGraph is to generate a graph based on data and a binary relation.
For example, using
RelationGraph I can get easily the kth power Gk of an graph G which is another graph that has the same set of vertices, but in which two vertices are adjacent when their distance in G is at most k.
Dis[g1_?UndirectedGraphQ, k_] :=
GraphDistance[g1, #1, #2] <= k && GraphDistance[g1, #1, #2] != 0 &,
If I use maple and do not use the built-in function
GraphPower, I might deal with the following.
choo:= choose(vex, 2):
for edge in choo do
if Distance(G, edge, edge)<=k then
I believe if the
RelationGraph function can be implemented in maple, the function
lexicographicProduct would be easier to obtain.