示例#1
0
文件: nautyex4.c 项目: igraph/nautier
int
static main(int argc, char *argv[])
{
    DYNALLSTAT(int,lab,lab_sz);
    DYNALLSTAT(int,ptn,ptn_sz);
    DYNALLSTAT(int,orbits,orbits_sz);
    static DEFAULTOPTIONS_SPARSEGRAPH(options);
    statsblk stats;
    sparsegraph sg;   /* Declare sparse graph structure */

    int n,m,i;

    options.writeautoms = TRUE;

 /* Initialise sparse graph structure. */

    SG_INIT(sg);

    while (1)
    {
        printf("\nenter n : ");
        if (scanf("%d",&n) == 1 && n > 0)
        {
            m = SETWORDSNEEDED(n);
            nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);

            DYNALLOC1(int,lab,lab_sz,n,"malloc");
            DYNALLOC1(int,ptn,ptn_sz,n,"malloc");
            DYNALLOC1(int,orbits,orbits_sz,n,"malloc");

         /* SG_ALLOC makes sure that the v,d,e fields of a sparse graph
            structure point to arrays that are large enough.  This only
            works if the structure has been initialised. */

            SG_ALLOC(sg,n,2*n,"malloc");

            sg.nv = n;              /* Number of vertices */
            sg.nde = 2*n;           /* Number of directed edges */

            for (i = 0; i < n; ++i)
            {
                sg.v[i] = 2*i;
                sg.d[i] = 2;
                sg.e[2*i] = (i+n-1)%n;      /* edge i->i-1 */
                sg.e[2*i+1] = (i+n+1)%n;    /* edge i->i+1 */
            }

            printf("Generators for Aut(C[%d]):\n",n);
            sparsenauty(&sg,lab,ptn,orbits,&options,&stats,NULL);

            printf("Automorphism group size = ");
            writegroupsize(stdout,stats.grpsize1,stats.grpsize2);
            printf("\n");
        }
        else
            break;
示例#2
0
int main(int argc, char** argv)
{
	int goal_min_p = 1;
	int goal_max_p = 10;

	if ( argc >= 2 )
	{
		goal_min_p = atoi(argv[1]);
		goal_max_p = goal_min_p;
	}

	if ( argc >= 3 )
	{
		goal_max_p = atoi(argv[2]);
	}

	char buffer[500];
	long long int count = 0;

	while ( scanf("%s", buffer) != EOF )
	{
		if ( strlen(buffer) == 0 )
		{
			continue;
		}

		count++;

		if ( count % ERR_UPDATE == 0 )
		{
			fprintf(stderr, "> COUNT: %010lld\n", count);
		}

		/* buffer holds an s6 string */
		sparsegraph g;
		SG_INIT(g);

		int num_loops;
		stringtosparsegraph(buffer, &g, &num_loops);
		int c = (g.nde / 2) - ((g.nv * g.nv) / 4);

		int p = countPM(&g, goal_max_p);

		if ( goal_min_p <= p && p <= goal_max_p )
		{
			printf("%5d\t%3d\t%s\n", p, c, buffer);
		}

		SG_FREE(g);
	}

	return 0;
}
示例#3
0
文件: linegraphg.c 项目: 3ki5tj/nauty
int
main(int argc, char *argv[])
{
    char *infilename,*outfilename;
    FILE *infile,*outfile;
    boolean badargs,quiet;
    int j,m,n,argnum;
    int codetype,outcode;
    sparsegraph g,h;
    nauty_counter nin,nullgraphs;
    char *arg,sw;
    static graph *gq;
    double t;

    HELP;

    SG_INIT(g);
    SG_INIT(h);

    infilename = outfilename = NULL;
    quiet = FALSE;

    argnum = 0;
    badargs = FALSE;
    for (j = 1; !badargs && j < argc; ++j)
    {
        arg = argv[j];
        if (arg[0] == '-' && arg[1] != '\0')
        {
            ++arg;
            while (*arg != '\0')
            {
                sw = *arg++;
                SWBOOLEAN('q',quiet)
                else badargs = TRUE;
            }
        }
        else
        {
            ++argnum;
void printModifiedGraphBarrier(sparsegraph* g)
{
	/* need to make a better graph! */
	sparsegraph sg;
	SG_INIT(sg);

	sg.w = 0;
	sg.wlen = 0;

	sg.v = (int*) malloc(g->nv * sizeof(int));
	sg.d = (int*) malloc(g->nv * sizeof(int));
	sg.e = (int*) malloc(g->nde * sizeof(int));

	int* rev_verts = (int*) malloc(g->nv * sizeof(int));
	int* down_verts = (int*) malloc(g->nv * sizeof(int));

	int vindex = 0;
	int eindex = 0;
	int indirect_edge_deletes = 0;

	for ( int i = 0; i < g->nv; i++ )
	{
		/* if vertex is not deleted */
		if ( g->v[i] >= 0 )
		{
			//			printf("[%d] : %d \t", vindex, i);
			rev_verts[vindex] = i;
			down_verts[i] = vindex;
			vindex++;
		}
	}

	vindex = 0;

	for ( int i = 0; i < g->nv; i++ )
	{
		/* if vertex is not deleted */
		if ( g->v[i] >= 0 )
		{
			sg.v[vindex] = eindex;
			sg.d[vindex] = 0;

			for ( int j = 0; j < g->d[i]; j++ )
			{
				/* if edge is not deleted AND other vertex is not deleted */
				int edge_val = g->e[g->v[i] + j];

				if ( edge_val >= 0 && g->v[edge_val] >= 0 )
				{
					sg.e[eindex] = down_verts[edge_val];
					sg.d[vindex] = sg.d[vindex] + 1;
					eindex++;
				}
				else
				{
					/* the vertex on the other end was deleted */
					indirect_edge_deletes++;
				}
			}

			vindex++;
		}
	}

	sg.vlen = vindex;
	sg.dlen = vindex;
	sg.elen = eindex;
	sg.nv = vindex;
	sg.nde = eindex;

	free(down_verts);
	free(rev_verts);

	printf("%s", sgtos6(&sg));

	SG_FREE(sg);
}
示例#5
0
int main(int argc, char** argv)
{
	char buffer[1500];
	int print_orig = 0;

	if ( argc > 1 )
	{
		print_orig = 1;
	}

	while ( scanf("%s", buffer) != EOF )
	{
		/* buffer holds an s6 string */
		sparsegraph g;
		SG_INIT(g);

		int num_loops;
		stringtosparsegraph(buffer, &g, &num_loops);

		int nv = g.nv;
		int m = (nv + WORDSIZE - 1) / WORDSIZE;
		nauty_check(WORDSIZE, m, nv, NAUTYVERSIONID);

		DYNALLSTAT(int, lab, lab_n);
		DYNALLSTAT(int, ptn, ptn_n);
		DYNALLSTAT(int, orbits, orbits_n);

		DYNALLOC1(int, lab, lab_n, nv, "malloc");
		DYNALLOC1(int, ptn, ptn_n, nv, "malloc");
		DYNALLOC1(int, orbits, orbits_n, nv, "malloc");

		static DEFAULTOPTIONS_SPARSEGRAPH( options);

		options.defaultptn = TRUE; /* Don't need colors */
		options.getcanon = TRUE; /* gets labels */
		options.digraph = TRUE;


		statsblk stats; /* we'll use this at the end */
		DYNALLSTAT(setword, workspace, worksize);
		DYNALLOC1(setword, workspace, worksize, 50 * m, "malloc");

		sparsegraph canon_g;
		SG_INIT(canon_g);

		/* call nauty */
		nauty((graph*) &g, lab, ptn, NULL, orbits, &options, &stats, workspace,
				50 * m, m, g.nv, (graph*) &canon_g);

		sortlists_sg(&canon_g);

		char* canon_str = sgtos6(&canon_g);
		int canon_len = strlen(canon_str);

		if ( print_orig == 0 )
		{
			printf("%s", canon_str);
		}
		else
		{
			canon_str[canon_len-1] = 0;
			printf("%s", canon_str);
			printf("\t%s\n", buffer);
		}

		/* free workspace */
		DYNFREE(workspace, worksize);
		DYNFREE(lab,lab_n);
		DYNFREE(ptn,ptn_n);
		DYNFREE(orbits,orbits_n);

		SG_FREE(canon_g);
		SG_FREE(g);
	}

	return 0;
}
示例#6
0
文件: nauthread2.c 项目: 3ki5tj/nauty
static void*
runit(void * threadarg)          /* Main routine for one thread */
{
    DYNALLSTAT(int,lab,lab_sz);
    DYNALLSTAT(int,ptn,ptn_sz);
    DYNALLSTAT(int,orbits,orbits_sz);
    DEFAULTOPTIONS_SPARSEGRAPH(options);
    statsblk stats;
    sparsegraph sg;   /* Declare sparse graph structure */

    int n,m,i;

    n = ((params*)threadarg)->n;
    options.writeautoms = ((params*)threadarg)->writeautoms;

 /* Initialise sparse graph structure. */

    SG_INIT(sg);

    m = SETWORDSNEEDED(n);
    nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);

    DYNALLOC1(int,lab,lab_sz,n,"malloc");
    DYNALLOC1(int,ptn,ptn_sz,n,"malloc");
    DYNALLOC1(int,orbits,orbits_sz,n,"malloc");

 /* SG_ALLOC makes sure that the v,d,e fields of a sparse graph
    structure point to arrays that are large enough.  This only
    works if the structure has been initialised. */

    SG_ALLOC(sg,n,2*n,"malloc");

    sg.nv = n;              /* Number of vertices */
    sg.nde = 2*n;           /* Number of directed edges */

    for (i = 0; i < n; ++i)
    {
        sg.v[i] = 2*i;
        sg.d[i] = 2;
        sg.e[2*i] = (i+n-1)%n;      /* edge i->i-1 */
        sg.e[2*i+1] = (i+n+1)%n;    /* edge i->i+1 */
    }

    if (options.writeautoms)
        printf("Generators for Aut(C[%d]):\n",n);
    sparsenauty(&sg,lab,ptn,orbits,&options,&stats,NULL);

    if (options.writeautoms)
    {
        printf("Automorphism group size = ");
        writegroupsize(stdout,stats.grpsize1,stats.grpsize2);
        printf("\n");
    }
    if (stats.numorbits != 1 || stats.grpsize1 != 2*n)
        fprintf(stderr,">E group error\n");

 /* If we are using multiple threads, we need to free all the dynamic
    memory we have allocated.  We don't have to do this after each 
    call to nauty, just once before the thread finishes. */

    SG_FREE(sg);
    DYNFREE(lab,lab_sz);
    DYNFREE(ptn,ptn_sz);
    DYNFREE(orbits,orbits_sz);
    nauty_freedyn();
    nautil_freedyn();
    nausparse_freedyn();  /* Use naugraph_freedyn() instead if
                            dense format is being used. */

    return NULL;
}
/**
 * getString
 *
 * Get a sparse6 representation of the 1-graph.
 *
 * @return a buffer containing the string. It will be free()'d by the caller.
 */
char* SaturationGraph::getString()
{
	sparsegraph sg;
	SG_INIT(sg);

	int sn = this->n;
	sg.nv = sn;

	sg.vlen = sn;
	sg.dlen = sn;

	sg.v = (size_t*) malloc(sn * sizeof(size_t));
	sg.d = (int*) malloc(sn * sizeof(int));

	int vindex = 0;

	for ( int i = 0; i < this->n; i++ )
	{
		sg.v[i] = vindex;
		sg.d[i] = this->oneDegrees[i];
		vindex = vindex + this->oneDegrees[i];
	}

	int sde = vindex;
	sg.nde = sde;
	sg.elen = sde;

	sg.e = (int*) malloc(sde * sizeof(int));

	int ve = 0;
	for ( int i = 0; i < this->n; i++ )
	{
		sg.v[i] = ve;

		for ( int j = 0; j < this->n; j++ )
		{
			if ( j != i )
			{
				int index = this->indexOf(i, j);

				/* 1-type edges in this layer */
				if ( this->adjmat[index] == 1 )
				{
					sg.e[ve] = j;
					ve++;
				}
			}
		}
	}

	char* s6 = sgtos6(&sg);

	/* Also, print adjmat and completemult */
	int Nchoose2 = (this->n * (this->n - 1)) / 2;
	char* buff = (char*) malloc(strlen(s6) + 6 * Nchoose2 + 6 * this->n + 5);

	strcpy(buff, s6);

	free(sg.v);
	free(sg.d);
	free(sg.e);

	return buff;
}
/**
 * compactTheGraph() Compact the graph g into small_g.
 */
void SaturationGraph::compactTheGraph()
{
	this->regenerateOpenEdges();

	if ( this->small_g != 0 )
	{
		/* we need to free small_g */
		SG_FREE((*(this->small_g)));
		free(this->small_g);
		this->small_g = 0;
	}

	clock_t start_c = clock();
	this->small_g = (sparsegraph*) malloc(sizeof(sparsegraph));

	SG_INIT((*(this->small_g)));

	/* small_g has two levels: one for each type (0/1) of edge */
	int sn = 2 * this->n;
	this->small_g->nv = sn;

	this->small_g->vlen = sn;
	this->small_g->dlen = sn;

	this->small_g->v = (size_t*) malloc(sn * sizeof(size_t));
	this->small_g->d = (int*) malloc(sn * sizeof(int));

	int vindex = 0;
	for ( int i = 0; i < this->n; i++ )
	{
		this->small_g->v[i] = vindex;
		this->small_g->d[i] = 1 + this->zeroDegrees[i];
		vindex += 1 + this->zeroDegrees[i];
	}
	for ( int i = 0; i < this->n; i++ )
	{
		this->small_g->v[this->n + i] = vindex;
		this->small_g->d[this->n + i] = 1 + this->oneDegrees[i];
		vindex += 1 + this->oneDegrees[i];
	}

	int sde = vindex;
	this->small_g->nde = sde;
	this->small_g->elen = sde;
	this->small_g->e = (int*) malloc(sde * sizeof(int));

	for ( int i = 0; i < this->n; i++ )
	{
		vindex = this->small_g->v[i];

		/* the cross-bar */
		this->small_g->e[vindex] = i + this->n;

		int ve = 1;
		for ( int j = 0; j < this->n; j++ )
		{
			if ( j != i )
			{
				int index = this->indexOf(i, j);

				/* 0-type edges in this layer */
				if ( this->adjmat[index] == 0 )
				{
					this->small_g->e[vindex + ve] = j;
					ve++;
				}
			}
		}
	}
	for ( int i = 0; i < this->n; i++ )
	{
		vindex = this->small_g->v[this->n + i];

		/* the cross-bar */
		this->small_g->e[vindex] = i;

		int ve = 1;
		for ( int j = 0; j < this->n; j++ )
		{
			if ( j != i )
			{
				int index = this->indexOf(i, j);

				/* 1-type edges in this layer */
				if ( this->adjmat[index] == 1 )
				{
					this->small_g->e[vindex + ve] = this->n + j;
					ve++;
				}
			}
		}
	}

	this->g_updated = false;

	clock_t end_c = clock();
	(this->time_in_compact) = this->time_in_compact + (double) (end_c - start_c) / (double) CLOCKS_PER_SEC;
}