Connecting Tech Pros Worldwide Forums | Help | Site Map

how to implement a huge adjacent matrix?

luke.yolanda@gmail.com
Guest
 
Posts: n/a
#1: Mar 15 '06
Hi everyone
Now i'm designing a random instances generator for maximum clique
problem using C.
So I planing to implement a adjacent matrix in this generator to store
the whole graph going to be generated. I couldn't find a method other
than using an unsigned char[][], but in this way, 7 bits in a unsigned
char will be wasted. Could anyone teach me a more effective way to
implement it? Thank you!


Vladimir S. Oka
Guest
 
Posts: n/a
#2: Mar 15 '06

re: how to implement a huge adjacent matrix?


On Wednesday 15 March 2006 06:40, luke.yolanda@gmail.com opined (in
<1142404851.856547.287670@u72g2000cwu.googlegroups .com>):
[color=blue]
> Hi everyone
> Now i'm designing a random instances generator for maximum clique
> problem using C.
> So I planing to implement a adjacent matrix in this generator to store
> the whole graph going to be generated. I couldn't find a method other
> than using an unsigned char[][], but in this way, 7 bits in a
> unsigned char will be wasted. Could anyone teach me a more effective
> way to implement it? Thank you![/color]

If I understand your problem correctly, you actually want an /adjacency/
matrix which, if memory serves is just a 0/1 matrix. So, it seems you
want to pack your bits, instead of using a whole `char` for each one.
You can still use the same sort of matrix you say you have now, just
pack your bits into it's elements. To make this as portable as
possible, do not assume, say, 8 bits, but use CHAR_BIT defined in
<limits.h> to tell you the size of `char` on your system. This will be
more work, so you will lose some performance extracting and packing
bits, but not too much.

--
BR, Vladimir

There's small choice in rotten apples.
-- William Shakespeare, "The Taming of the Shrew"

Keith Thompson
Guest
 
Posts: n/a
#3: Mar 15 '06

re: how to implement a huge adjacent matrix?


"Vladimir S. Oka" <novine@btopenworld.com> writes:[color=blue]
> On Wednesday 15 March 2006 06:40, luke.yolanda@gmail.com opined (in
> <1142404851.856547.287670@u72g2000cwu.googlegroups .com>):
>[color=green]
>> Hi everyone
>> Now i'm designing a random instances generator for maximum clique
>> problem using C.
>> So I planing to implement a adjacent matrix in this generator to store
>> the whole graph going to be generated. I couldn't find a method other
>> than using an unsigned char[][], but in this way, 7 bits in a
>> unsigned char will be wasted. Could anyone teach me a more effective
>> way to implement it? Thank you![/color]
>
> If I understand your problem correctly, you actually want an /adjacency/
> matrix which, if memory serves is just a 0/1 matrix. So, it seems you
> want to pack your bits, instead of using a whole `char` for each one.
> You can still use the same sort of matrix you say you have now, just
> pack your bits into it's elements. To make this as portable as
> possible, do not assume, say, 8 bits, but use CHAR_BIT defined in
> <limits.h> to tell you the size of `char` on your system. This will be
> more work, so you will lose some performance extracting and packing
> bits, but not too much.[/color]

And use unsigned char, not plain char (which can be either signed or
unsigned).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Closed Thread