# How do I model poker hands as graphs such that I can evaluate using graph isomorphism?

These two poker hands are graph isomorphic via a trivial suit-shifting function f:

G = Ah Kc Qd Js Th

H = Ac Kd Qs Jh Tc

V(H) = f(V(G)) where f shifts the suits

Question: how do I represent these hands as graphs such that I can test for isomophism algorithmically? I assume the ranks and suits will have to form a bipartite graph, but I'm not sure how the different cards within the hand should be modeled as nodes.

===EDIT - clarifying the isomorphism===

I would like for the following two hands not to be isomorphic.

G = Ah Kc Qd Js Th

H = Ah Kc Qd Js Tc

Is there any way to restrict the model such that the first case above would be isomorphic but this second case wouldn't?

Put another way, is there any way to constrain the isomorphism tests so that they only allow for suit shifting and not rank shifting functions?

-

You should get a complete bipartite graph $G$ where $V(G) = V_1 \cup V_2$ where $V_1 = \left\{ 2,3,\ldots,10,J,Q,K,A \right\}$ and $V_2 = \left\{ Club, Heart, Diamond, Spade \right\}$. Thus a hand of 5 cards can be represented as $E' \subset E(G) s.t. |E'|=5$. Thus if you can find an isomorphism between two hands, $E_1$ and $E_2$, in the graphs $G_1 = (V,E_1)$ and $G_2 = (V,E_2)$ the two hands will be the same.
@MikeRand You are correct in your first assumption that there would be 5 edges per edge set, and that $E(G)$ would be the full set of edges since $G$ was complete bipartite. And my construction would not consider those two hands isomorphic since in the first hand the degree of the King vertex is only 1 while in the other hand it is of degree 2. – Nicolas Villanueva May 3 '11 at 5:55