[Pntool-developers] SF.net SVN: pntool:[215] spnbox
Brought to you by:
compaqdrew,
miordache
From: <Ste...@us...> - 2009-08-14 08:10:16
|
Revision: 215 http://pntool.svn.sourceforge.net/pntool/?rev=215&view=rev Author: StephenCamp Date: 2009-08-14 08:10:08 +0000 (Fri, 14 Aug 2009) Log Message: ----------- Modified fvpr and avpr so that they can now display with or without the index offset needed sometimes to generate output identical to that produced by Matlab. Corrected some logging errors in dp and changed it so that all indices in the log are shown as if they started at 1 - output should be identical to that of a Matlab run. Modified test routines for fvpr, avpr as appropriate. Modified constant definitions for fvpr, avpr modes in spnbox.h. Modified Paths: -------------- spnbox/avpr.c spnbox/dp.c spnbox/fvpr.c spnbox/spnbox.h spnbox/tests/test-avpr.c spnbox/tests/test-avpr.txt spnbox/tests/test-fvpr.c spnbox/tests/test-fvpr.txt Modified: spnbox/avpr.c =================================================================== --- spnbox/avpr.c 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/avpr.c 2009-08-14 08:10:08 UTC (rev 215) @@ -18,7 +18,7 @@ { char element[64]; - if (mode == DISPLAY_MATRIX) length = MatrixLength(*((matrix*) vector)); + if (mode & DISPLAY_MATRIX) length = MatrixLength(*((matrix*) vector)); /*Fill in default parameters.*/ if (! CheckParams(vector, length, mode, &chr)) return 0; @@ -61,15 +61,15 @@ { if (c == 1) { - sprintf(element, "%s%s%d%s", chr, bl, i + 1, el); + sprintf(element, "%s%s%d%s", chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } else if (c == -1) { - sprintf(element, "-%s%s%d%s", chr, bl, i + 1, el); + sprintf(element, "-%s%s%d%s", chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } else { - sprintf(element, "%d%s%s%d%s", c, chr, bl, i + 1, el); + sprintf(element, "%d%s%s%d%s", c, chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } firstProcessed = 1; } @@ -77,19 +77,19 @@ { if (c == 1) { - sprintf(element, "+%s%s%d%s", chr, bl, i + 1, el); + sprintf(element, "+%s%s%d%s", chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } else if (c > 0) { - sprintf(element, "+%d%s%s%d%s", c, chr, bl, i + 1, el); + sprintf(element, "+%d%s%s%d%s", c, chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } else if (c == -1) { - sprintf(element, "-%s%s%d%s", chr, bl, i + 1, el); + sprintf(element, "-%s%s%d%s", chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } else { - sprintf(element, "%d%s%s%d%s", c, chr, bl, i + 1, el); + sprintf(element, "%d%s%s%d%s", c, chr, bl, i + ((mode & DISPLAY_OFFSET) ? 1 : 0), el); } } strcat(buffer, element); @@ -143,14 +143,13 @@ int GetVectorEl(void* vector, int i, int mode) { - switch(mode) + if (mode & DISPLAY_MATRIX) { - case DISPLAY_MATRIX: return GetMatrixEl((matrix*) vector, i % NumberOfRows(* ((matrix*) vector)), i / NumberOfRows(* ((matrix*) vector))); - break; - case DISPLAY_INTS: + } + else + { return ((int*)vector)[i]; - break; } } @@ -173,10 +172,5 @@ { *chr = "m"; } - if (mode != DISPLAY_MATRIX && mode !=DISPLAY_INTS) - { - merror(0, "AVPR: Invalid mode"); - return 0; - } return 1; } Modified: spnbox/dp.c =================================================================== --- spnbox/dp.c 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/dp.c 2009-08-14 08:10:08 UTC (rev 215) @@ -404,12 +404,12 @@ achieve = "deadlock-free"; if (d->state.anetfail) { - fprintf(d->log, "in the subsystem containing the transitions\nT = %s", ListTransitions(d->TA, d->TACount)); + fprintf(d->log, " in the subsystem containing the transitions\nT = %s", ListTransitions(d->TA, d->TACount)); fprintf(d->log, "The supervisor may not enforce T-liveness.\n"); } else { - fprintf(d->log, "the supervisor may not enforce liveness.\n"); + fprintf(d->log, ".\nThe supervisor may not enforce liveness.\n"); } } } @@ -491,7 +491,7 @@ } if (d->state.noTlive) { - fprintf(d->log, "No T-livenss enforcing supervisor exists."); + fprintf(d->log, "\nNo T-livenss enforcing supervisor exists."); } } else if (failed) @@ -520,7 +520,7 @@ if (! (NumberOfRows(d->L) && NumberOfRows(d->L0))) { - fprintf(d->log, "\nNo constraints are needed: the Petri net is %s for all initial\nmarkings", supname); + fprintf(d->log, "\nNo constraints are needed: the Petri net is %s for all initial\nmarkings.", supname); } else { @@ -561,7 +561,7 @@ for (i = 0; i < NumberOfRows(*L); i++) { CopyBlock(1, NumberOfColumns(*L), L, i, 0, &lrow, 0, 0); - fprintf(log, "\n%s >= %d", avpr(&lrow, 0, DISPLAY_MATRIX, "m", 0), B[i]); + fprintf(log, "\n%s >= %d", avpr(&lrow, 0, DISPLAY_MATRIX | DISPLAY_OFFSET, "m", 0), B[i]); } fflush(log); DeallocateMatrix(&lrow); @@ -594,7 +594,7 @@ strcpy(buffer, "{"); for (i = 0; i < listCount - 1; i++) { - sprintf(element, "t%d, ", list[i]); + sprintf(element, "t%d, ", list[i] + 1); strcat(buffer, element); } if (listCount) @@ -1198,8 +1198,8 @@ { case 0: /*Display.*/ - fprintf(d->log, "\nNo control places needed. Constraints below added to (L0, B0)"); - fprintf(d->log, "\n%s >= %d", avpr(l, NumberOfColumns(*l), DISPLAY_MATRIX, 0, 0), b); + fprintf(d->log, "\nNo control places needed. Constraints below added to (L0, B0):"); + fprintf(d->log, "\n%s >= %d", avpr(l, NumberOfColumns(*l), DISPLAY_MATRIX | DISPLAY_OFFSET, 0, 0), b); break; case -1: fprintf(d->log, "\nNo constraints added."); @@ -1209,7 +1209,7 @@ break; default: fprintf(d->log, "\nPlace %d added to control the siphon and enforce:", cpl); - fprintf(d->log, "\n%s >= %d", avpr(l, NumberOfColumns(*l), DISPLAY_MATRIX, 0, 0), b); + fprintf(d->log, "\n%s >= %d", avpr(l, NumberOfColumns(*l), DISPLAY_MATRIX | DISPLAY_OFFSET, 0, 0), b); break; } if (wn == 1) fprintf(d->log, "\nSiphon control failure occurred."); @@ -1480,7 +1480,7 @@ void PrintState(dpData *d) { fprintf(d->log, "\nThe Petri net has %d places and %d transitions", NumberOfRows(d->Dm), NumberOfColumns(d->Dm)); - if (d->ExcludeT) fprintf(d->log, "\nThe current active subnet excludes the transitions %s", fvpr(d->ExcludeT, d->ExcludeCount, DISPLAY_INTS, 2)); + if (d->ExcludeT) fprintf(d->log, "\nThe current active subnet excludes the transitions %s", fvpr(d->ExcludeT, d->ExcludeCount, DISPLAY_INTS | DISPLAY_OFFSET, 2)); int i, j; /*Build a list of the original places for vector display.*/ @@ -1492,7 +1492,7 @@ originalPlaces[i] = i; } /*Display it.*/ - fprintf(d->log, "\n %d original places: %s", d->targetRows, fvpr(originalPlaces, d->targetRows, DISPLAY_INTS, 2)); + fprintf(d->log, "\n %d original places: %s", d->targetRows, fvpr(originalPlaces, d->targetRows, DISPLAY_INTS | DISPLAY_OFFSET, 2)); free(originalPlaces); } @@ -1520,22 +1520,22 @@ { if (d->ipCount - firstNewInd == 1) { - fprintf(d->log, "\n One split place: %s", fvpr(d->ipl + firstNewInd, d->ipCount - firstNewInd, DISPLAY_INTS, 2)); + fprintf(d->log, "\n One split place: %s", fvpr(d->ipl + firstNewInd, d->ipCount - firstNewInd, DISPLAY_INTS | DISPLAY_OFFSET, 2)); } else if (d->ipCount - firstNewInd > 1) { - fprintf(d->log, "\n %d split places: %s", d->ipCount - firstNewInd, fvpr(d->ipl + firstNewInd, d->ipCount - firstNewInd, DISPLAY_INTS, 2)); + fprintf(d->log, "\n %d split places: %s", d->ipCount - firstNewInd, fvpr(d->ipl + firstNewInd, d->ipCount - firstNewInd, DISPLAY_INTS | DISPLAY_OFFSET, 2)); } } if (firstNewDep != -1) { if (d->dpCount - firstNewDep == 1) { - fprintf(d->log, "\n One control place: %s", fvpr(d->dpl + firstNewDep, d->dpCount - firstNewDep, DISPLAY_INTS, 2)); + fprintf(d->log, "\n One control place: %s", fvpr(d->dpl + firstNewDep, d->dpCount - firstNewDep, DISPLAY_INTS | DISPLAY_OFFSET, 2)); } else if (d->dpCount - firstNewDep > 1) { - fprintf(d->log, "\n %d control places: %s", d->dpCount - firstNewDep, fvpr(d->dpl + firstNewDep, d->dpCount - firstNewDep, DISPLAY_INTS, 2)); + fprintf(d->log, "\n %d control places: %s", d->dpCount - firstNewDep, fvpr(d->dpl + firstNewDep, d->dpCount - firstNewDep, DISPLAY_INTS | DISPLAY_OFFSET, 2)); } } fprintf(d->log, "\n"); @@ -1552,7 +1552,7 @@ MRow[d->ipl[j]] = GetMatrixEl(&d->M, i, j); } /*Display the row.*/ - fprintf(d->log, "\n %d --> %s >= %d", d->dpl[i], avpr(MRow, NumberOfRows(d->Dm), DISPLAY_INTS, 0, 0), d->G[i]); + fprintf(d->log, "\n %d --> %s >= %d", d->dpl[i], avpr(MRow, NumberOfRows(d->Dm), DISPLAY_INTS | DISPLAY_OFFSET, 0, 0), d->G[i]); } free(MRow); Modified: spnbox/fvpr.c =================================================================== --- spnbox/fvpr.c 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/fvpr.c 2009-08-14 08:10:08 UTC (rev 215) @@ -18,7 +18,7 @@ char element[64]; /*If the vector is a matrix, get the length.*/ - if (mode == DISPLAY_MATRIX) length = MatrixLength(*((matrix*)vector)); + if (mode & DISPLAY_MATRIX) length = MatrixLength(*((matrix*)vector)); /*Check the parameters.*/ if (! CheckParams(vector, length, mode, option)) return 0; @@ -70,7 +70,7 @@ strcat(buffer, element); } strcat(buffer, cl); - if (mode == DISPLAY_MATRIX && NumberOfRows(*((matrix*)vector)) > 1) + if ((mode & DISPLAY_MATRIX) && NumberOfRows(*((matrix*)vector)) > 1) { strcat(buffer, "'"); } @@ -101,20 +101,19 @@ digits++; } - return strlen(op) + strlen(cl) + ((strlen(", ") + digits) * length) + 1 + ((mode == DISPLAY_MATRIX) ? 1 : 0); + return strlen(op) + strlen(cl) + ((strlen(", ") + digits) * length) + 1 + ((mode & DISPLAY_MATRIX) ? 1 : 0); } int GetVectorEl(void* vector, int i, int mode) { - switch(mode) + if (mode & DISPLAY_MATRIX) { - case DISPLAY_MATRIX: - return GetMatrixEl((matrix*) vector, i % NumberOfRows(* ((matrix*) vector)), i / NumberOfRows(* ((matrix*) vector))); - break; - case DISPLAY_INTS: - return ((int*)vector)[i]; - break; + return GetMatrixEl((matrix*) vector, i % NumberOfRows(* ((matrix*) vector)), i / NumberOfRows(* ((matrix*) vector))) + ((mode & DISPLAY_OFFSET) ? 1 : 0); } + else + { + return ((int*)vector)[i] + ((mode & DISPLAY_OFFSET) ? 1 : 0); + } } int CheckParams(void* vector, int length, int mode, int option) @@ -132,11 +131,6 @@ return 0; } /*If the chr is 0, fill it with the default, m.*/ - if (mode != DISPLAY_MATRIX && mode !=DISPLAY_INTS) - { - merror(0, "FVPR: Invalid mode"); - return 0; - } if (option < 0 || option > 2) { merror(0, "FVPR: Invalid option"); Modified: spnbox/spnbox.h =================================================================== --- spnbox/spnbox.h 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/spnbox.h 2009-08-14 08:10:08 UTC (rev 215) @@ -244,8 +244,9 @@ #define VRB_MAX 10 /*Constants used to change the behavior of the vector display functions.*/ -#define DISPLAY_MATRIX 0 -#define DISPLAY_INTS 1 +#define DISPLAY_INTS 0 +#define DISPLAY_MATRIX 1 +#define DISPLAY_OFFSET 2 /*Options for dp.*/ #define DP_OPT_WRITELOG 4 @@ -978,6 +979,9 @@ If chr is a null pointer it will default to m, as in Matlab. Use mode = DISPLAY_MATRIX for vector a pointer to a matrix. length is ignored. Use mode = DISPLAY_INTS for vector a pointer to an array of integers. +Or the DISPLAY_OFFSET flag with the DISPLAY_MATRIX or DISPLAY_INTS to build a +string that displays vector indices as if they began at 1 rather than zero. This +will produce the same output as Matlab. The function returns a pointer to a static buffer that it owns. This buffer is overwritten every time the function is called. The caller should use or copy the buffer immediately after calling the function.*/ @@ -996,6 +1000,10 @@ C Usage: Parameters have the same meaning and names as in Matlab. Use mode = DISPLAY_MATRIX for vector a pointer to a matrix. length is ignored. Use mode = DISPLAY_INTS for vector a pointer to an array of integers. +Or the DISPLAY_OFFSET flag with the DISPLAY_MATRIX or DISPLAY_INTS to add 1 to +each value before displaying it. When fvpr is used to display vectors +containing lists of indices, this will effectively shift all the indices up +by one, displaying them as if they began at 1 rather than at 0. This will generate the same output as Matlab when used in these circumstances. The function returns a pointer to a static buffer that it owns. This buffer is overwritten every time the function is called. The caller should use or copy the buffer immediately after calling the function.*/ Modified: spnbox/tests/test-avpr.c =================================================================== --- spnbox/tests/test-avpr.c 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/tests/test-avpr.c 2009-08-14 08:10:08 UTC (rev 215) @@ -2,8 +2,9 @@ int main(int argc, char* argv[]) { - char iDesc[] = "arrayi V, matrix M, string chr, int option"; + char iDesc[] = "arrayi V, matrix M, string chr, int option, string ShowOffset"; char *result; + char ShowOffset[128] = ""; int* vector = 0; int vLength = 0, option = 0; char chr[128] = ""; @@ -19,18 +20,26 @@ MemoryManager mem = CreateMemoryManager(3, 1, 0, 0); - while (ParseStructure(file, iDesc, &iFill, &mem, &vector, &vLength, &M, chr, &option)) + while (ParseStructure(file, iDesc, &iFill, &mem, &vector, &vLength, &M, chr, &option, ShowOffset)) { if (iFill[0]) iFill[1] = 0; - DisplayStructure(iDesc, iFill, vector, vLength, &M, chr, option); - + DisplayStructure(iDesc, iFill, vector, vLength, &M, chr, option, ShowOffset); + if (iFill[4]) + { + if (strcmp(ShowOffset, "on") && strcmp(ShowOffset, "off")) + { + printf("Warning: Invalid ShowOffset option: '%s'.\n", ShowOffset); + printf("Ignoring. Default is ShowOffset = off.\n"); + ShowOffset[0] = '\0'; + } + } if (iFill[0]) { - result = avpr(vector, vLength, DISPLAY_INTS, chr, option); + result = avpr(vector, vLength, DISPLAY_INTS | (strcmp(ShowOffset, "on") ? 0 : DISPLAY_OFFSET), chr, option); } else if (iFill[1]) { - result = avpr(&M, 0, DISPLAY_MATRIX, chr, option); + result = avpr(&M, 0, DISPLAY_MATRIX | (strcmp(ShowOffset, "on") ? 0 : DISPLAY_OFFSET), chr, option); } else { @@ -46,6 +55,7 @@ vLength = 0; option = 0; chr[0] = '\0'; + ShowOffset[0] = '\0'; printf("-------------------------------------------------------------------------------\n"); } return 1; Modified: spnbox/tests/test-avpr.txt =================================================================== --- spnbox/tests/test-avpr.txt 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/tests/test-avpr.txt 2009-08-14 08:10:08 UTC (rev 215) @@ -7,42 +7,42 @@ echo Problem 2. echo Solution should be: -echo m1 +echo m0 V 1 1 done echo Problem 3. echo Solution should be: -echo -m1 +echo -m0 V 1 -1 done echo Problem 4. echo Solution should be: -echo 2m1 +echo 2m0 V 1 2 done echo Problem 5 echo Solution should be: -echo -2m1 +echo -2m0 V 1 -2 done echo Problem 6 echo Solution should be: -echo -2m1-m2+m4+2m5 +echo -2m0-m1+m3+2m4 V 5 -2 -1 0 1 2 done echo Problem 7 echo Solution should be: -echo -2z1-z2+z4+2z5 +echo -2z0-z1+z3+2z4 V 5 -2 -1 0 1 2 chr z @@ -50,7 +50,7 @@ echo Problem 8 echo Solution should be: -echo -2m_{1}-m_{2}+m_{4}+2m_{5} +echo -2m_{0}-m_{1}+m_{3}+2m_{4} V 5 -2 -1 0 1 2 option 1 @@ -58,12 +58,23 @@ echo Problem 9 echo Solution should be: +echo -2m_{0}-m_{1}+m_{3}+2m_{4} +M 3 2 +-2 1 +-1 2 + 0 0 +option 1 +done + +echo Problem 10 +echo Solution should be: echo -2m_{1}-m_{2}+m_{4}+2m_{5} M 3 2 -2 1 -1 2 0 0 option 1 +ShowOffset on done quit Modified: spnbox/tests/test-fvpr.c =================================================================== --- spnbox/tests/test-fvpr.c 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/tests/test-fvpr.c 2009-08-14 08:10:08 UTC (rev 215) @@ -2,12 +2,13 @@ int main(int argc, char* argv[]) { - char iDesc[] = "arrayi V, matrix M, int option"; + char iDesc[] = "arrayi V, matrix M, int option, string ShowOffset"; char *result; int* vector = 0; int vLength = 0; int option = 1; int *iFill; + char ShowOffset[128] = ""; matrix M; FILE* file; @@ -19,18 +20,27 @@ MemoryManager mem = CreateMemoryManager(3, 1, 0, 0); - while (ParseStructure(file, iDesc, &iFill, &mem, &vector, &vLength, &M, &option)) + while (ParseStructure(file, iDesc, &iFill, &mem, &vector, &vLength, &M, &option, ShowOffset)) { if (iFill[0]) iFill[1] = 0; - DisplayStructure(iDesc, iFill, vector, vLength, &M, option); + DisplayStructure(iDesc, iFill, vector, vLength, &M, option, ShowOffset); + if (iFill[3]) + { + if (strcmp(ShowOffset, "on") && strcmp(ShowOffset, "off")) + { + printf("Warning: Invalid ShowOffset option: '%s'.\n", ShowOffset); + printf("Ignoring. Default is ShowOffset = off.\n"); + ShowOffset[0] = '\0'; + } + } if (iFill[0]) { - result = fvpr(vector, vLength, DISPLAY_INTS, option); + result = fvpr(vector, vLength, DISPLAY_INTS | (strcmp(ShowOffset, "on") ? 0 : DISPLAY_OFFSET), option); } else if (iFill[1]) { - result = fvpr(&M, 0, DISPLAY_MATRIX, option); + result = fvpr(&M, 0, DISPLAY_MATRIX | (strcmp(ShowOffset, "on") ? 0 : DISPLAY_OFFSET), option); } else { @@ -45,6 +55,7 @@ vector = 0; vLength = 0; option = 1; + ShowOffset[0] = '\0'; printf("-------------------------------------------------------------------------------\n"); } Modified: spnbox/tests/test-fvpr.txt =================================================================== --- spnbox/tests/test-fvpr.txt 2009-08-14 06:56:54 UTC (rev 214) +++ spnbox/tests/test-fvpr.txt 2009-08-14 08:10:08 UTC (rev 215) @@ -32,4 +32,14 @@ 1 2 3 4 5 6 option 2 done + +echo Problem 6. +echo Solution should be: +echo {2, 3, 4, 5, 6, 7} +M 1 6 +1 2 3 4 5 6 +option 2 +ShowOffset on +done + quit \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |