/* 2012 (C) Jussi Rintanen jrintanen.jr@gmail.com */ #include #include #include "main.h" #include "asyntax.h" #include "intsets.h" #include "ordintsets.h" #include "interface.h" #include "dimacsinput.h" #include "clausedb.h" #include "operators.h" #include "tables.h" //#include "staticpredicates.h" #include "cleanup.h" #include "invariants.h" #include "scc.h" #include "translate2sat.h" #include #include #include #include #include #include #include #include #ifdef MULTICORE #include #endif int numberOfGroundActionsAfterParsing = -1; int numberOfStateVariablesAfterParsing = -1; int numberOfGroundActionsAfterSimplification = -1; int numberOfStateVariablesAfterSimplification = -1; int maxSizeOfStronglyConnectedComponents = -1; char state_for_random[256]; char dump_for_random[256]; char stri[1000]; long time10ms() { /* The time spent in user mode in 100ms */ struct tms TMS; times(&TMS); return TMS.tms_utime / (sysconf(_SC_CLK_TCK) / 100); } int abstimesec() { struct timeval aux; gettimeofday(&aux,NULL); return aux.tv_sec; } int abstimeusec() { struct timeval aux; gettimeofday(&aux,NULL); return aux.tv_usec; } intset test; void givememorystatistics() { char buf[30]; snprintf(buf, 30, "/proc/%u/statm", (unsigned)getpid()); FILE* pf = fopen(buf, "r"); if (pf) { unsigned size; // total program size unsigned resident;// resident set size unsigned share;// shared pages unsigned text;// text (code) unsigned lib;// library unsigned data;// data/stack fscanf(pf, "%u %u %u %u %u %u", &size, &resident, &share, &text, &lib, &data); printf("memoryConsumption:\n total: %.1f # [MB]\n", ((double)size)/256.0); } fclose(pf); } /***************** MALLOC STATISTICS *****************/ #define noSHOWMALLOCSTATS #ifdef SHOWMALLOCSTATS long statmallocs[1000]; void initstatmalloc() { int i; allocatedbyFE = 0.0; for(i=0;i<1000;i++) statmallocs[i] = 0; } void showstatsmalloc() { int i; double sum; sum = 0.0; printf("Malloc statistics:\n"); for(i=0;i<1000;i++) { if(statmallocs[i]) { printf("%i: %.2f\n",i,((float)statmallocs[i])/1024.0/1024.0); sum = sum + ((double)statmallocs[i])/1024.0/1024.0; } } printf("TOTAL = %.2f\n",sum); } #endif void *statmalloc(int n,int s) { void *tmp; tmp = malloc(s); #ifdef SHOWMALLOCSTATS statmallocs[n] += s; assert(tmp); #else allocatedbyFE += s; #endif return tmp; } /******************** TIME OUTS ********************/ void timeouthandler(int i) { printf("\nTimeout after %i seconds of real time.\n",flagRealTimeout); givememorystatistics(); #ifdef SHOWMALLOCSTATS showstatsmalloc(); #endif exit(0); } float time2real(long dif) { return ((float)dif)/100.0; } float timefromstart() { return time2real(time10ms() - TIMEstart); } int numer(char c) { return (c >= '0' && c <= '9'); } void processheuristic(char *decls) { int position,n; HEURordmode = 0; HEURordmin = 0; HEURordrnd = 0; HEURtime = 0; HEURops = 0; HEURchoice = 0; HEURactions = 1; HEURactionchoice = 0; HEURactiondepthlimit = 0; position = 0; if(!numer(*decls)) { printf("ERROR: Expected numeric option.\n"); exit(1); } do { n = 0; while(numer(*decls)) { n = n*10 + (*(decls++) - '0'); } if(*decls != 0 && *decls != ':') { printf("ERROR: Number separator is : and not %c.\n",*decls); exit(1); } switch(position) { case 0: HEURordmode = n; break; case 1: HEURordmin = n; break; case 2: HEURordrnd = n; break; case 3: HEURtime = n; break; case 4: HEURops = n; break; case 5: HEURchoice = n; break; case 6: HEURactions = n; break; case 7: HEURactionchoice = n; break; case 8: HEURactiondepthlimit = n; break; default: printf("ERROR: too many parameters.\n"); exit(1); } position += 1; } while(*(decls++) == ':'); } void printStatistics() { printf("\n\n# statistics in YAML format\n---\n"); printf("runtime:\n total: %.2f # [s]\n preprocessing: %.2f # [s]\n", time2real(time10ms() - TIMEstart), time2real(TIMEpreprocess - TIMEstart)); printf("maxLearnedClauseLength: %i\n",stats_longest_learned); if (numberOfGroundActionsAfterParsing > -1) printf("groundActions:\n afterParsing: %i\n",numberOfGroundActionsAfterParsing); if (numberOfGroundActionsAfterSimplification > -1) printf(" afterPreprocessing: %i\n",numberOfGroundActionsAfterSimplification); if (numberOfStateVariablesAfterParsing > -1) printf("stateVariables:\n afterParsing: %i\n",numberOfStateVariablesAfterParsing); if (numberOfStateVariablesAfterSimplification > -1) printf(" afterPreprocessing: %i\n",numberOfStateVariablesAfterSimplification); if (maxSizeOfStronglyConnectedComponents > -1) printf("stronglyConnectedComponents:\n maxSize: %i\n",maxSizeOfStronglyConnectedComponents); int solutionIndex = -1; for (int i = 0; seqs[i].sati; i++) { if (seqs[i].sati->value != 1) continue; solutionIndex = i; break; } printf("plan:\n found: "); if (solutionIndex < 0) printf("false\n"); else { printf("true\n"); const auto planLength = seqs[solutionIndex].sati->nOfTPoints - 1; int numberOfActions = 0; const satinstance sati = seqs[solutionIndex].sati; for (int t = 0; t < sati->nOfTPoints - 1; t++) for (int i = 0; i < sati->nOfActions; i++) if (vartruep(sati,TACT(i,t))) numberOfActions++; printf(" length: %i\n actions: %i\n", planLength, numberOfActions); } if(flagOutputDIMACS == 0) { if (seqs[0].sati) printf("iterations:\n"); int i = 0; while(i*outputTimeStep+firstTimePoint < lastTimePoint && seqs[i].sati) { printf(" - horizon: %i\n",seqs[i].sati->nOfTPoints-1); printf(" result: "); if (seqs[i].sati->value == 0) printf("unsatisfiable"); else if (seqs[i].sati->value == 1) printf("satisfiable"); else printf("unknown"); printf("\n"); printf(" conflicts: %i\n",seqs[i].sati->conflicts); printf(" decisions: %i\n",seqs[i].sati->decisions); printf(" variables: %i\n",seqs[i].sati->nOfVars); i += 1; }// && seqs[i-1].sati->value != 1); // } while(i*outputTimeStep+firstTimePoint < lastTimePoint); } printf("...\n"); } void handleSIGINT() { printStatistics(); exit(0); } int main(int argc,char **argv) { signal(SIGINT, handleSIGINT); int i,j; syntacticclass sclass; nOfInputFiles = 0; TIMEstartReal = time(NULL); TIMEstart = time10ms(); #include "zPRINTDATE" #ifdef __LP64__ printf(" amd64"); #else printf(" x86-32"); #endif #ifdef MULTICORE printf(" multi-core"); #else printf(" 1-core"); #endif #ifdef VSIDS printf("\n"); #else printf(" (no VSIDS)\n"); #endif #ifdef MULTICORE nOfThreads = omp_get_num_procs(); printf("%i CPUS available\n",nOfThreads); #endif stats_longest_learned = 0; /* Process command line options. */ flagShortCutHorizon = 5; flagShowInput = 0; flagPDDLadddel = 1; flagRestartInterval = 60; flagRestartScheme = 0; flagPreprocessing = 0; flagCEvariables = 1; flagRandomSeedTime = 0; flagNoInvariants = 0; flagEliminateConverses = 1; currentInputFile = 0; outputfile = NULL; #ifdef __LP64__ flagMemoryLimit = 8.0*1024.0; /* By default, use max 8 GB of memory. */ #else flagMemoryLimit = 3500.0; /* By default, use max 3.5 GB of memory. */ #endif flagOutputDIMACS = 0; flagIPCplans = 0; #if (MPDOWNLOAD || CMPDOWNLOAD) PLANheuristic = 1; HEURordmode = 1; HEURordmin = 0; HEURordrnd = 0; HEURtime = 0; HEURops = 1; /* This was 0 for long. */ HEURchoice = 0; HEURactions = 50; /* This was 40 for the AIJ article. */ HEURactionchoice = 4; HEURactiondepthlimit = 1; #else PLANheuristic = 0; /* By default don't use planning heuristic, but VSIDS. */ #endif flagTimeout = 0; flagRealTimeout = 0; lastTimePoint = 3000; outputTimeStep = 5; firstTimePoint = 0; debugOutput = 0; #ifdef CMPDOWNLOAD evalAlgorithm = 2; paramC = 1.414214; /* Default: Algorithm C */ #else evalAlgorithm = 1; paramB = 0.9; /* Default: Algorithm B */ #endif paramM = 20; planFrontend = 1; planSemantics = EStep; filenamebase = NULL; if(argc == 1) { printf("\n"); printf("The command line parameters are the input file names and options:\n"); printf("-A n Run algorithm A with parameter n (range 1 to 50)"); if(evalAlgorithm==0) printf(" default -A %i.\n",paramA); else printf("\n"); printf("-B r Run algorithm B with parameter r (range 0.1 to 0.9999)"); if(evalAlgorithm==1) printf(" default -B %.2f.\n",paramB); else printf("\n"); printf("-C r Run algorithm C with parameter r (range 1.2 to 2.0)"); if(evalAlgorithm==2) printf(" default -C %.2f.\n",paramC); else printf("\n"); printf("-M n With algorithm B, use maximum n processes (default -M %i).\n",paramM); printf("-S n Step for horizon lengths 0,n,2n,3n,... (default -S %i, algorithms A and B only)\n",outputTimeStep); // printf("-H n Use SAT heuristic n.\n"); // printf("-pH n Use planning heuristic n (0 = none).\n"); printf("-F n Starting horizon length (default -F %i)\n",firstTimePoint); printf("-T n Ending horizon length (default -T %i)\n",lastTimePoint); printf("-P n Choose plan type n: (default -P 2)\n"); printf(" 0 = sequential plans\n"); printf(" 1 = A-step plans (Graphplan parallelism)\n"); printf(" 2 = E-step plans (Rintanen et al. 2004, 2006)\n"); // printf(" 3 = E-step plans (Ogata et al. 2004)\n"); printf("-O Write formulas in a file in DIMACS format instead of solving.\n"); printf("-X Don't use PDDL semantics for simultaneous v:=0 v:=1.\n"); printf("-Q Output plans in the IPC format.\n"); printf("-o [filename] Output plan to file.\n"); printf("-b [filename] Name for the DIMACS CNF files.\n"); printf("-t n Timeout n seconds of CPU time\n"); printf("-r n Timeout n seconds of real time\n"); printf("-m n Allocating max. n MB of memory (default -m %i)\n",(int)flagMemoryLimit); printf("-N Don't compute invariants.\n"); printf("-c Don't eliminate converse literals.\n"); printf("-W Use time as the random seed (instead of seed 0).\n"); // printf("-Z n Select preprocessing.\n"); printf("-i n Restart interval is n (default -i %i).\n",flagRestartInterval); printf("-R n Restart scheme n=0 constant n=1 Luby (default -R %i).\n",flagRestartScheme); #ifdef CP3 printf("-E Use external preprocessor.\n"); #endif // printf("-K n Add shortcuts for horizon n.\n"); // printf("-I Show input and auxiliary data in detail.\n"); // printf("-2 Use the closure of binary clauses to speed up propagation.\n"); // printf("-d b Level of debug output (default = 0).\n"); exit(0); } printf("Options:"); for(i=1;i= 1) printf("Eliminating static...\n"); // // eliminatestatic(); // // simplifysillyconditionals(); // // if(debugOutput >= 1) printf("Grounding...\n"); // // groundoperators(); if(debugOutput >= 1) printf("Grounding...\n"); NEWgroundoperators(); numberOfGroundActionsAfterParsing = nOfActions; numberOfStateVariablesAfterParsing = nOfAtoms; printf("Parser: %i ground actions and %i state variables\n",nOfActions,nOfAtoms); if(flagShowInput) { for(i=0;i= 1) printf("Cleaning up...\n"); cleanupoperators(); #ifdef SHOWMALLOCSTATS showstatsmalloc(); #endif TIMEinvariants = time10ms(); if(debugOutput >= 1) printf("Preparing to compute invariants...\n"); computeinvariants(); if(!flagNoInvariants) printf(" %.2f secs\n", time2real(time10ms() - TIMEinvariants)); simplifyoperatorsstatic(); eliminatestaticvariables(); if(flagEliminateConverses) mergecontras(); numberOfGroundActionsAfterSimplification = nOfActions; numberOfStateVariablesAfterSimplification = nOfAtoms; printf("Simplified: %i ground actions and %i state variables\n",nOfActions,nOfAtoms); sortactions(); if(flagShowInput) { for(i=0;i 0) printf("time %.2f for preprocessing for disabling graph\n", time2real(time10ms() - TIMEdisaprepro)); if(planSemantics == EStep) { int maxsize; TIMEdisabling = time10ms(); maxsize = scc(nOfActions); maxSizeOfStronglyConnectedComponents = maxsize; printf(" %.2f secs (max SCC size %i)\n",time2real(time10ms() - TIMEdisabling),maxsize); } TIMEpreprocess = time10ms(); encoding(); printStatistics(); } #ifdef SHOWMALLOCSTATS showstatsmalloc(); #endif return 0; }