[Pntool-developers] SF.net SVN: pntool:[175] pnheaders
Brought to you by:
compaqdrew,
miordache
From: <mio...@us...> - 2009-07-07 02:56:54
|
Revision: 175 http://pntool.svn.sourceforge.net/pntool/?rev=175&view=rev Author: miordache Date: 2009-07-07 02:56:50 +0000 (Tue, 07 Jul 2009) Log Message: ----------- added a function to print constraints Modified Paths: -------------- pnheaders/main_function.c pnheaders/pns.c pnheaders/pns.h Modified: pnheaders/main_function.c =================================================================== --- pnheaders/main_function.c 2009-07-07 02:25:04 UTC (rev 174) +++ pnheaders/main_function.c 2009-07-07 02:56:50 UTC (rev 175) @@ -76,6 +76,14 @@ return 0; } + if(is_verbose() >= 3) { // For debugging + for(i = 0; i < sp->process_num; i++) { + printf("\n\n======================================================"); + printf("\nPROCESS NAME: %s\n", sp->process_array[i]->name); + displaypn(*(sp->process_array[i]->pn), stdout); + } + } + // Label the PNs for(i = 0; i < sp->process_num; i++) @@ -98,6 +106,12 @@ extractLHCB(sp, &pn, &L, &H, &C, &B); + if(is_verbose() >= 3) { // For debugging + printf("\n\n======================================================"); + printf("\nCONSTRAINTS:\n"); + printLHCB(&pn, &L, &H, &C, B, -1, stdout); + } + // Perform SC Tuc = tcalloc(pn.tnum, sizeof(*Tuc)); @@ -114,6 +128,12 @@ lin_res = linenf(&pn.out, &pn.in, &L, B, pn.marking, &H, &C, \ UCcnt, UClst, UOcnt, UOlst); + if(is_verbose() >= 3) { // For debugging + printf("\n\n======================================================"); + printf("\nADMISSIBLE CONSTRAINTS (H entries omitted): \n"); + printLHCB(&pn, &lin_res.Lf, 0, &lin_res.Cf, lin_res.bf, -1, stdout); + } + free(Tuc); free(Tuo); free(UClst); free(UOlst); // Check whether SC was successful @@ -130,7 +150,7 @@ pnsv = getSupervisor(&pn, &lin_res.Dfm, &lin_res.Dfp, lin_res.ms0); - if(is_verbose() >= 3) { // Temporary code for debugging + if(is_verbose() >= 3) { // For debugging printf("\n\n======================================================"); printf("\nCOMPOSED PN\n"); displaypn(pn, stdout); @@ -144,8 +164,7 @@ // Generate code - // Commented until code above generates meaningful data - //GenerateProgram(&pnsv, sp->name, sp->process_array, sp->process_num); + GenerateProgram(&pnsv, sp->name, sp->process_array, sp->process_num); deallocpn(&pnsv); Modified: pnheaders/pns.c =================================================================== --- pnheaders/pns.c 2009-07-07 02:25:04 UTC (rev 174) +++ pnheaders/pns.c 2009-07-07 02:56:50 UTC (rev 175) @@ -1245,6 +1245,96 @@ /*************************************************************************** + PRINTLHCB +****************************************************************************/ + +void printLHCB(pns* pn, matrix* L, matrix* H, matrix* C, int* B, int row, FILE* f) { + int i, j, nr, nc, x, flag, isnamed; + matrix *mat; + char *prefix, **name, c; + + if(L) + nr = NumberOfRows(*L); + else if(H) + nr = NumberOfRows(*H); + else if(C) + nr = NumberOfRows(*C); + else { + merror(0, "PRINTLHCB: At least one of L, H, or C should be given"); + return; + } + + if(row < 0) { + fprintf(f, "\nThere are %d constraints:\n", nr); + for(i = 0; i < nr; i++) + printLHCB(pn, L, H, C, B, i, f); + return; + } + + if(row >= nr) { + merror(0, "PRINTLHCB: Index %d exceeds number of constraints (%d)", row, nr); + return; + } + + flag = 1; + for(j = 0; j < 3; j++) { + + if(j == 0) { + fprintf(f, "\n(%d) ", row); + mat = L; + prefix = ""; + c = 'p'; + name = pn->place_name; + } + else if(j == 1) { + mat = H; + prefix = "q."; + c = 't'; + name = pn->trans_name; + } + else { + mat = C; + prefix = ""; + c = 't'; + name = pn->trans_name; + } + + if(!mat) + continue; + + nc = NumberOfColumns(*mat); + + for(i = 0; i < nc; i++) { + x = GetMatrixEl(mat, row, i); + if(x) { + if (x == 1 && !flag) // flag = 1 indicates the first element + fprintf(f, "+ "); + else if(x == -1) + fprintf(f, "- "); + else if( x > 0 && x != 1) + fprintf(f, "+ %d*", x); + else if( x < 0) + fprintf(f, "- %d*", -x); + + flag = 0; + + isnamed = 0; + if(name) + if(name[i]) + isnamed = name[i][0]; // nonzero if nonempty string + if(isnamed) + fprintf(f, "%s%s ", prefix, name[i]); + else + fprintf(f, "%s%c%d ", prefix, c, i); + } + } + } + if(flag) + fprintf(f, "0 "); + fprintf(f, "<= %d\n", B[row]); +} + +/*************************************************************************** GETSUPERVISOR ****************************************************************************/ Modified: pnheaders/pns.h =================================================================== --- pnheaders/pns.h 2009-07-07 02:25:04 UTC (rev 174) +++ pnheaders/pns.h 2009-07-07 02:56:50 UTC (rev 175) @@ -347,6 +347,14 @@ initializes pn to the Petri net on which the specs should be enforced. */ +void printLHCB(pns* pn, matrix* L, matrix* H, matrix* C, int* B, int n, FILE* f); + +/* Displays the constraint number n stored in the matrices L, H. C, B. The + first constraint has the number 0 (not 1). To display all constraints, + use n < 0. The pn parameter specifies the PN on which the constraints + are defined. If one or more of L, H, or C is unavailable, enter 0. */ + + pns getSupervisor(pns* pn, matrix* Dcm, matrix* Dcp, int* ms0); /* Extracts the PN representing the supervisor from the plant PN (pn), the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |