[Pntool-developers] SF.net SVN: pntool:[181] spnbox
Brought to you by:
compaqdrew,
miordache
From: <Ste...@us...> - 2009-07-07 15:29:44
|
Revision: 181 http://pntool.svn.sourceforge.net/pntool/?rev=181&view=rev Author: StephenCamp Date: 2009-07-07 15:29:42 +0000 (Tue, 07 Jul 2009) Log Message: ----------- test-tactn.txt now implements all the test functionality in tactdem.m. tactn.c now debugged and passes all tests. Modified Paths: -------------- spnbox/tactn.c spnbox/tests/test-tactn.txt Modified: spnbox/tactn.c =================================================================== --- spnbox/tactn.c 2009-07-07 13:35:25 UTC (rev 180) +++ spnbox/tactn.c 2009-07-07 15:29:42 UTC (rev 181) @@ -421,20 +421,32 @@ { matrix L; int i, j, k, Cols, Rows; + int *LFlags; short *IntList; double *B; + double *LoBounds; ipsolve_r lpResult; Cols = NumberOfColumns(*D); Rows = NumberOfRows(*D); + MemoryManager mem; /*We will be iterating through each transition in D and doing a linear programming problem. The constraint matrix will be a copy of D with constraint columns for each zeroed element in keepTransition and for the current column removed or zeroed.*/ /*Allocate space and initialize.*/ - AllocateMatrixType(2, &L, Rows, Cols); - CopyMatrix(D, &L); - IntList = tcalloc(Cols, sizeof(short)); - B = tcalloc(Rows, sizeof(double)); + mem = CreateMemoryManager(5, 1, 0, 0); + MAllocateMatrixType(&mem, 2, &L, Rows, Cols); + IntList = mcalloc(&mem, Cols, sizeof(short)); + B = mcalloc(&mem, Rows, sizeof(double)); + LoBounds = mcalloc(&mem, Cols, sizeof(double)); + /*Lo bounds are 0 for columns not flagged in IncludeFlag and 1 for the rest.*/ + for (i = 0; i < Cols; i++) + { + if (IncludeFlag[i]) LoBounds[i] = 1.0; + } + /*This flag array indicates whether a particular column of L has been filled + (flag set) or nulled (flag cleared).*/ + LFlags = mcalloc(&mem, Cols, sizeof(int)); for (i = 0; i < Cols; i++) { @@ -442,21 +454,34 @@ been marked as unkeepable and those which are NOT flagged in IncludeFlag.*/ if (keepTransition[i] && (! IncludeFlag[i])) { - /*Zero the appropriate columns of the constraint matrix.*/ + /*Zero or fill columns of the constraint matrix as appropriate.*/ for (j = 0; j < Cols; j++) { - if ((! keepTransition[j]) || i == j) + /*We zero the current column and any column not flagged in + keepTransition.*/ + if (((! keepTransition[j]) || i == j)) { - for (k = 0; k < Rows; k++) + /*Zero the column only if it has not already been zeroed.*/ + if (LFlags[j]) { - SetMatrixEl(&L, k, j, 0); - } + for (k = 0; k < Rows; k++) + { + SetMatrixEl(&L, k, j, 0); + } + LFlags[j] = 0; + } } + /*Otherwise, the column should be filled if it is not already full.*/ + else if (! LFlags[j]) + { + CopyBlock(Rows, 1, D, 0, j, &L, 0, j); + LFlags[j] = 1; + } } /*Solve the linear programming problem. Cost defaults to all 1s, upper - and lower bounds default to infinity and zero respectively, and constraint - type defaults to >=. No variables should be restricted to being integers.*/ - lpResult = ipsolve(&L, B, 0, IntList, 0, 0, 0); + bounds default to infinity, and constraint type defaults to >=. No + variables should be restricted to being integers.*/ + lpResult = ipsolve(&L, B, 0, IntList, 0, LoBounds, 0); /*If the linear programming problem was infeasible, break, leave the keepTransition flag array as-is, and return immediately.*/ @@ -472,27 +497,19 @@ memset(keepTransition, 0, sizeof(int) * Cols); for (j = 0; j < Cols; j++) { - /*Ignore very small nonzero values in the solution vector.*/ - if (lpResult.res[j] < -HOW_MAX_ERROR || lpResult.res[j] > HOW_MAX_ERROR) + /*Ignore very small nonzero values in the solution vector. Also + examine only solution elements corresponding to non-nulled columns, + as noted in LFlags.*/ + if ((lpResult.res[j] < -HOW_MAX_ERROR || lpResult.res[j] > HOW_MAX_ERROR) && LFlags[j]) { - keepTransition[j] = 0; + keepTransition[j] = 1; } - - /*Take advantage of the loop to restore any columns of the constraint - matrix that need to be restored. Instead of doing a full matrix copy, - just copy columns that were zeroed above.*/ - if ((! keepTransition[j]) || i == j) - { - CopyBlock(Rows, 1, D, 0, j, &L, 0, j); - } } free(lpResult.res); } } } - free(B); - free(IntList); - DeallocateMatrix(&L); + FreeMemory(&mem); } /******************************************************************************* Modified: spnbox/tests/test-tactn.txt =================================================================== --- spnbox/tests/test-tactn.txt 2009-07-07 13:35:25 UTC (rev 180) +++ spnbox/tests/test-tactn.txt 2009-07-07 15:29:42 UTC (rev 181) @@ -61,4 +61,27 @@ echo Problems 4 & 5 echo These problems test update mode. The solutions to the problems should be echo the same. +echo Problem 4...update mode. +D 5 4 +-1 0 0 0 +1 -1 3 -1 +0 1 -1 0 +0 -1 0 1 +1 0 2 -1 + +Dc 3 3 +0 0 0 +0 -2 3 +0 1 -1 + +done +echo Problem 5...normal mode. +D 5 4 +-1 0 0 0 +1 -1 3 -1 +0 1 -1 0 +0 -1 0 1 +1 0 2 -1 +done + quit This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |