[GAP Forum] Reading strongly regular graphs into GAP
Alexander Hulpke
hulpke at math.colostate.edu
Fri Mar 22 19:13:37 GMT 2013
Dear Forum, Dear Robert Bailey,
> This is perhaps not strictly a GAP question, but anyway....
>
> I've been working on some computations in GAP (using the GRAPE and other
> packages), testing certain properties of distance-regular and strongly
> [...]
>
> The graphs are given by their adjacency matrices; however, as given
> these matrices are not immediately readable by GAP. Does anyone know of
> an easy way to convert them into the right format
As Mathieu Dutour already wrote, the classical method is to coax your favorite P-named language (Perl, Python) to parse these matrices so that you get a valid GAP input file.
However you can also read in the file line by line to GAP and write a small routine to parse the data. Personally (with the bias that I know GAP far better than Perl or Python) I find this easier.
For example the appended program can be used to read in the lists of adjacency matrices as given on this web page, the function call
a:=ReadMatrixList("PathTofilename");;
returns a list of the adjacency matrices over Q. (You can probably take it from there.)
At the moment the function assumes single digits but it should be easy to adapt to more complicated formats.
(This function ought to work also under Windows, but as usual you need to be careful how to specify the path.)
I hope this is of help,
Alexander Hulpke
# the promised function
ReadMatrixList:=function(file)
local l,f,m,row;
l:=[];
f:=InputTextFile(file);
m:=fail;
while not IsEndOfStream(f) do
row:=ReadLine(f);
if row<>fail then
row:=Chomp(row); # remove CR,LF
row:=Filtered(row,x->x<>' '); # remove blanks
if Length(row)=0 then
# new matrix
if m<>fail and Length(m)>0 then Add(l,m);fi;
m:=[];
elif IsSubset(DIGITS,row) then
# new row
row:=List(row,x->Int([x]));
Add(m,row);
else
Print("#I ",row,"\n"); # non parsed row
fi;
fi;
od;
CloseStream(f);
if m<>fail and Length(m)>0 then Add(l,m);fi;
return l;
end;
-- Colorado State University, Department of Mathematics,
Weber Building, 1874 Campus Delivery, Fort Collins, CO 80523-1874, USA
email: hulpke at math.colostate.edu, Phone: ++1-970-4914288
http://www.math.colostate.edu/~hulpke
More information about the Forum
mailing list