/*************************************** * this routine constructs the encoder * * for every new codeword * **************************************/ void constructencoder(graphs * graph, channels * channel, encoders * encoder, simulations * simulation, int loop) { int node; if (loop == -1) { // if encoder shall be used and encoder has not been built // then build one if (((*encoder).useencoder == 1) && ((*encoder).gap < 0)) { /* run greedy algorithm to find approximate */ /* upper triangulation */ uppertriangulation(graph, &(*encoder).gap, 0); /* build encoder */ determineiphi(graph, encoder, (*simulation).graphfile, 0); /* read the modified graph and encoder back */ readgraph(graph, encoder, (*simulation).graphfile, (*simulation).verbose); } else { /* store the inverse etc in the file */ savegraph(graph, encoder, (*simulation).graphfile, 0); } } else if (loop >= 0) { if ((*encoder).useencoder == 1) { { /* run greedy algorithm to find approximate */ /* upper triangulation */ uppertriangulation(graph, &(*encoder).gap, 0); determineiphi(graph, encoder, (*simulation).graphfile, 0); readgraph(graph, encoder, (*simulation).graphfile, (*simulation).verbose); /* store the inverse etc in the file */ savegraph(graph, encoder, (*simulation).graphfile, 0); } } } }
int main() { int start; printf("\nDIJKSTRA ALGORITHM"); readgraph(); displaymat(); inittable(); printf("\nEnter the starting Vertex:"); scanf("%d",&start); dj(start); printf("\nfinal:"); displaytable(); getch(); return 0; }
int main() { int i, j, k; readgraph(); for (k = 1; k <= n; k++) for (i = 1; i <= n; i++) if (adjacent[i][k]) for (j = 1; j <= n; j++) adjacent[i][j] |= adjacent[k][j]; printf("推移的閉包:\n"); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) printf(" %d", adjacent[i][j]); printf("\n"); } return EXIT_SUCCESS; }
/*************************************************************************************************************************** Main Function(Serial and Parallel Fault Simulation) ****************************************************************************************************************************/ void main(int argc,char **argv) { FILE *fisc,*fvec,*ffau,*fres; //file pointers used for .isc file, .vec file, .faults file and resultfile int Max,Opt,Npi,Npo,Tot,Tfs; //maxnode id,option,tot no of PIs,tot no of Pos,Tot no of input patterns& faults in.vec in.faults clock_t is,it; //execution time clock signals double iexe; //execution time NODE graph[Mnod]; //structure used to store the ckt information in .isc file PATTERN vector[Mpt]; //structure used to store the input vectors information in .vec file FAULT struck[Mft]; //structure used to store the faults information in .faults file int a,b,c,d; //random variables //Read the .isc file and store the information in graph structure is=clock(); //starting timer fisc=fopen(argv[1],"r"); //file pointer to open .isc file Max=0; Max=ReadIsc(fisc,graph); //read .isc file and return index of last node in graph formed fclose(fisc); //close file pointer for .isc file it=clock(); //ending the timer iexe=((double)(it-is))/CLOCKS_PER_SEC; //execuetion time calculation PrintCircuit(graph,Max); //print all members of graph structure printf("\nTime Taken for ISC File: %f",iexe); //print execuetion time //Read the .vec file and store the information in vector structure fvec=fopen(argv[2],"r"); //file pointer to open .vec file Tot=0; Tot=ReadVec(fvec,vector); //read .vec file and store in vector structure and return tot number of patterns printf("\nTot No of Pattern: %d",Tot); //print total number of patterns in .vec file fclose(fvec); //close file pointer for .vec file printf("\nIndex\tInputVector\n"); for(a=0;a<Tot;a++){ printf("%d\t%s",a,vector[a].piv); } //print all members of vector structure ffau=fopen(argv[4],"r"); Tfs = Readfault(ffau,struck); fclose(ffau); for(a=0;a<Tfs;a++){ printf("%d/%d \n",struck[a].nod,struck[a].sval); } fres=fopen(argv[3],"w"); //file pointer to open .out file for printing results readgraph(graph, vector, fres, Max,Tot,struck,Tfs); //call the readgraph function to process and print outputs //Perform Logic Simulationfor each Input vector and print the Pos .val in output file fclose(fres); //close file pointer for .out file ClearCircuit(graph,Mnod); //clear memeory for all members of graph for(a=0;a<Tot;a++){ bzero(vector[a].piv,Mpi); } //clear memeory for all members of vector return; }//end of main
int main(int argc, char *argv[]) { if (argc==2) readgraph(argv[1]); else printf("Usage: %s name_of_file_containing_the_graph\n", argv[0]); dfs(graph); //O(|E| + |V|) depth first search printNodesWithNumber(); dfsBackedge(graph); //a second O(|E| + |V|) depth first search to check for backedges if(HAS_BACKEDGE==0) //no backedges found { printf("Is a valid DAG\n"); printLinearization(); } else { printf("Not a valid DAG\n"); } }
void StorageLog::on_start_up(int fd) { unsigned char* superblock_pt; ssize_t freeresult; superblock_pt = get_superblock(fd); Superblock* pt = (Superblock*) superblock_pt; if(isValid(superblock_pt)) { edge_list = readgraph(pt->logsize, fd); play_log(fd, pt->generation); print_graph(edge_list); } else { printf("superblock is invalid on startup\n"); exit(-1); } printf("one_start_up, edge_list is of size: %lu\n", edge_list.size()); freeresult = munmap(superblock_pt, PAGESIZE); if(freeresult < 0) { printf("free superblock failed in on_start_up\n"); } }
void insertgraph( ) { int i; char graphname[30]; notavailable( ); /* comment this out */ storeline( curline ); blockmsg( 5 ); dispstrhgc( "ãÊèª×èÍá¿éÁÃÙ»ÀÒ¾·Õèµéͧ¡ÒÃÍèÒ¹ :", ( 14 + center_factor ) + 3, 6, REVERSEATTR ); strcpy( graphname, "*.*" ); i = getname( graphname, ( 14 + center_factor ) + 28, 5, 22, REVERSEATTR ); if ( ( i == YES ) && ( graphname[0] != '\0' ) ) { if ( havewild( graphname ) ) { selectfile( graphname ); } curline->graph = readgraph( graphname ); } changeflag = YES; pagecomplete = NO; loadtoline( curline->text ); }
EXTRADECLS #endif /***************************************************************************** * * * This is a program which illustrates the use of nauty. * * Commands are read from stdin, and may be separated by white space, * * commas or not separated. Output is written to stdout. * * For a short description, see the nauty User's Guide. * * * *****************************************************************************/ main() { int m,n,newm,newn; boolean gvalid,ovalid,cvalid,pvalid,minus,prompt,doquot; int i,worksize,numcells,refcode,umask,qinvar; int oldorg; char *s1,*s2,*invarprocname; int c,d; register long li; set *gp; double timebefore,timeafter; char filename[100]; graph *savedg; nvector *savedlab; int sgn,sgactn,sgorg; int cgactn,gactn; curfile = 0; fileptr[curfile] = stdin; prompt = DOPROMPT(INFILE); outfile = stdout; n = m = 1; #ifdef INITSEED INITSEED; #endif umask = 0; pvalid = FALSE; gvalid = FALSE; ovalid = FALSE; cvalid = FALSE; minus = FALSE; worksize = 2*MAXM*WORKSIZE; labelorg = oldorg = 0; cgactn = sgactn = gactn = 0; #ifdef DYNALLOC workspace = (setword*) ALLOCS(WORKSIZE,2*MAXM*sizeof(setword)); ptn = (nvector*) ALLOCS(MAXN,sizeof(nvector)); orbits = (nvector*) ALLOCS(MAXN,sizeof(nvector)); perm = (permutation*) ALLOCS(MAXN,sizeof(permutation)); if (workspace == NILSET || ptn == (nvector*)NULL || orbits == (nvector*)NULL || perm == (permutation*)NULL) { fprintf(ERRFILE,"ALLOCS failed; reduce MAXN.\n\n"); EXIT; } #endif #ifdef INITIALIZE INITIALIZE; #endif allocg(&g,&lab,&gactn,n); if (gactn == 0) { fprintf(ERRFILE,"ALLOCS failed for g: this shouldn't happen.\n\n"); EXIT; } invarprocname = "none"; if (prompt) { fprintf(PROMPTFILE,"Dreadnaut version %s.\n",DREADVERSION); fprintf(PROMPTFILE,"> "); } /* Calling dummy routines in nautinv.c, nauty.c and nautil.c causes those segments to get loaded in various Macintosh variants. This causes an apparent, but illusory, improvement in the time required for the first call to nauty(). */ nautinv_null(); nautil_null(); nauty_null(); while (curfile >= 0) if ((c = getc(INFILE)) == EOF || c == '\004') { fclose(INFILE); --curfile; if (curfile >= 0) prompt = DOPROMPT(INFILE); } else switch (c) { case '\n': /* possibly issue prompt */ if (prompt) fprintf(PROMPTFILE,"> "); minus = FALSE; break; case ' ': /* do nothing */ case '\t': #ifndef NLMAP case '\r': #endif case '\f': break; case '-': /* remember this for next time */ minus = TRUE; break; case '+': /* forget - */ case ',': case ';': minus = FALSE; break; case '<': /* new input file */ minus = FALSE; if (curfile == MAXIFILES - 1) fprintf(ERRFILE,"exceeded maximum input nesting of %d\n\n", MAXIFILES); if (!readstring(INFILE,filename)) { fprintf(ERRFILE, "missing file name on '>' command : ignored\n\n"); break; } if ((fileptr[curfile+1] = fopen(filename,"r")) == NULL) { for (s1 = filename; *s1 != '\0'; ++s1) {} for (s2 = def_ext; (*s1 = *s2) != '\0'; ++s1, ++s2) {} fileptr[curfile+1] = fopen(filename,"r"); } if (fileptr[curfile+1] != NULL) { ++curfile; prompt = DOPROMPT(INFILE); if (prompt) fprintf(PROMPTFILE,"> "); } else fprintf(ERRFILE,"can't open input file\n\n"); break; case '>': /* new output file */ if ((d = getc(INFILE)) != '>') ungetc((char)d,INFILE); if (minus) { minus = FALSE; if (outfile != stdout) { fclose(outfile); outfile = stdout; } } else { if (!readstring(INFILE,filename)) { fprintf(ERRFILE, "improper file name, reverting to stdout\n\n"); outfile = stdout; break; } OPENOUT(outfile,filename,d=='>'); if (outfile == NULL) { fprintf(ERRFILE, "can't open output file, reverting to stdout\n\n"); outfile = stdout; } } break; case '!': /* ignore rest of line */ do c = getc(INFILE); while (c != '\n' && c != EOF); if (c == '\n') ungetc('\n',INFILE); break; case 'n': /* read n value */ minus = FALSE; i = getint(INFILE); if (i <= 0 || i > MAXN) fprintf(ERRFILE, " n can't be less than 1 or more than %d\n\n",MAXN); else { gvalid = FALSE; ovalid = FALSE; cvalid = FALSE; pvalid = FALSE; n = i; m = (n + WORDSIZE - 1) / WORDSIZE; allocg(&g,&lab,&gactn,n); if (gactn == 0) { fprintf(ERRFILE,"can't allocate space for graph\n"); n = m = 1; break; } } break; case 'g': /* read graph */ minus = FALSE; readgraph(INFILE,g,options.digraph,prompt,FALSE, options.linelength,m,n); gvalid = TRUE; cvalid = FALSE; ovalid = FALSE; break; case 'e': /* edit graph */ minus = FALSE; readgraph(INFILE,g,options.digraph,prompt,gvalid, options.linelength,m,n); gvalid = TRUE; cvalid = FALSE; ovalid = FALSE; break; case 'r': /* relabel graph and current partition */ minus = FALSE; if (gvalid) { allocg(&canong,(nvector**)NULL,&cgactn,n); if (cgactn == 0) { fprintf(ERRFILE, "can't allocate work space for 'r'\n\n"); break; } readperm(INFILE,perm,prompt,n); relabel(g,(pvalid ? lab : (nvector*)NULL),perm,canong,m,n); cvalid = FALSE; ovalid = FALSE; } else fprintf(ERRFILE,"g is not defined\n\n"); break; case '_': /* complement graph */ minus = FALSE; if (gvalid) { complement(g,m,n); cvalid = FALSE; ovalid = FALSE; } else fprintf(ERRFILE,"g is not defined\n\n"); break; case '@': /* copy canong into savedg */ minus = FALSE; if (cvalid) { allocg(&savedg,&savedlab,&sgactn,n); if (sgactn == 0) { fprintf(ERRFILE,"can`t allocate space for h'\n\n"); break; } sgn = n; for (li = (long)n * (long)m; --li >= 0;) savedg[li] = canong[li]; for (i = n; --i >= 0;) savedlab[i] = lab[i]; sgorg = labelorg; } else fprintf(ERRFILE,"h is not defined\n\n"); break; case '#': /* compare canong to savedg */ if ((d = getc(INFILE)) != '#') ungetc((char)d,INFILE); if (cvalid) { if (sgactn > 0) { if (sgn != n) fprintf(OUTFILE, "h and h' have different sizes.\n"); else { for (li = (long)n * (long)m; --li >= 0;) if (savedg[li] != canong[li]) break; if (li >= 0) fprintf(OUTFILE, "h and h' are different.\n"); else { fprintf(OUTFILE, "h and h' are identical.\n"); if (d == '#') putmapping(OUTFILE,savedlab,sgorg, lab,labelorg,options.linelength,n); } } } else fprintf(ERRFILE,"h' is not defined\n\n"); } else fprintf(ERRFILE,"h is not defined\n\n"); break; case 'j': /* relabel graph randomly */ minus = FALSE; if (gvalid) { allocg(&canong,(nvector**)NULL,&cgactn,n); if (cgactn == 0) { fprintf(ERRFILE, "can't allocate work space for 'j'\n\n"); break; } ranperm(perm,n); relabel(g,(pvalid ? lab : (nvector*)NULL),perm,canong,m,n); cvalid = FALSE; ovalid = FALSE; } else fprintf(ERRFILE,"g is not defined\n\n"); break; case 'v': /* write vertex degrees */ minus = FALSE; if (gvalid) putdegs(OUTFILE,g,options.linelength,m,n); else fprintf(ERRFILE,"g is not defined\n\n"); break; case '%': /* do Mathon doubling operation */ minus = FALSE; if (gvalid) { if (2L * ((long)n + 1L) > MAXN) { fprintf(ERRFILE,"n can't be more than %d\n\n",MAXN); break; } newn = 2 * (n + 1); newm = (newn + WORDSIZE - 1) / WORDSIZE; allocg(&canong,(nvector**)NULL,&cgactn,n); if (cgactn == 0) { fprintf(ERRFILE, "can't allocate work space for '%'\n\n"); break; } for (li = (long)n * (long)m; --li >= 0;) canong[li] = g[li]; allocg(&g,&lab,&gactn,newn); if (gactn == 0) { fprintf(ERRFILE,"can't allocate space for graph \n\n"); break; } mathon(canong,m,n,g,newm,newn); m = newm; n = newn; cvalid = FALSE; ovalid = FALSE; pvalid = FALSE; } else fprintf(ERRFILE,"g is not defined\n\n"); break; case 's': /* generate random graph */ minus = FALSE; i = getint(INFILE); if (i <= 0) i = 2; rangraph(g,options.digraph,i,m,n); gvalid = TRUE; cvalid = FALSE; ovalid = FALSE; break; case 'q': /* quit */ EXIT; break; case '"': /* copy comment to output */ minus = FALSE; copycomment(INFILE,OUTFILE,'"'); break; case 'I': /* do refinement and invariants procedure */ if (!pvalid) unitptn(lab,ptn,&numcells,n); cellstarts(ptn,0,active,m,n); #ifdef CPUTIME timebefore = CPUTIME; #endif doref(g,lab,ptn,0,&numcells,&qinvar,perm,active,&refcode, refine,options.invarproc, 0,0,options.invararg,options.digraph,m,n); #ifdef CPUTIME timeafter = CPUTIME; #endif fprintf(OUTFILE," %d cell%s; code = %x", SS(numcells,"","s"),refcode); if (options.invarproc != NILFUNCTION) fprintf(OUTFILE," (%s %s)",invarprocname, (qinvar == 2 ? "worked" : "failed")); #ifdef CPUTIME fprintf(OUTFILE,"; cpu time = %.2f seconds\n", timeafter-timebefore); #else fprintf(OUTFILE,"\n"); #endif if (numcells > 1) pvalid = TRUE; break; case 'i': /* do refinement */ if (!pvalid) unitptn(lab,ptn,&numcells,n); cellstarts(ptn,0,active,m,n); if (m == 1) refine1(g,lab,ptn,0,&numcells,perm,active,&refcode,m,n); else refine(g,lab,ptn,0,&numcells,perm,active,&refcode,m,n); fprintf(OUTFILE," %d cell%s; code = %x\n", SS(numcells,"","s"),refcode); if (numcells > 1) pvalid = TRUE; break; case 'x': /* execute nauty */ minus = FALSE; ovalid = FALSE; cvalid = FALSE; if (!gvalid) { fprintf(ERRFILE,"g is not defined\n\n"); break; } if (pvalid) { fprintf(OUTFILE,"[fixing partition]\n"); options.defaultptn = FALSE; } else options.defaultptn = TRUE; options.outfile = outfile; if (options.getcanon) { allocg(&canong,(nvector**)NULL,&cgactn,n); if (cgactn == 0) { fprintf(ERRFILE,"can't allocate space for h\n\n"); break; } } firstpath = TRUE; #ifdef CPUTIME timebefore = CPUTIME; #endif nauty(g,lab,ptn,NILSET,orbits,&options,&stats,workspace, worksize,m,n,canong); #ifdef CPUTIME timeafter = CPUTIME; #endif if (stats.errstatus != 0) fprintf(ERRFILE, "nauty returned error status %d [this can't happen]\n\n", stats.errstatus); else { if (options.getcanon) cvalid = TRUE; ovalid = TRUE; fprintf(OUTFILE,"%d orbit%s",SS(stats.numorbits,"","s")); if (stats.grpsize2 == 0) fprintf(OUTFILE,"; grpsize=%.0f",stats.grpsize1+0.1); else { while (stats.grpsize1 >= 10.0) { stats.grpsize1 /= 10.0; ++stats.grpsize2; } fprintf(OUTFILE,"; grpsize=%12.10fe%d", stats.grpsize1,stats.grpsize2); } fprintf(OUTFILE,"; %d gen%s", SS(stats.numgenerators,"","s")); fprintf(OUTFILE,"; %ld node%s",SS(stats.numnodes,"","s")); if (stats.numbadleaves) fprintf(OUTFILE," (%ld bad lea%s)", SS(stats.numbadleaves,"f","ves")); fprintf(OUTFILE,"; maxlev=%d\n", stats.maxlevel); fprintf(OUTFILE,"tctotal=%ld",stats.tctotal); if (options.getcanon) fprintf(OUTFILE,"; canupdates=%ld",stats.canupdates); #ifdef CPUTIME fprintf(OUTFILE,"; cpu time = %.2f seconds\n", timeafter-timebefore); #else fprintf(OUTFILE,"\n"); #endif if (options.invarproc != NILFUNCTION && options.maxinvarlevel != 0) { fprintf(OUTFILE,"invarproc \"%s\" succeeded %ld/%ld", invarprocname,stats.invsuccesses,stats.invapplics); if (stats.invarsuclevel > 0) fprintf(OUTFILE," beginning at level %d.\n", stats.invarsuclevel); else fprintf(OUTFILE,".\n"); } } break; case 'f': /* read initial partition */ if (minus) { pvalid = FALSE; minus = FALSE; } else { readptn(INFILE,lab,ptn,&numcells,prompt,n); pvalid = TRUE; } break; case 't': /* type graph */ minus = FALSE; if (!gvalid) fprintf(ERRFILE,"g is not defined\n\n"); else putgraph(OUTFILE,g,options.linelength,m,n); break; case 'T': /* type graph preceded by n, $ and g commands */ minus = FALSE; if (!gvalid) fprintf(ERRFILE,"g is not defined\n\n"); else { fprintf(OUTFILE,"n=%d $=%d g\n",n,labelorg); putgraph(OUTFILE,g,options.linelength,m,n); fprintf(OUTFILE,"$$\n"); } break; case 'u': /* call user procs */ if (minus) { umask = 0; minus = FALSE; } else { umask = getint(INFILE); if (umask < 0) umask = ~0; } if (umask & U_NODE) options.usernodeproc = NODEPROC; else options.usernodeproc = NILFUNCTION; if (umask & U_AUTOM) options.userautomproc = AUTOMPROC; else options.userautomproc = NILFUNCTION; if (umask & U_LEVEL) options.userlevelproc = LEVELPROC; else options.userlevelproc = NILFUNCTION; if (umask & U_TCELL) options.usertcellproc = TCELLPROC; else options.usertcellproc = NILFUNCTION; if (umask & U_REF) options.userrefproc = REFPROC; else options.userrefproc = NILFUNCTION; break; case 'o': /* type orbits */ minus = FALSE; if (ovalid) putorbits(OUTFILE,orbits,options.linelength,n); else fprintf(ERRFILE,"orbits are not defined\n\n"); break; case 'b': /* type canonlab and canong */ minus = FALSE; if (cvalid) putcanon(OUTFILE,lab,canong,options.linelength,m,n); else fprintf(ERRFILE,"h is not defined\n\n"); break; case 'z': /* type hashcode for canong */ minus = FALSE; if (cvalid) fprintf(OUTFILE,"[%8lx %8lx]\n", hash(canong,(long)m * (long)n,13), hash(canong,(long)m * (long)n,7)); else fprintf(ERRFILE,"h is not defined\n\n"); break; case 'c': /* set getcanon option */ options.getcanon = !minus; minus = FALSE; break; case 'w': /* read size of workspace */ minus = FALSE; worksize = getint(INFILE); if (worksize > 2*MAXM*WORKSIZE) { fprintf(ERRFILE, "too big - setting worksize = %d\n\n", 2*MAXM*WORKSIZE); worksize = 2*MAXM*WORKSIZE; } break; case 'l': /* read linelength for output */ options.linelength = getint(INFILE); minus = FALSE; break; case 'y': /* set tc_level field of options */ options.tc_level = getint(INFILE); minus = FALSE; break; case 'k': /* set invarlev fields of options */ options.mininvarlevel = getint(INFILE); options.maxinvarlevel = getint(INFILE); minus = FALSE; break; case 'K': /* set invararg field of options */ options.invararg = getint(INFILE); minus = FALSE; break; case '*': /* set invarproc field of options */ minus = FALSE; d = getint(INFILE); if (d >= -1 && d <= NUMINVARS-2) { options.invarproc = invarproc[d+1].entrypoint; invarprocname = invarproc[d+1].name; } else fprintf(ERRFILE,"no such vertex-invariant\n\n"); break; case 'a': /* set writeautoms option */ options.writeautoms = !minus; minus = FALSE; break; case 'm': /* set writemarkers option */ options.writemarkers = !minus; minus = FALSE; break; case 'p': /* set cartesian option */ options.cartesian = !minus; minus = FALSE; break; case 'd': /* set digraph option */ if (options.digraph && minus) gvalid = FALSE; options.digraph = !minus; minus = FALSE; break; case '$': /* set label origin */ if ((d = getc(INFILE)) == '$') labelorg = oldorg; else { ungetc((char)d,INFILE); oldorg = labelorg; i = getint(INFILE); if (i < 0) fprintf(ERRFILE,"labelorg must be >= 0\n\n"); else labelorg = i; } break; case '?': /* type options, etc. */ minus = FALSE; fprintf(OUTFILE,"m=%d n=%d labelorg=%d",m,n,labelorg); if (!gvalid) fprintf(OUTFILE," g=undef"); else { li = 0; for (i = 0, gp = g; i < n; ++i, gp += m) li += setsize(gp,m); if (options.digraph) fprintf(OUTFILE," arcs=%ld",li); else fprintf(OUTFILE," edges=%ld",li/2); } fprintf(OUTFILE," options=(%cc%ca%cm%cp%cd", PM(options.getcanon),PM(options.writeautoms), PM(options.writemarkers),PM(options.cartesian), PM(options.digraph)); if (umask & 31) fprintf(OUTFILE," u=%d",umask&31); if (options.tc_level > 0) fprintf(OUTFILE," y=%d",options.tc_level); if (options.mininvarlevel != 0 || options.maxinvarlevel != 0) fprintf(OUTFILE," k=(%d,%d)", options.mininvarlevel,options.maxinvarlevel); if (options.invararg > 0) fprintf(OUTFILE," K=%d",options.invararg); fprintf(OUTFILE,")\n"); fprintf(OUTFILE,"linelen=%d worksize=%d input_depth=%d", options.linelength,worksize,curfile); if (options.invarproc != NILFUNCTION) fprintf(OUTFILE," invarproc=%s",invarprocname); if (pvalid) fprintf(OUTFILE,"; %d cell%s",SS(numcells,"","s")); else fprintf(OUTFILE,"; 1 cell"); fprintf(OUTFILE,"\n"); if (OUTFILE != PROMPTFILE) fprintf(PROMPTFILE,"m=%d n=%d depth=%d labelorg=%d\n", m,n,curfile,labelorg); break; case '&': /* list the partition and possibly the quotient */ if ((d = getc(INFILE)) == '&') doquot = TRUE; else { ungetc((char)d,INFILE); doquot = FALSE; } minus = FALSE; if (pvalid) putptn(OUTFILE,lab,ptn,0,options.linelength,n); else fprintf(OUTFILE,"unit partition\n"); if (doquot) { if (!pvalid) unitptn(lab,ptn,&numcells,n); putquotient(OUTFILE,g,lab,ptn,0,options.linelength,m,n); } break; case 'h': /* type help information */ minus = FALSE; help(PROMPTFILE); break; default: /* illegal command */ fprintf(ERRFILE,"'%c' is illegal - type 'h' for help\n\n",c); flushline(INFILE); if (prompt) fprintf(PROMPTFILE,"> "); break; } /* end of switch */ }
void main(int argc, char *argv[]) { int c, i; int statistics = 0; int draw = 0; char initialize = 'p'; extern char *optarg; #ifndef NOTIMES srand48((long)time(NULL)); #else srand48(0); #endif //NOTIMES if (readgraph()) exit(1); if (nvertices == 0) { fprintf(stderr, "Empty graph\n"); exit(1); } if (nvertices < 200) iter[1] = 200; else iter[1] = nvertices; iter[0] = iter[1] / 20; iter[2] = iter[1] / 10; height = 0.65 * sqrt((double)nvertices); while ((c = getopt(argc, argv, "fg:i:n:osv:w:B:D:E:H:NOW:")) != EOF) { switch (c) { case 'f': flat = 1; break; case 'g': sscanf( optarg, "%d,%d,%d", &(gstep[0]), &(gstep[1]), &(gstep[2]) ); draw = 1; break; case 'i': initialize = optarg[0]; break; break; case 'n': sscanf( optarg, "%d,%d,%d", &(iter[0]), &(iter[1]), &(iter[2]) ); break; case 'o': fprintf(stdout,"%d\n",getpid()); fflush(stdout); break; case 's': statistics = 1; break; case 'v': sscanf( optarg, "%d,%d,%d", &(vstep[0]), &(vstep[1]), &(vstep[2]) ); break; case 'w': bestangle = atof( optarg ) / 180.0 * M_PI; break; case 'B': frames_begin = atoi( optarg ); break; case 'D': maxdist = atof( optarg ); break; case 'E': frames_end = atoi( optarg ); break; case 'H': height = atof( optarg ); break; case 'N': print_frame_count = 1; break; case 'O': count_only = print_frame_count = 1; break; case 'W': sleep_ms = atoi(optarg); break; case '?': fprintf(stderr, "%s: unknown option -%c\n", argv[0], c); exit(1); } } switch(initialize) { case 'r': random_positions(); break; case 's': initial_positions_planar(1); break; case 'z': zero_out_positions(); break; case 'p': initial_positions_planar(0); break; default: break; } for (i = 1; i <= nvertices; i++) { vertices[i].saved_pos.x = vertices[i].pos.x; vertices[i].saved_pos.y = vertices[i].pos.y; vertices[i].saved_pos.z = vertices[i].pos.z; } maxstep = iter[0] + iter[1] + iter[2]; #if USE_TCL if (draw > 0) { init_tk(); draw_graph(0); sprintf(tcl_command_buffer, "stop_go"); c = Tcl_Eval(interp, tcl_command_buffer); if (c != TCL_OK) { fprintf(stderr, "in Tcl_Eval: %s\n", interp->result); exit(c); } } #endif /*USE_TCL*/ if (position()) exit(1); if (writegraph()) exit(1); if (statistics) show_statistics(); #if USE_TCL if (draw > 0) exit_tk(); #endif /*USE_TCL*/ }
int main(void) { int i=0; problem *p = readparameters(&nodes,&edges); if(!p) { printf("readparameters failed."); exit(1); } printf("Knoten:\t\t%4d\n Angebot:\t%4d\n Nachfrage:\t%4d\nKanten:\t\t%4d\n\n",nodes,p->angebot,p->nachfrage,edges); readgraph(p); printf("Kosten auf Kanten nach dem Einlesen:\n\n"); printgraph(p); matrix *x = newmatrix(p->angebot,p->nachfrage); /* Solange noch Spalten oder Zeilen vorhanden, Kante waehlen, * in die Basisloesung aufnehmen und Vogel-Werte neu berechnen. */ /* for(i=0; i < p->angebot+p->nachfrage-1; i++) { waehlekante_vogel(p,x); vogel(p); } printf("\n\nBasislösung nach Vogel:\n\n"); printmatrix(x); p = readparameters(&nodes,&edges); readgraph(p); x = newmatrix(p->angebot,p->nachfrage); */ for(i=0; i < p->angebot+p->nachfrage-1; i++) { waehlekante_nwe(p,x); } printf("\n\nBasislösung nach Nordwest-Ecken-Regel:\n\n"); printmatrix(x); /* p = readparameters(&nodes,&edges); readgraph(p); x = newmatrix(p->angebot,p->nachfrage); for(i=0; i < p->angebot+p->nachfrage-1; i++) { waehlekante_mkk(p,x); } printf("\n\nBasislösung nach Methode der kleinsten Kosten:\n\n"); printmatrix(x); */ /* Stepping stone */ /* stepstone(x,p); printf("\n\nBasislösung nach Stepping Stone:\n\n"); printmatrix(x); */ /* Modi */ modi(p,x); printf("\n\nBasislösung nach Modi:\n\n"); printmatrix(x); return 0; }
int main(int argc, char *argv[]){ char nome_arquivo[60]; int opcao; if(argc == 1){ printf("É necessário indicar ao menos o nome do arquivo de entrada!\n\n"); printf("Para mais detalhe, indique a diretiva -h para acessar a Seção Ajuda\n\n"); return 0; } while((opcao = getopt(argc,argv,"ha:b:c:f:i:r:t:")) != -1){ switch (opcao) { case 'h': { ajuda(); return 0; } case 'i': { strcpy(nome_arquivo, optarg); break; } case 'a': { alpha = atof(optarg); break; } case 'b': { beta = atof(optarg); break; } case 'c': { ciclos = atoi(optarg); break; } case 'f': { NumeroFormigas = atoi(optarg); break; } case 'r': { rho = atof(optarg); break; } case 't': { num_threads = atoi(optarg); break; } } } FILE* fp; if((fp = fopen(nome_arquivo, "r")) == NULL){ printf("Arquivo inexistente\n"); return 0; } readgraph(fp); MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &wrank); MPI_Comm_size(MPI_COMM_WORLD, &wsize); inicializarVertices(); melhor_geral.qtdVertice = 0; melhor_colonia = (Formiga *) calloc (ciclos, sizeof (Formiga)); AntSystemColony(); //barreira //MPI_Send(&BUFFER, NUM_ELEMENTOS, MPI_INT, DESTINO, TAG, COMUNICADOR); //if(wrank == 0){} //MPI_Send(&wrank, 1, MPI_INT, destino, 0, MPI_COMM_WORLD); //MPI_Recv(&BUFFER, NUM_ELEMENTOS, MPI_INT, FONTE, TAG, COMUNICADOR, STATUS, ERROR); //MPI_Recv(&mensagem, 1, MPI_INT, origem, MPI_ANY_TAG, MPI_COMM_WORLD, &status); /*if(dele x recebeu){ escolhe } send*/ //comparar os resultados (dele x recebido) //printf("O Processo: %d recebeu de %d, o seu wrank: %d\n\n", wrank, origem, mensagem); if(wrank == 0){ mostraRespostaColonia(&melhor_geral); } MPI_Finalize(); //================== //pthread_mutex_init(&lock, NULL); //pthread_barrier_init(&barreira, NULL, num_threads); //pthread_t threads[num_threads]; //================== //inicializarVertices(); //melhor_geral.qtdVertice = 0; //melhor_colonia = (Formiga *) calloc (ciclos, sizeof (Formiga)); //int i; //for(i = 0; i < num_threads; i++){ // pthread_create(&threads[i], NULL, AntSystemColony, (void *) &i); //} //for(i = 0; i < num_threads; i++){ // pthread_join(threads[i], NULL); //} //mostraRespostaColonia(&melhor_geral); //AntSystemColony(); return 0; }
int main (int argc,char *argv[]) { double sigx = 0.0 ,sigx2 = 0.0, sig; int nn,ne,cval = 0,num_attemp = 0,mincval = 32600; int *igraph, *ma,*mb,*costa,oneflag = 1; /* ,*check,x; */ nodez *alist; indextype *sindex; clock_t startt; float matcht = 0,partt= 0,swapt = 0,bestt,ttime,curtime,run_time; periodt(); startt = clock(); srand(32063); getgraph(argc,argv,&igraph,&ma,&mb,&sindex, &nn,&ne,&alist); cand_list_size = atoi(argv[4]); if(argv[3][0] == '4') big_flag = 0; run_time = atof(argv[5]); readgraph(ne,nn,igraph,alist); curtime = clock()/CLK_TCK; while (curtime < run_time * 2) { num_attemp++; remem(&costa,nn); switch (argv[2][0]) { case '1': heappart(costa,nn,ma,mb,alist); partt += periodt(); break; case '2': greedypart(costa,nn,ma,mb,sindex,alist); partt += periodt(); break; default : exit(0); } switch (argv[3][0]) { case '1': hswap(igraph,ma,mb,costa,nn,&cval,alist); break; case '2': slightswap(igraph,ma,mb,costa,nn,&cval,alist); break; case '3': slightestswap(igraph,ma,mb,costa,nn,&cval,alist); break; case '4': aslightswap(ma,mb,costa,nn,&cval,alist); break; default : hswap(igraph,ma,mb,costa,nn,&cval,alist); } swapt += periodt(); free(costa); sig = cval; sigx += sig; sigx2 += (sig * sig); if (cval < mincval) { bestt = ((clock() - startt)/CLK_TCK); mincval = cval; /* check = (int *) calloc (nn + 1,sizeof(int)); for(x = 1; x<= nn / 2; x++) { check[ma[x]]++; check[mb[x]]++; } for (x = 1; x<= nn; x++) printf("\ncheck %d: %d",x,check[x]); printf("\n\n"); free(check); */ } cval = 0; curtime = clock()/CLK_TCK; if (!oneflag && curtime >= run_time) { oneflag++; ttime = ((clock() - startt)/CLK_TCK); printf("%d\n",mincval); printf("%f\n",ttime); printf("%f\n",bestt); printf("%f\n",matcht); printf("%f\n",partt); printf("%f\n",swapt); printf("%lg\n",sigx); printf("%lg\n",sigx2); printf("%d\n",num_attemp); } } /* while */ ttime = ((clock() - startt)/CLK_TCK); printf("min cost = %d\n",mincval); // printf("%f\n",ttime); // printf("%f\n",bestt); // printf("%f\n",matcht); // printf("%f\n",partt); // printf("%f\n",swapt); // printf("%lg\n",sigx); // printf("%lg\n",sigx2); printf("number of attempts = %d\n",num_attemp); free (alist); if (big_flag) free(igraph); free (ma); free(mb); free (sindex); return EXIT_SUCCESS; }