# The following code doesn't seem to work finding Chomatic Number of Undirected Graph in Mathematica(MathKernel)

In[37]:= g = Graph[{4->3, 5->3, 5->4, 6->1, 6->2, 6->4, 6->5}]

Out[37]= Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}]


I created a graph as show above and while trying to import combinatorica package, I get the following error

In[38]:= << Combinatorica;

General::compat:
Combinatorica Graph and Permutations functionality has been superseded by
this. Please see the Compatibility Guide for details.


I don't know what's going on here, but while trying to find the chromatic number using the following command, it gives the subsequent following error.

In[43]:= CN = ChromaticNumber[g]

First::normal: Nonatomic expression expected at position 1 in First[All].

First::normal: Nonatomic expression expected at position 1 in First[All].

Part::partw: Part 2 of First[All] does not exist.

First::normal: Nonatomic expression expected at position 1 in First[All].

General::stop: Further output of First::normal
will be suppressed during this calculation.

Part::partw: Part 2 of First[All] does not exist.

Part::partw: Part 2 of First[All] does not exist.

General::stop: Further output of Part::partw
will be suppressed during this calculation.

Range::range: Range specification in
Range[V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}]]]
does not have appropriate bounds.

Table::iterb: Iterator {CombinatoricaPrivatei\$318,
V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}]]} does
not have appropriate bounds.

Join::heads: Heads CombinatoricaPrivateDouble and Table at positions 1 and 2
are expected to be the same.

Join::heads: Heads CombinatoricaPrivateDouble and Table at positions 1 and 2
are expected to be the same.

Join::heads: Heads CombinatoricaPrivateDouble and List at positions 1 and 2
are expected to be the same.

will be suppressed during this calculation.

Table::iterb: Iterator {V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2,
6 -> 4, 6 -> 5}]]} does not have appropriate bounds.

Transpose::nmtx:
The first two levels of the one-dimensional list {} cannot be transposed.

Transpose::nmtx:
The first two levels of the one-dimensional list {} cannot be transposed.

Part::pspec: Part specification
{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}
is neither an integer nor a list of integers.

Part::pspec: Part specification
Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}][[2]]
is neither an integer nor a list of integers.

Table::iterb: Iterator {V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2,
6 -> 4, 6 -> 5}]]} does not have appropriate bounds.

General::stop: Further output of Table::iterb
will be suppressed during this calculation.

Part::pspec: Part specification CombinatoricaPrivateDouble[]
is neither an integer nor a list of integers.

General::stop: Further output of Part::pspec
will be suppressed during this calculation.

Range::range: Range specification in
Range[1 + Table[0, {V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2,
6 -> 4, 6 -> 5}]]}][[CombinatoricaPrivateDouble[],0]]] does not
have appropriate bounds.

Heads Part and Range at positions 2 and 1 are expected to be the same.

Out[43]= Table[Complement[Range[1 +

>       Table[0, {V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4,

>             6 -> 5}]]}][[CombinatoricaPrivateDouble[],0]]],

>     Table[0, {V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4,

>           6 -> 5}]]}][[CombinatoricaPrivateDouble[],0]]],

>    {V[Graph[{4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}]]}]


Did I go wrong somewhere ?

-

## migrated from stackoverflow.comSep 10 '12 at 20:35

This question came from our site for professional and enthusiast programmers.

btw, I'm using Ubuntu 12.04 OS, and running MathKernel in Terminal – tsndiffopera Sep 10 '12 at 16:53

Start a fresh Mma session and type

Needs["GraphUtilities"];

g = {4 -> 3, 5 -> 3, 5 -> 4, 6 -> 1, 6 -> 2, 6 -> 4, 6 -> 5}
<< Combinatorica
ShowGraph[g1 = ToCombinatoricaGraph[g]]
ChromaticNumber[g1]


There are a lot of name conflicts between the System context and Combinatorica.

-
awesome sir. You made my day. Million Thanks to you. Even I had a doubt that there could be a conflict between the two packages, but couldn't resolve it. You've made it. Thanks again for this. :) – tsndiffopera Sep 10 '12 at 17:43
But EdgeList@g1 gives {{1, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 3}, {4, 5}, {4, 6}}, which is the wrong answer, and for this reason I have never trusted ToCombinatoricaGraph. (EdgeList@g gives {{4, 3}, {5, 3}, {5, 4}, {6, 1}, {6, 2}, {6, 4}, {6, 5}} ). I prefer to generate a CombinatoricaGraph using FromOrderedPairs (to again raise one of my favourite rants). In this case it makes no difference (but how can we be certain with independently checking?): ChromaticNumber@FromOrderedPairs@EdgeList@g also gives 3. – user 106 Sep 28 '12 at 8:46
@TomD Why don't you post an answer? I'll upvote it! – Dr. belisarius Sep 28 '12 at 8:58
@TomD : +1 for that comment. It teaches me something which I didn't knew :) – saint1729 Sep 29 '12 at 9:46