[Pntool-developers] SF.net SVN: pntool:[211] spnbox
Brought to you by:
compaqdrew,
miordache
From: <Ste...@us...> - 2009-08-03 20:00:29
|
Revision: 211 http://pntool.svn.sourceforge.net/pntool/?rev=211&view=rev Author: StephenCamp Date: 2009-08-03 20:00:13 +0000 (Mon, 03 Aug 2009) Log Message: ----------- The dp tests now complete without any runtime errors. There are still logic errors to be debugged, but this seems like a good time to back up my source. While debugging dp.c, found and corrected bugs in admcon, fvpr, and the dp test routines. Modified Paths: -------------- spnbox/admcon.c spnbox/dp.c spnbox/fvpr.c spnbox/tests/test-dp.c spnbox/tests/test-dp.txt Modified: spnbox/admcon.c =================================================================== --- spnbox/admcon.c 2009-07-31 22:09:33 UTC (rev 210) +++ spnbox/admcon.c 2009-08-03 20:00:13 UTC (rev 211) @@ -9,7 +9,7 @@ static int CheckParams(admcon_p *params); static int GetRowCount(admcon_p *params); static matrix BuildZ(admcon_p *params); -static matrix BuildDX(admcon_p *p, admcon_r *result, matrix *Z); +static matrix BuildDX(admcon_p *p, matrix *Z); static int *nlplace(admcon_p *p, matrix *DX, int *pCount); static ipsolve_r RawSolution(admcon_p *param, matrix *DX, int* p, int pCount); static admcon_r BuildResult(ipsolve_r *lpresult, int *p, int pCount, int rowCount); @@ -27,22 +27,23 @@ } /*Initialize the result to a default value.*/ - if (params->siphon) - { - result.l = tcalloc(NumberOfRows(params->Dm), sizeof(int)); - memcpy(result.l, params->siphon, sizeof(int) * NumberOfRows(params->Dm)); - } result.how = 1; /*Get the row count and the intermediate matrix Z.*/ int rowCount = GetRowCount(params); matrix Z = BuildZ(params); /*Get the intermediate linear programming matrix DX. Z will be deallocated - by the function call. - If DX returns an empty matrix, it means that the current solution is - feasible. Return immediately.*/ - matrix DX = BuildDX(params, &result, &Z); - if (! DX.type) return result; + by the function call. If DX returns an empty matrix, it means that the + default solution, a copy of the siphon, is feasible. Return immediately.*/ + matrix DX = BuildDX(params, &Z); + if (! DX.type) + { + /*Build the result and return. l should be a copy of the siphon vector.*/ + result.l = tcalloc(NumberOfRows(params->Dm), sizeof(int)); + result.lCount = NumberOfRows(params->Dm); + memcpy(result.l, params->siphon, sizeof(int) * NumberOfRows(params->Dm)); + return result; + } /*Get p, a list of places. This function is an aggregate of the nlplace function present in the Matlab version of this function, and several lines of code @@ -51,8 +52,8 @@ int pCount; int *p; if (! (p = nlplace(params, &DX, &pCount))) - { - memset(&result, 0, sizeof(admcon_r)); + { + result.how = 0; DeallocateMatrix(&DX); return result; } @@ -61,8 +62,7 @@ using p. This problem deallocates DX.*/ ipsolve_r lpresult = RawSolution(params, &DX, p, pCount); - /*Get the new solution (Deallocate the space used by the old first)*/ - free(result.l); + /*Get the new solution.*/ return BuildResult(&lpresult, p, pCount, rowCount); } @@ -309,7 +309,7 @@ correct it returns an empty matrix to signify that admcon should return immediately. This function also deallocates the Z matrix, which, is not used again.*/ -matrix BuildDX(admcon_p *p, admcon_r *result, matrix *Z) +matrix BuildDX(admcon_p *p, matrix *Z) { /*DX is a matrix composed of a right-to-left concatentation of submatrices, all transposed: DX = [Auc, Auo, -Auo, -Ds, d]' @@ -354,26 +354,29 @@ /*Deallocate Z. It will not be needed anymore.*/ DeallocateMatrix(Z); - /*Run a test. If DX * l (the current solution vector) >= b, the current - solution vector is good. b should be a vector of all zeros except for the last - element, which should be 1. We can skip the building of b and simply put the - test in a loop.*/ - for (i = 0; i < NumberOfRows(DX); i++) + /*Run a test. If DX * siphon (the default solution vector is simply the siphon) + >= b, the default solution vector is good. b should be a vector of all zeros + except for the last element, which should be 1. We can skip the building of b + and simply put the test in a loop.*/ + if (p->siphon) { - k = MultiplyVector(&DX, (matrix*) result->l, i, MULTIPLYVECTOR_ARRAY, 0); - if (k < (i < NumberOfRows(DX) - 1 ? 0 : 1)) + for (i = 0; i < NumberOfRows(DX); i++) { - break; + k = MultiplyVector(&DX, (matrix*) p->siphon, i, MULTIPLYVECTOR_ARRAY, 0); + if (k < (i < NumberOfRows(DX) - 1 ? 0 : 1)) + { + break; + } } + /*If we made it through the loop without breaking out early, it means that the + default solution vector is valid. Deallocate and zero DX and return to + indicate this. Otherwise just return DX as-is for the next stage in + processing.*/ + if (i == NumberOfRows(DX)) + { + DeallocateMatrix(&DX); + } } - /*If we made it through the loop without breaking out early, it means that the - current solution vector is valid. Deallocate and zero DX and return to - indicate this. Otherwise just return DX as-is for the next stage in - processing.*/ - if (i == NumberOfRows(DX)) - { - DeallocateMatrix(&DX); - } return DX; } @@ -433,7 +436,7 @@ { for (k = 0; k < p->dpCount; k++) { - SetMatrixEl(&result, p->dpl[k], j, GetMatrixEl(&p->M, i, k)); + SetMatrixEl(&result, p->dpl[k], j, GetMatrixEl(&p->M, k, i)); } } Modified: spnbox/dp.c =================================================================== --- spnbox/dp.c 2009-07-31 22:09:33 UTC (rev 210) +++ spnbox/dp.c 2009-08-03 20:00:13 UTC (rev 211) @@ -328,7 +328,8 @@ free(d->Tuo); free(d->TDCount); DeallocateMatrix(&d->TSIPH); - DeallocateMatrix(&d->S); + /*S may not ever have been allocated if no new siphons were found.*/ + if (d->S.type) DeallocateMatrix(&d->S); memset(d, 0, sizeof(dpData)); } @@ -612,6 +613,9 @@ void ReduceLB(dpData *d) { MarkingConstraints cons = UpdateMarkingConstraints(d); + //If there are no constraints, return immediately. + if (! cons.L.type) return; + reduce_r rcons = reduce(&cons.L, cons.B); free(cons.B); DeallocateMatrix(&cons.L); @@ -798,8 +802,8 @@ CopyMatrix(&l, &l2); AddToArray(&d->B, NumberOfRows(d->L), b); AddToCountedArray(&d->G, &d->GCount, b); - InsertRows(&d->L, &l, -1, 1); - InsertRows(&d->M, &l2, -1, 1); + InsertRows(&d->L, &l, -1, -1); + InsertRows(&d->M, &l2, -1, -1); /*Add a null column to the end of S. */ InsertNullColumns(&d->S, -1, 1, -1); } @@ -808,7 +812,7 @@ /*Add the built constraint to the initial marking constraints.*/ if (d->log) PrintConstraints(d, &l, b, currentSiphon, 0, x); AddToArray(&d->B0, NumberOfRows(d->L0), NumberOfRows(d->L0)); - InsertRows(&d->L0, &l, -1, 1); + InsertRows(&d->L0, &l, -1, -1); } } else @@ -836,13 +840,13 @@ d->uci = 1; d->state.perm = 0; d->upd = 0; - if (d->log) PrintConstraints(d, 0, 0, 0, -2, 1); + if (d->log) PrintConstraints(d, 0, 0, currentSiphon, -2, 1); } DeallocateAdmcon(&admconRes); } else { - if (d->log) PrintConstraints(d, 0, 0, 0, -1, 0); + if (d->log) PrintConstraints(d, 0, 0, currentSiphon, -1, 0); } } } @@ -1052,6 +1056,7 @@ admconP.Dm = d->Dm; admconP.Dp = d->Dp; admconP.DI = d->DI; + admconP.M = d->M; admconP.ipl = d->ipl; admconP.dpl = d->dpl; admconP.opl = d->opl; @@ -1224,7 +1229,7 @@ break; } } - if (j == NumberOfColumns(d->Dcm)) newApl[newApCount++] = i; + if (j != NumberOfColumns(d->Dcm)) newApl[newApCount++] = i; } free(d->apl); d->apl = newApl; @@ -1778,8 +1783,9 @@ { d.state.uncontro = 1; } - /*If L or L0 are present, set the initial conditions (incon) state bit.*/ - if (d.L.type || d.L0.type) + /*If L or L0 are present (have at least one row), set the initial conditions + (incon) state bit.*/ + if (d.L.nr || d.L0.nr) { d.state.incon = 1; d.consis = 1; @@ -1824,15 +1830,16 @@ it in the MarkingConstraints structure.*/ MarkingConstraints UpdateMarkingConstraints(dpData *d) { - int count; + int count, cols; MarkingConstraints result; memset(&result, 0, sizeof(MarkingConstraints)); if (NumberOfRows(d->L) || NumberOfRows(d->L0)) { count = NumberOfRows(d->L) + NumberOfRows(d->L0); - AllocateMatrixType(2, &result.L, count, NumberOfRows(d->Dm)); - CopyBlock(NumberOfRows(d->L), NumberOfRows(d->Dm), &d->L, 0, 0, &result.L, 0, 0); - CopyBlock(NumberOfRows(d->L0), NumberOfRows(d->Dm), &d->L0, 0, 0, &result.L, NumberOfRows(d->L), 0); + cols = NumberOfColumns(d->L) ? NumberOfColumns(d->L) : NumberOfColumns(d->L0); + AllocateMatrixType(2, &result.L, count, cols); + CopyBlock(NumberOfRows(d->L), cols, &d->L, 0, 0, &result.L, 0, 0); + CopyBlock(NumberOfRows(d->L0), cols, &d->L0, 0, 0, &result.L, NumberOfRows(d->L), 0); } if (count && (d->B || d->B0)) { Modified: spnbox/fvpr.c =================================================================== --- spnbox/fvpr.c 2009-07-31 22:09:33 UTC (rev 210) +++ spnbox/fvpr.c 2009-08-03 20:00:13 UTC (rev 211) @@ -79,7 +79,7 @@ int GetBufferLength(void* vector, int length, int mode, char* op, char* cl) { - if (length == 0) return 1; + if (length == 0) return 3; /*The buffer length will be, at most, the vector length times the length of the element separator plus the number of digits required to display the largest number in the vector, all plus the lengths of the beginning and ending @@ -101,7 +101,7 @@ 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) Modified: spnbox/tests/test-dp.c =================================================================== --- spnbox/tests/test-dp.c 2009-07-31 22:09:33 UTC (rev 210) +++ spnbox/tests/test-dp.c 2009-08-03 20:00:13 UTC (rev 211) @@ -26,9 +26,13 @@ setverbose(VRB_MAX); + //Before we begin, delete any old log files. + remove("dp.log"); + remove("dp.dat"); + while (ParseStructure(input, iDesc, &iFill, &mem, &D, &p.Dm, &p.Dp, &p.Tuc, &p.TucCount, &p.Tuo, &p.TuoCount, &p.IncludeT, &p.IncludeCount, &p.ExcludeT, &p.ExcludeCount, &p.B, &BCount, &p.B0, &B0Count, &p.L, &p.L0, WriteLog, EnforceLive)) { - DisplayStructure(iDesc, iFill, &D, &p.Dm, &p.Dp, p.Tuc, p.TucCount, p.Tuo, p.TuoCount, p.IncludeT, p.IncludeCount, p.ExcludeT, p.ExcludeCount, p.B, BCount, p.B0, B0Count, &p.L, &p.L0, WriteLog, EnforceLive); + DisplayStructure(iDesc, iFill, &D, &p.Dm, &p.Dp, p.Tuc, p.TucCount, NumberOfColumns(p.Dm), p.Tuo, p.TuoCount, NumberOfColumns(p.Dm), p.IncludeT, p.IncludeCount, p.ExcludeT, p.ExcludeCount, p.B, BCount, p.B0, B0Count, &p.L, &p.L0, WriteLog, EnforceLive); FillDmDp(iFill, &D, &p.Dm, &p.Dp, &mem); /*Log writing defaults to on.*/ if (strcmp(WriteLog, "off")) p.option |= DP_OPT_WRITELOG; @@ -45,6 +49,7 @@ printf("Should be 'off' or 'on'. Defaulting to 'off'.\n"); } + //For the duration of a test, append to the log files. p.option |= DP_OPT_APPENDLOGS; dp_r res = dp(&p); Modified: spnbox/tests/test-dp.txt =================================================================== --- spnbox/tests/test-dp.txt 2009-07-31 22:09:33 UTC (rev 210) +++ spnbox/tests/test-dp.txt 2009-08-03 20:00:13 UTC (rev 211) @@ -90,7 +90,7 @@ 3 0 0 0 0 0 1 0 0 0 -L 4 4 +L 1 4 1 1 1 1 B 1 3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |