/* 2012 (C) Jussi Rintanen, jrintanen.jr@gmail.com */ #include #include #include #include "interface.h" #include "main.h" #include "asyntax.h" #include "tables.h" #include "ordintsets.h" #include "operators.h" #define IPC 1 #define FIELD 35 /* Print atoms true in a state. */ void printstate(satinstance sati,int *state) { int i; for(i=0;inOfSVars;i++) { if(state[i]) { printf(" "); printatomi(i); } } } /* Print a tabular representation of the values of state variables and operators at different time points. */ void printplanT(satinstance sati) { int i,j,len; for(j=0;jnOfTPoints;j++) printf("%i",j%10); printf("\n"); for(i=0;inOfTPoints;j++) { switch(varvalue(sati,TVAR(i,j))) { case 0: printf("."); break; case 1: printf("T"); break; default: printf(" "); break; } } printf("\n"); } for(i=0;inOfTPoints-1;j++) { switch(varvalue(sati,TACT(i,j))) { case 0: printf("."); break; case 1: printf("T"); break; default: printf(" "); break; } } printf("\n"); } } /* Print a tabular representation of the values of state variables at different time points. */ void printplanV(satinstance sati) { int i,j,len; for(j=0;jnOfTPoints;j++) printf("%i",j%10); printf("\n"); for(i=0;inOfTPoints;j++) { switch(varvalue(sati,TVAR(i,j))) { case 0: printf("."); break; case 1: printf("T"); break; default: printf(" "); break; } } printf("\n"); } } /* Print the plan as a sequence of operators. (Test also that the plan actually is a solution to the planning problem.) */ void copystate(satinstance sati,int *s1,int *s2) { int i; for(i=0;inOfSVars;i++) s2[i] = s1[i]; } #define MAXSTEPSIZE 50000 void fprintplan(FILE *f,satinstance sati) { int pactions[MAXSTEPSIZE]; int sactions[MAXSTEPSIZE]; int substepcnt; int pcnt,toprint,round,naf,cnt; int t,i,j,actionsinplan; int state0[sati->nOfSVars],state1[sati->nOfSVars]; int print_t; int cost; #ifdef IPC int print_a; #endif cost = 0; actionsinplan = 0; print_t = 0; #ifdef IPC print_a = 0; #endif for(i=0;inOfSVars;i++) state0[i] = varvalue(sati,i); copystate(sati,state0,state1); for(t=0;tnOfTPoints-1;t++) { /* Get action indices to pactions. */ pcnt = 0; /* How many actions in the current time point. */ #ifdef DEBUG fprintf(f,"Actions at STEP %i: ",t); #endif for(i=0;i= MAXSTEPSIZE) { fprintf(stderr,"ERROR: max. step size %i exceeded. Recompile with increased MAXSTEPSIZE.\n",MAXSTEPSIZE); } #ifdef DEBUG fprintactionname(f,i); #endif actionsinplan += 1; cost += actions[i].cost; } } #ifdef DEBUG printf("\n"); #endif toprint = pcnt; round = 0; /* Find actions that don't affect any of the remaining actions. */ while(toprint) { copystate(sati,state0,state1); cnt = 0; substepcnt = 0; /* Number of actions currently in the substep */ for(i=0;i