#include
#include
/* Removes graphs which contain vertices with valency bigger than maxDegree. Use -h to remove the header
expectedVertices is the number of vertices that graphs generated by plantri output.
currentMaxDegree is the current maximum degree that vertices can have
*/
/* #define expectedVertices 12*/
#define currentMaxDegree 11
#define maxDegree 5
int main(int argc, char **arguments)
{
char a, expectedVertices;
unsigned char graph[expectedVertices*(currentMaxDegree+1) + 1], *graphIndex; //stores the details about the graph for printing
int filterFlag = 0; //should the current graph be filtered
int degreeOfNode = 0; //the degree of the current node
int vertexNumber = 0; //the number of vertices counted in the current graph
int graphLength=0; //stores the length of information to write
int validgraphs=0; // Count the number of valid graphs found by the program
graphIndex = &graph[0];
//Get the number of nodes in the graphs
a = getchar();
expectedVertices = a;
*graphIndex=a;
graphLength++;
if(a!=expectedVertices)
{
fprintf(stderr,"Error: the expected number of vertices differed from the value in the file. The number of vertices in the file was %i \n",a);
}
a=getchar();
while(a!= EOF)
{
graphLength++;
graphIndex++;
*graphIndex=a;
if (a == 0)
{
//a=0 indicates the end of a vertex
if(degreeOfNode>maxDegree)
{
//the degree of this node was too large
filterFlag=1;
}
vertexNumber++;
degreeOfNode=0;
if(vertexNumber == expectedVertices)
{
/*This marks the end of the graph */
if(filterFlag == 0)
{
fwrite(graph,sizeof(unsigned char),graphLength,stdout);
validgraphs++;
//must print here
}
filterFlag = 0;
vertexNumber = 0;
/*Check for expectedVertices at the beginning of the new graph, or end of file*/
graphIndex = &graph[0];
a = getchar();
if(a!=EOF)
{
*graphIndex = a;
graphLength = 1;
if(a != expectedVertices)
{
fprintf(stderr,"Error: the expected number of vertices differed from the value in the file. The number of vertices in the file was %c \n",a);
//error
}
a = getchar();
}
}
else a = getchar();
}
else
{
degreeOfNode++;
a=getchar();
}
}
fprintf(stderr, "%i graphs with maximum vertex-degree of 5 generated\n", validgraphs);
}