Ejemplo n.º 1
0
	void main(int argc, char** argv)
	{
		boost::program_options::options_description options("Usage");
		options.add_options()
			("graphFile", boost::program_options::value<std::string>(), "(path) The path to a graph file, in graphml format. ")
			("help", "Display this message");
		boost::program_options::variables_map variableMap;
		try
		{
			boost::program_options::store(boost::program_options::parse_command_line(argc, argv, options), variableMap);
		}
		catch (boost::program_options::error& ee)
		{
			std::cerr << "Error parsing command line arguments: " << ee.what() << std::endl << std::endl;
			std::cerr << options << std::endl;
			return;
		}
		if (variableMap.count("help") > 0)
		{
			std::cout << "Compute the size of the automorphism group" << std::endl;
			std::cout << options << std::endl;
			return;
		}

		std::ifstream graphStream(variableMap["graphFile"].as<std::string>());
		typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> graphType;
		graphType boostGraph;
		boost::dynamic_properties properties;
		try
		{
			boost::read_graphml(graphStream, boostGraph, properties, 0);
		}
		catch(std::exception& exp)
		{
			std::cout << "Error calling boost::read_graphml: " << exp.what() << std::endl;
			return;
		}
		std::size_t nVertices = boost::num_vertices(boostGraph);
		std::vector<int> lab;
		std::vector<int> ptn;
		std::vector<int> orbits;
		std::vector<graph> nautyGraph;
		std::vector<graph> cannonicalNautyGraph;

		static DEFAULTOPTIONS_GRAPH(nautyOptions);
		statsblk stats;
		//nautyOptions.getcanon = true;
		nautyOptions.userlevelproc = userlevelproc;

		int n = nVertices;
		int m = SETWORDSNEEDED(n);
		nauty_check(WORDSIZE, m, n, NAUTYVERSIONID);
		lab.resize(n);
		ptn.resize(n);
		orbits.resize(n);
		nautyGraph.resize(n * m);
		EMPTYGRAPH(&(nautyGraph[0]), m, n);
		graphType::edge_iterator current, end;
		boost::tie(current, end) = boost::edges(boostGraph);
		for(; current != end; current++)
		{
			ADDONEEDGE(&(nautyGraph[0]), (int)boost::source(*current, boostGraph), (int)boost::target(*current, boostGraph), m);
		}
		//cannonicalNautyGraph.resize(n * m);
		densenauty(&(nautyGraph[0]), &(lab[0]), &(ptn[0]), &(orbits[0]), &nautyOptions, &stats, m, n, &(cannonicalNautyGraph[0]));
		std::cout << product << std::endl;
	}
Ejemplo n.º 2
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;

		/* options.invarproc = &adjacencies_sg; /* sparse version */
		//	options.invarproc = &adjtriang;

		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);
	}
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
    DYNALLSTAT(int,lab1,lab1_sz);
    DYNALLSTAT(int,lab2,lab2_sz);
    DYNALLSTAT(int,ptn,ptn_sz);
    DYNALLSTAT(int,orbits,orbits_sz);
    DYNALLSTAT(int,map,map_sz);
    static DEFAULTOPTIONS_TRACES(options);
    TracesStats stats;
 /* Declare and initialize sparse graph structures */
    SG_DECL(sg1); SG_DECL(sg2);
    SG_DECL(cg1); SG_DECL(cg2);

    int n,m,i;

 /* Select option for canonical labelling */

    options.getcanon = TRUE;
 
 /* Read a number of vertices and process */

    while (1)
    {
        printf("\nenter n : ");
        if (scanf("%d",&n) == 1 && n > 0)
        {
            if (n%2 != 0)
            {
                fprintf(stderr,"Sorry, n must be even\n");
                continue;
            }

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

            DYNALLOC1(int,lab1,lab1_sz,n,"malloc");
            DYNALLOC1(int,lab2,lab2_sz,n,"malloc");
            DYNALLOC1(int,ptn,ptn_sz,n,"malloc");
            DYNALLOC1(int,orbits,orbits_sz,n,"malloc");
            DYNALLOC1(int,map,map_sz,n,"malloc");

         /* Now make the first graph */

            SG_ALLOC(sg1,n,3*n,"malloc");
            sg1.nv = n;              /* Number of vertices */
            sg1.nde = 3*n;           /* Number of directed edges */

            for (i = 0; i < n; ++i)
            {
                sg1.v[i] = 3*i;     /* Position of vertex i in v array */
                sg1.d[i] = 3;       /* Degree of vertex i */
            }
             
            for (i = 0; i < n; i += 2)   /* Spokes */
            {
                sg1.e[sg1.v[i]] = i+1;
                sg1.e[sg1.v[i+1]] = i;
            }

            for (i = 0; i < n-2; ++i)  /* Clockwise edges */
                sg1.e[sg1.v[i]+1] = i+2;
            sg1.e[sg1.v[n-2]+1] = 1;
            sg1.e[sg1.v[n-1]+1] = 0;

            for (i = 2; i < n; ++i)  /* Anticlockwise edges */
                sg1.e[sg1.v[i]+2] = i-2;
            sg1.e[sg1.v[1]+2] = n-2;
            sg1.e[sg1.v[0]+2] = n-1;
                
         /* Now make the second graph */

            SG_ALLOC(sg2,n,3*n,"malloc");
            sg2.nv = n;              /* Number of vertices */
            sg2.nde = 3*n;           /* Number of directed edges */

            for (i = 0; i < n; ++i)
            {
                sg2.v[i] = 3*i;
                sg2.d[i] = 3;
            }

            for (i = 0; i < n; ++i)
            {
                sg2.v[i] = 3*i;
                sg2.d[i] = 3;
                sg2.e[sg2.v[i]] = (i+1) % n;      /* Clockwise */
                sg2.e[sg2.v[i]+1] = (i+n-1) % n;  /* Anti-clockwise */
                sg2.e[sg2.v[i]+2] = (i+n/2) % n;  /* Diagonals */
            }

         /* Label sg1, result in cg1 and labelling in lab1; similarly sg2.
            It is not necessary to pre-allocate space in cg1 and cg2, but
            they have to be initialised as we did above.  */
            
            Traces(&sg1,lab1,ptn,orbits,&options,&stats,&cg1);
            Traces(&sg2,lab2,ptn,orbits,&options,&stats,&cg2);

         /* Compare canonically labelled graphs */

            if (aresame_sg(&cg1,&cg2))
            {
                printf("Isomorphic.\n");
                if (n <= 1000)
                {
                 /* Write the isomorphism.  For each i, vertex lab1[i]
                    of sg1 maps onto vertex lab2[i] of sg2.  We compute
                    the map in order of labelling because it looks better. */

                    for (i = 0; i < n; ++i) map[lab1[i]] = lab2[i];
                    for (i = 0; i < n; ++i) printf(" %d-%d",i,map[i]);
                    printf("\n");
                }
            }
            else
                printf("Not isomorphic.\n");
        }
        else
            break;
    }
Ejemplo n.º 4
0
JNIEXPORT jobjectArray JNICALL Java_org_tmu_core_Nauty_canonize
  (JNIEnv * env, jobject thisobj, jobjectArray arr, jint k){
    int subgraph_size=0;
	graph g[MAXN*MAXM];
	graph canong[MAXN*MAXM];
	int lab[MAXN],ptn[MAXN],orbits[MAXN];
	static DEFAULTOPTIONS_DIGRAPH(options);
	statsblk stats;

	subgraph_size=k;
		
	
	if (subgraph_size > MAXN)
        {
            printf("size of graph must be in the range 1..%d\n",MAXN);
            return NULL;
        }
	
	options.defaultptn = TRUE;
	options.getcanon = TRUE;
	
	
	char bin_adj[BUFSIZE];
	char zeroed_adj[BUFSIZE];
	char str[BUFSIZE];

	int n=subgraph_size;
	int m=SETWORDSNEEDED(n);
	nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
	
	int stringCount = GetArrayLength(env, arr);
	
	jobjectArray ret;
	ret= (jobjectArray)env->NewObjectArray(stringCount,  
         env->FindClass("java/lang/String"),  
         env->NewStringUTF(""));
		 

    
	for (int i=0; i<stringCount; i++) {
        jstring string = (jstring) GetObjectArrayElement(env, arr, i);
        const char *rawString = GetStringUTFChars(env, string, 0);
        strcpy(bin_adj,rawString);
		ReleaseStringUTFChars(rawString);
		int bin_len=strlen(bin_adj);
		if(bin_len<subgraph_size*subgraph_size){
			memset(zeroed_adj,'0',subgraph_size*subgraph_size-bin_len);
		}
		strcpy(zeroed_adj+subgraph_size*subgraph_size-bin_len,bin_adj);		
		EMPTYGRAPH(g,m,n);
		for (int i = 0; i < subgraph_size; i++)
            for (int j = 0; j < subgraph_size; j++)
                if (i!=j&&zeroed_adj[i * subgraph_size + j] == '1')
						ADDONEARC(g,i,j,m);
		
		densenauty(g,lab,ptn,orbits,&options,&stats,m,n,canong);
		
		memset(str,'0',subgraph_size*subgraph_size);
		for (int i = 0; i < subgraph_size; i++) {	
			for(int j = 0; j < subgraph_size; j++) {
				if(i!=j&&zeroed_adj[lab[i]*subgraph_size+lab[j]]=='1') 
					str[i*subgraph_size+j]='1';
			}
		}
		str[subgraph_size*subgraph_size]=0;
		
		env->SetObjectArrayElement(ret,i,env->NewStringUTF(str));
    }   
	
	return ret;  
}
Ejemplo n.º 5
0
static void*
runit(void * threadarg)          /* Main routine for one thread */
{
    DYNALLSTAT(graph,g,g_sz);
    DYNALLSTAT(int,lab,lab_sz);
    DYNALLSTAT(int,ptn,ptn_sz);
    DYNALLSTAT(int,orbits,orbits_sz);
    DEFAULTOPTIONS_GRAPH(options);
    statsblk stats;
    set *gv;

    int n,m,v;

    n = ((params*)threadarg)->n;

 /* Default options are set by the DEFAULTOPTIONS_GRAPH macro above.
    Here we change those options that we want to be different from the
    defaults.  writeautoms=TRUE causes automorphisms to be written.     */

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

    m = SETWORDSNEEDED(n);

 /* The following optional call verifies that we are linking
    to compatible versions of the nauty routines.            */

    nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);

    DYNALLOC2(graph,g,g_sz,m,n,"malloc");
    DYNALLOC1(int,lab,lab_sz,n,"malloc");
    DYNALLOC1(int,ptn,ptn_sz,n,"malloc");
    DYNALLOC1(int,orbits,orbits_sz,n,"malloc");

 /* Now we will make a polygon of n vertices */

    EMPTYGRAPH(g,m,n);
    for (v = 0; v < n; ++v) ADDONEEDGE(g,v,(v+1)%n,m);

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

    if (options.writeautoms)
    {
        printf("order = ");
        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. */

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

    return NULL;
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[])
{
    DYNALLSTAT(int,lab1,lab1_sz);
    DYNALLSTAT(int,lab2,lab2_sz);
    DYNALLSTAT(int,ptn,ptn_sz);
    DYNALLSTAT(int,orbits,orbits_sz);
    DYNALLSTAT(int,map,map_sz);
    DYNALLSTAT(graph,g1,g1_sz);
    DYNALLSTAT(graph,g2,g2_sz);
    DYNALLSTAT(graph,cg1,cg1_sz);
    DYNALLSTAT(graph,cg2,cg2_sz);
    static DEFAULTOPTIONS_GRAPH(options);
    statsblk stats;

    int n,m,i;

 /* Select option for canonical labelling */

    options.getcanon = TRUE;
 
    while (1)
    {
        printf("\nenter n : ");
        if (scanf("%d",&n) == 1 && n > 0)
        {
            if (n%2 != 0)
            {
                fprintf(stderr,"Sorry, n must be even\n");
                continue;
            }

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

            DYNALLOC1(int,lab1,lab1_sz,n,"malloc");
            DYNALLOC1(int,lab2,lab2_sz,n,"malloc");
            DYNALLOC1(int,ptn,ptn_sz,n,"malloc");
            DYNALLOC1(int,orbits,orbits_sz,n,"malloc");
            DYNALLOC1(int,map,map_sz,n,"malloc");
            DYNALLOC2(graph,g1,g1_sz,n,m,"malloc");
            DYNALLOC2(graph,g2,g2_sz,n,m,"malloc");
            DYNALLOC2(graph,cg1,cg1_sz,n,m,"malloc");
            DYNALLOC2(graph,cg2,cg2_sz,n,m,"malloc");

         /* Now make the first graph */
         /* ADDEDGE() is defined above */

            EMPTYGRAPH(g1,m,n);  /* start with no edges */

            for (i = 0; i < n-2; ++i) ADDONEEDGE(g1,i,i+2,m);
            ADDONEEDGE(g1,n-2,1,m);
            ADDONEEDGE(g1,n-1,0,m);
            for (i = 0; i < n; i += 2) ADDONEEDGE(g1,i,i+1,m);

         /* Now make the second graph */

            EMPTYGRAPH(g2,m,n);  /* start with no edges */

            for (i = 0; i < n-1; ++i) ADDONEEDGE(g2,i,i+1,m);
            ADDONEEDGE(g2,n-1,0,m);
            for (i = 0; i < n/2; ++i) ADDONEEDGE(g2,i,i+n/2,m);

         /* Label g1, result in cg1 and labelling in lab1; similarly g2.
            It is not necessary to pre-allocate space in cg1 and cg2, but
            they have to be initialised as we did above.  */
            
            densenauty(g1,lab1,ptn,orbits,&options,&stats,m,n,cg1);
            densenauty(g2,lab2,ptn,orbits,&options,&stats,m,n,cg2);

         /* Compare canonically labelled graphs */

            if (memcmp(cg1,cg2,m*sizeof(graph)*n) == 0)
            {
                printf("Isomorphic.\n");
                if (n <= 1000)
                {
                 /* Write the isomorphism.  For each i, vertex lab1[i]
                    of sg1 maps onto vertex lab2[i] of sg2.  We compute
                    the map in order of labelling because it looks better. */

                    for (i = 0; i < n; ++i) map[lab1[i]] = lab2[i];
                    for (i = 0; i < n; ++i) printf(" %d-%d",i,map[i]);
                    printf("\n");
                }
            }
            else
                printf("Not isomorphic.\n");
        }
        else
            break;
    }
Ejemplo n.º 7
0
/* Cette fonction génère les structures qui vont bien pour les appels à Nauty */
void Carquois::genGraph()
{
    int i,j,m,nbSommetsNauty;
    int lab1[MAXN],ptn[MAXN],orbits[MAXN];
    static DEFAULTOPTIONS_GRAPH(options);
    statsblk stats;
    setword workspace[5*MAXM];
    
    if(!this->graphAJour)
    {
        
        nbSommetsNauty = 2 * this->getN();
        m=(nbSommetsNauty + WORDSIZE - 1)/WORDSIZE;

        /* Si on trouve une valeur strictement positive dans la matrice d'incidence, alors on ajoute une arrête dans notre graphe */
        for(i=0;i<this->getN();i++)
        {
            gv=GRAPHROW(nautyG,i+this->getN(),m);
            EMPTYSET(gv,m);
            
            gv=GRAPHROW(nautyG,i,m);
            EMPTYSET(gv,m);
            /* On ajoute les fausses arrêtes entre le layer 0 et le layer 1 */
            ADDELEMENT(gv,i+this->getN());
            for(j=0;j<this->getN();j++)
            {
                /* multiplicité de 1 */
                if(this->getM(i,j)==1)
                {
                    gv=GRAPHROW(nautyG,i,m);
                    ADDELEMENT(gv,j);
                }
                else
                {
                    if(this->getM(i,j)==2)
                    {
                        gv=GRAPHROW(nautyG,i+this->getN(),m);
                        ADDELEMENT(gv,j+this->getN());
                    }
                }
            }
        }
        options.getcanon = TRUE;
        options.digraph = TRUE;
        options.defaultptn = FALSE;
        nauty_check(WORDSIZE,m,nbSommetsNauty,NAUTYVERSIONID);
        
        for(i=0;i<2*n;i++)
        {
            lab1[i]=i;
            ptn[i]=1;
        }
        ptn[n-1]=0;
        ptn[2*n-1]=0;
        
        
        nauty(nautyG,lab1,ptn,NULL,orbits,&options,&stats,
                                  workspace,5*MAXM,m,nbSommetsNauty,nautyGC);
        this->graphAJour=1;    
    }
}
Ejemplo n.º 8
0
main(int argc, char *argv[])
#endif
{
        char *arg;
        boolean badargs,gotd,gotD,gotf,gotmr;
	boolean secret,connec1;
	char *outfilename,sw;
        int i,j,argnum;
        graph g[1];
        int deg[1];
	int splitlevinc;
	xword testxword;
        double t1,t2;
	char msg[201];

	HELP;
	nauty_check(WORDSIZE,1,MAXN,NAUTYVERSIONID);

	testxword = (xword)(-1);
	if (MAXN > 32 || MAXN > WORDSIZE || MAXN > 8*sizeof(xword)
	    || (MAXN == 8*sizeof(xword) && testxword < 0))
	{
	    fprintf(stderr,"gentourng: incompatible MAXN, WORDSIZE, or xword\n");
	    fprintf(stderr,"--See notes in program source\n");
	    exit(1);
	}

        badargs = FALSE;
	graph6 = FALSE;
	sparse6 = FALSE;
        nooutput = FALSE;
        canonise = FALSE;
	header = FALSE;
	outfilename = NULL;
	secret = FALSE;
	connec1 = FALSE;

        maxdeg = MAXN; 
	mindeg = 0;
	splitlevinc = 0;
	
	gotd = gotD = gotf = gotmr = FALSE;

        argnum = 0;
        for (j = 1; !badargs && j < argc; ++j)
        {
            arg = argv[j];
            if (arg[0] == '-' && arg[1] != '\0')
            {
		++arg;
		while (*arg != '\0')
		{
		    sw = *arg++;
		         SWBOOLEAN('u',nooutput)
		    else SWBOOLEAN('g',graph6)
		    else SWBOOLEAN('s',sparse6)
		    else SWBOOLEAN('l',canonise)
		    else SWBOOLEAN('h',header)
		    else SWBOOLEAN('q',quiet)
		    else SWBOOLEAN('c',connec1)
		    else SWBOOLEAN('$',secret)
		    else SWINT('d',gotd,mindeg,"gentourng -d")
		    else SWINT('D',gotD,maxdeg,"gentourng -D")
#ifdef PLUGIN_SWITCHES
PLUGIN_SWITCHES
#endif
                    else badargs = TRUE;
		}
            }
            else if (arg[0] == '-' && arg[1] == '\0')