Changeset c7f3b7 in git
- Timestamp:
- Dec 3, 1999, 12:03:52 AM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 9f3e9bef10a5b0f7fd4ed74bc83407329b62b4a6
- Parents:
- 2983b3377c3bd9abf59dd57780cedc5d940ca219
- Location:
- Singular
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/solve.lib
r2983b3 rc7f3b7 1 1 /////////////////////////////////////////////////////////////////////////////// 2 2 3 version="$Id: solve.lib,v 1.1 3 1999-11-14 21:35:02 wenk Exp $";3 version="$Id: solve.lib,v 1.14 1999-12-02 23:03:52 wenk Exp $"; 4 4 info=" 5 5 LIBRARY: solve.lib PROCEDURES TO SOLVE POLYNOMIAL SYSTEMS … … 62 62 { 63 63 ERROR("Third parameter l must be positive!"); 64 } 65 } 64 } } 66 65 if ( size(#) >= 3 ) 67 66 { … … 883 882 } 884 883 885 886 884 /////////////////////////////////////////////////////////////////////////////// 887 885 … … 946 944 } 947 945 946 /////////////////////////////////////////////////////////////////////////////// 947 948 proc simplexOut(list l) 949 "USAGE: simpelxOut(l); l list 950 ASSUME: 951 RETURN: 952 EXAMPLE: example simplexOut; shows an example 953 " 954 { 955 int i,j; 956 matrix m= l[1]; 957 intvec iposv= l[3]; 958 int icase= l[2]; 959 960 int cols= ncols(m); 961 int rows= nrows(m); 962 963 int N= l[6]; 964 965 if ( -1 == icase ) // objective function is unbound 966 { 967 "objective function is unbound"; 968 return; 969 } 970 if ( 1 == icase ) // no solution satisfies the given constraints 971 { 972 "no solution satisfies the given constraints"; 973 return; 974 } 975 if ( -2 == icase ) // other error 976 { 977 "an error occurred during simplex computation!"; 978 return; 979 } 980 981 for ( i = 1; i <= rows; i++ ) 982 { 983 if (i == 1) 984 { 985 "z = "+string(m[1][1]); 986 } 987 else 988 { 989 if ( iposv[i-1] <= N+1 ) 990 { 991 "x"+string(i-1)+" = "+string(m[1][iposv[i-1]]); 992 } 993 // else 994 // { 995 // "Y"; iposv[i-1]-N+1; 996 // } 997 } 998 } 999 } 1000 example 1001 { 1002 "EXAMPLE:";echo=2; 1003 ring r = (real,10),(x),lp; 1004 1005 // suppose we have the 1006 1007 matrix sm[5][5]=( 0, 1, 1, 3,-0.5, 1008 740,-1, 0,-2, 0, 1009 0, 0,-2, 0, 7, 1010 0.5, 0,-1, 1,-2, 1011 9,-1,-1,-1,-1); 1012 1013 // simplex input: 1014 // 1: matrix 1015 // 2: number of variables 1016 // 3: total number of constraints (#4+#5+#6) 1017 // 4: number of <= constraints 1018 // 5: number of >= constraints 1019 // 6: number of == constraints 1020 1021 list sol= simplex(sm, 4, 4, 2, 1, 1); 1022 simplexOut(sol); 1023 } 1024 1025 /////////////////////////////////////////////////////////////////////////////// 948 1026 949 1027 // local Variables: *** -
Singular/iparith.cc
r2983b3 rc7f3b7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: iparith.cc,v 1.19 3 1999-12-01 13:22:52 SingularExp $ */4 /* $Id: iparith.cc,v 1.194 1999-12-02 23:03:48 wenk Exp $ */ 5 5 6 6 /* … … 138 138 { "continue", 0, CONTINUE_CMD , CONTINUE_CMD}, 139 139 { "contract", 0, CONTRACT_CMD , CMD_2}, 140 { "convhull", 0, NEWTONPOLY_CMD, CMD_1}, 140 141 { "dbprint", 0, DBPRINT_CMD , CMD_M}, 141 142 { "def", 0, DEF_CMD , ROOT_DECL}, … … 278 279 { "rvar", 0, IS_RINGVAR , CMD_1}, 279 280 { "setring", 0, SETRING_CMD , SETRING_CMD}, 281 { "simplex", 0, SIMPLEX_CMD, CMD_M}, 280 282 { "simplify", 0, SIMPLIFY_CMD , CMD_2}, 281 283 { "size", 0, COUNT_CMD , CMD_1}, … … 3612 3614 ,{kWeight, WEIGHT_CMD, INTVEC_CMD, MODUL_CMD } 3613 3615 ,{jjLOAD1, LOAD_CMD, NONE, STRING_CMD } 3616 ,{loNewtonP, NEWTONPOLY_CMD, IDEAL_CMD, IDEAL_CMD} 3614 3617 ,{NULL, 0, 0, 0} 3615 3618 }; … … 4913 4916 ,{jjUNLOAD, UNLOAD_CMD, NONE, -2 } 4914 4917 #endif /* HAVE_NAMESPACES */ 4918 ,{loSimplex, SIMPLEX_CMD, LIST_CMD, 6 } 4915 4919 ,{nuUResSolve, URSOLVE_CMD, LIST_CMD, 4 } 4916 4920 ,{NULL, 0, 0, 0 } -
Singular/mpr_base.cc
r2983b3 rc7f3b7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mpr_base.cc,v 1.1 5 1999-11-23 17:58:47 SingularExp $ */4 /* $Id: mpr_base.cc,v 1.16 1999-12-02 23:03:49 wenk Exp $ */ 5 5 6 6 /* … … 9 9 */ 10 10 11 #include <math.h> 11 12 #include <limits.h> 12 #include <math.h>13 13 14 14 #include "mod2.h" … … 26 26 #include "numbers.h" 27 27 #include "longalg.h" 28 #include "tok.h"29 28 #ifdef HAVE_FACTORY 30 29 #include "clapsing.h" … … 43 42 #define FreeSizeOf(X,Y) Free(X,sizeof(Y)) 44 43 #endif 45 46 44 //<- 47 45 … … 70 68 //-> sparse resultant matrix 71 69 72 //-> typedefs and structs73 74 70 /* set of points */ 75 71 class pointSet; 76 72 77 /* Linear Program stuff */ 78 struct linProg 79 { 80 mprfloat **LiPM; 81 int *izrov, *iposv; 82 int LiPM_cols,LiPM_rows; 83 }; 84 85 typedef linProg *linProgP; 73 86 74 87 75 /* sparse resultant matrix class */ … … 144 132 ideal rmat; // sparse matrix representation 145 133 146 linProg LP;134 simplex * LP; // linear programming stuff 147 135 }; 148 136 //<- 149 137 138 //-> typedefs and structs 139 poly monomAt( poly p, int i ); 150 140 151 141 typedef unsigned int Coord_t; … … 270 260 { 271 261 public: 272 convexHull( linProgP_pLP ) : pLP(_pLP) {}262 convexHull( simplex * _pLP ) : pLP(_pLP) {} 273 263 ~convexHull() {} 274 264 … … 277 267 * Returns Q[]. 278 268 */ 279 pointSet ** newtonPolytopes( ideal gls ); 269 pointSet ** newtonPolytopesP( const ideal gls ); 270 ideal newtonPolytopesI( const ideal gls ); 280 271 281 272 private: … … 288 279 pointSet **Q; 289 280 int n; 290 linProgPpLP;281 simplex * pLP; 291 282 }; 292 283 //<- … … 297 288 { 298 289 public: 299 mayanPyramidAlg( linProgP_pLP ) : n(pVariables), pLP(_pLP) {}290 mayanPyramidAlg( simplex * _pLP ) : n(pVariables), pLP(_pLP) {} 300 291 ~mayanPyramidAlg() {} 301 292 … … 342 333 Coord_t acoords[MAXVARS+2]; 343 334 344 linProgPpLP;335 simplex * pLP; 345 336 }; 346 347 poly monomAt( poly p, int i ); 337 //<- 348 338 349 339 #ifndef ASO_GENERATE 350 //<-351 340 352 341 //-> debug output stuff … … 441 430 for ( i= 0; i <= max; i++ ) 442 431 { 443 points[i]= (onePointP)Alloc SizeOf( onePoint);432 points[i]= (onePointP)Alloc( sizeof(onePoint) ); 444 433 points[i]->point= (Coord_t *)Alloc0( (dim+2) * sizeof(Coord_t) ); 445 434 } … … 454 443 { 455 444 Free( (ADDRESS) points[i]->point, fdim * sizeof(Coord_t) ); 456 Free SizeOf( (ADDRESS) points[i], onePoint);445 Free( (ADDRESS) points[i], sizeof(onePoint) ); 457 446 } 458 447 Free( (ADDRESS) points, (max+1) * sizeof(onePointP) ); … … 476 465 for ( i= max+1; i <= max*2; i++ ) 477 466 { 478 points[i]= (onePointP)Alloc SizeOf( onePoint);467 points[i]= (onePointP)Alloc( sizeof(struct onePoint) ); 479 468 points[i]->point= (Coord_t *)Alloc0( fdim * sizeof(Coord_t) ); 480 469 } … … 720 709 } 721 710 722 #ifdef mprDEBUG_ PROT711 #ifdef mprDEBUG_ALL 723 712 Print(" lift vector: "); 724 713 for ( j=1; j < dim; j++ ) Print(" %d ",l[j] ); … … 754 743 bool convexHull::inHull(poly p, poly pointPoly, int m, int site) 755 744 { 756 int i, j, col , icase;757 int numcons; // num of constraints 758 int numpts; // num of pts in defining support759 int numcols; // tot number of cols760 761 numcons = n+1;762 numpts = m-1;763 numcols = numpts+1; // this includes col of cts764 765 pLP->LiPM[1][1] = +0.0; pLP->LiPM[1][2] = +1.0; // optimize (arbitrary) var 766 pLP->LiPM[2][1] = +1.0; pLP->LiPM[2][2] = -1.0; // lambda vars sum up to 1767 for ( j=3; j<=numcols; j++)768 {769 pLP->LiPM[ 1][j] = +0.0; pLP->LiPM[2][j] = -1.0;745 int i, j, col; 746 747 pLP->m = n+1; 748 pLP->n = m; // this includes col of cts 749 750 pLP->LiPM[1][1] = +0.0; 751 pLP->LiPM[1][2] = +1.0; // optimize (arbitrary) var 752 pLP->LiPM[2][1] = +1.0; 753 pLP->LiPM[2][2] = -1.0; // lambda vars sum up to 1 754 755 for ( j=3; j <= pLP->n; j++) 756 { 757 pLP->LiPM[1][j] = +0.0; 758 pLP->LiPM[2][j] = -1.0; 770 759 } 771 760 … … 785 774 #ifdef mprDEBUG_ALL 786 775 Print("Matrix of Linear Programming\n"); 787 print_mat( pLP->LiPM, numcons+1, numcols); 788 #endif 789 #if 1 790 if ( numcons + 1 > pLP->LiPM_rows ) 791 WerrorS("convexHull::inHull: #rows > #pLP->LiPM_rows!"); 792 if ( numcols + 1 > pLP->LiPM_cols ) 793 WerrorS("convexHull::inHull: #cols > #pLP->LiPM_cols!"); 794 #endif 795 796 simplx( pLP->LiPM, numcons, numcols-1, 0, 0, numcons, &icase, pLP->izrov, pLP->iposv); 797 798 return (icase == 0); 776 print_mat( pLP->LiPM, pLP->m+1,pLP->n); 777 #endif 778 779 pLP->m3= pLP->m; 780 781 pLP->compute(); 782 783 return (pLP->icase == 0); 799 784 } 800 785 … … 802 787 // ST_SPARSE_VADD: new vertex of convex hull added 803 788 // ST_SPARSE_VREJ: point rejected (-> inside hull) 804 pointSet ** convexHull::newtonPolytopes (ideal gls )789 pointSet ** convexHull::newtonPolytopesP( const ideal gls ) 805 790 { 806 791 int i, j, k; … … 856 841 return Q; 857 842 } 843 844 // mprSTICKYPROT: 845 // ST_SPARSE_VADD: new vertex of convex hull added 846 // ST_SPARSE_VREJ: point rejected (-> inside hull) 847 ideal convexHull::newtonPolytopesI( const ideal gls ) 848 { 849 int i, j; 850 int m; // Anzahl der Exponentvektoren im i-ten Polynom (gls->m)[i] des Ideals gls 851 int idelem= IDELEMS(gls); 852 ideal id; 853 poly p,pid,pd; 854 Exponent_t * vert; 855 856 n= pVariables; 857 vert= (Exponent_t *)Alloc( (idelem+1) * sizeof(Exponent_t) ); 858 id= idInit( idelem, 1 ); 859 860 for( i= 0; i < idelem; i++ ) 861 { 862 m = pLength( (gls->m)[i] ); 863 864 p= (gls->m)[i]; 865 for( j= 1; j <= m; j++) { // für jeden Exponentvektor 866 if( !inHull( (gls->m)[i], p, m, j ) ) 867 { 868 if ( (id->m)[i] == NULL ) { 869 (id->m)[i]= pCopy(p); 870 pNext((id->m)[i])= NULL; 871 pid=(id->m)[i]; 872 } else { 873 pNext(pid)= pCopy(p); 874 pIter(pid); 875 pNext(pid)= NULL; 876 } 877 mprSTICKYPROT(ST_SPARSE_VADD); 878 } 879 else 880 { 881 mprSTICKYPROT(ST_SPARSE_VREJ); 882 } 883 pIter( p ); 884 } // j 885 mprSTICKYPROT("\n"); 886 } // i 887 888 Free( (ADDRESS) vert, (idelem+1) * sizeof(Exponent_t) ); 889 890 #ifdef mprDEBUG_PROT 891 PrintLn(); 892 for( i= 0; i < idelem; i++ ) 893 { 894 } 895 #endif 896 897 return id; 898 } 858 899 //<- 859 900 … … 880 921 { 881 922 int i, ii, j, k, col, r; 882 int icase, constr,numverts, cols;923 int numverts, cols; 883 924 884 925 numverts = 0; … … 924 965 Werror("mayanPyramidAlg::vDistance:" 925 966 "setting up matrix for udist: col %d != cols %d",col,cols); 926 constr = n+dim+1; 967 968 pLP->m = n+dim+1; 969 pLP->m3= pLP->m; 970 pLP->n=cols-1; 927 971 928 972 #ifdef mprDEBUG_ALL 929 Print("vDistance LP, known koords dim=%d, constr %d, cols %d, acoords= ",dim, constr,cols);973 Print("vDistance LP, known koords dim=%d, constr %d, cols %d, acoords= ",dim,pLP->m,cols); 930 974 for( i= 0; i < dim; i++ ) Print(" %d",acoords[i]); 931 975 PrintLn(); 932 print_mat( pLP->LiPM, constr+1, cols); 933 #endif 934 935 #if 1 936 if ( constr + 1 > pLP->LiPM_rows ) 937 WerrorS("mayanPyramidAlg::vDistance: #rows > #pLP->LiPM_rows!"); 938 if ( cols + 1 > pLP->LiPM_cols ) 939 WerrorS("mayanPyramidAlg::vDistance: #cols > #pLP->LiPM_cols!"); 940 #endif 941 942 // 3rd arg is #columns excluding column of constants 943 // M N m1 m2 m3, M= m1+m2+m3 944 simplx( pLP->LiPM, constr, cols-1, 0, 0, constr, &icase, pLP->izrov, pLP->iposv); 976 print_mat( pLP->LiPM, pLP->m+1, cols); 977 #endif 978 979 pLP->compute(); 945 980 946 981 #ifdef mprDEBUG_ALL 947 982 Print("LP returns matrix\n"); 948 print_bmat( pLP->LiPM, constr+1, cols+1-constr, cols, pLP->iposv);949 #endif 950 951 if( icase != 0 ) { // check for errors983 print_bmat( pLP->LiPM, pLP->m+1, cols+1-pLP->m, cols, pLP->iposv); 984 #endif 985 986 if( pLP->icase != 0 ) { // check for errors 952 987 WerrorS("mayanPyramidAlg::vDistance:"); 953 if( icase == 1 ) 954 WerrorS(" vDistance: Unbounded v-distance: probably 1st v-coor=0"); 955 if( icase == -1 ) 956 WerrorS(" vDistance: Infeasible v-distance"); 988 if( pLP->icase == 1 ) 989 WerrorS(" Unbounded v-distance: probably 1st v-coor=0"); 990 else if( pLP->icase == -1 ) 991 WerrorS(" Infeasible v-distance"); 992 else 993 WerrorS(" Unknown error"); 957 994 return -1.0; 958 995 } … … 964 1001 { 965 1002 int i, j, k, cols, cons; 966 int icase,la_cons_row;1003 int la_cons_row; 967 1004 968 1005 cons = n+dim+2; … … 1012 1049 #endif 1013 1050 1014 #if 11015 if ( cons + 1 > pLP->LiPM_rows )1016 WerrorS(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!");1017 if ( cols + 1 > pLP->LiPM_cols )1018 WerrorS(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!");1019 #endif1020 1021 1051 // simplx finds MIN for obj.fnc, puts it in [1,1] 1022 simplx(pLP->LiPM, cons, cols-1, 0, 0, cons, &icase, pLP->izrov, pLP->iposv); 1023 1024 if ( icase != 0 ) { // check for errors 1025 if( icase < 0) 1052 pLP->m= cons; 1053 pLP->n= cols-1; 1054 pLP->m3= cons; 1055 1056 pLP->compute(); 1057 1058 if ( pLP->icase != 0 ) { // check for errors 1059 if( pLP->icase < 0) 1026 1060 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: minR: infeasible"); 1027 else if( icase > 0)1061 else if( pLP->icase > 0) 1028 1062 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: minR: unbounded"); 1029 1063 } … … 1071 1105 #endif 1072 1106 1073 #if 1 1074 if ( cons + 1 > pLP->LiPM_rows ) 1075 WerrorS(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!"); 1076 if ( cols + 1 > pLP->LiPM_cols ) 1077 WerrorS(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!"); 1078 #endif 1107 pLP->m= cons; 1108 pLP->n= cols-1; 1109 pLP->m3= cons; 1079 1110 1080 1111 // simplx finds MAX for obj.fnc, puts it in [1,1] 1081 simplx(pLP->LiPM, cons, cols-1, 0, 0, cons, &icase, pLP->izrov, pLP->iposv);1082 1083 if ( icase != 0 )1084 { 1085 if( icase < 0)1112 pLP->compute(); 1113 1114 if ( pLP->icase != 0 ) 1115 { 1116 if( pLP->icase < 0) 1086 1117 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: maxR: infeasible"); 1087 else if( icase > 0)1118 else if( pLP->icase > 0) 1088 1119 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: maxR: unbounded"); 1089 1120 } … … 1198 1229 { 1199 1230 int i, j, k,c ; 1200 int ncols, size, icase, NumCons;1231 int size; 1201 1232 bool found= true; 1202 1233 mprfloat cd; … … 1205 1236 setID *optSum; 1206 1237 1207 ncols= 1;1208 NumCons= n + n + 1; // number of constrains1238 LP->n = 1; 1239 LP->m = n + n + 1; // number of constrains 1209 1240 1210 1241 // fill in LP matrix … … 1214 1245 for ( k= 1; k <= size; k++ ) 1215 1246 { 1216 ncols++;1247 LP->n++; 1217 1248 1218 1249 // objective funtion, minimize 1219 LP .LiPM[1][ncols] = - ( (mprfloat) (*pQ[i])[k]->point[pQ[i]->dim] / SCALEDOWN );1250 LP->LiPM[1][LP->n] = - ( (mprfloat) (*pQ[i])[k]->point[pQ[i]->dim] / SCALEDOWN ); 1220 1251 1221 1252 // lambdas sum up to 1 1222 1253 for ( j = 0; j <= n; j++ ) 1223 1254 if ( i==j ) 1224 LP .LiPM[j+2][ncols] = -1.0;1255 LP->LiPM[j+2][LP->n] = -1.0; 1225 1256 else 1226 LP .LiPM[j+2][ncols] = 0.0;1257 LP->LiPM[j+2][LP->n] = 0.0; 1227 1258 1228 1259 // the points 1229 1260 for ( j = 1; j <= n; j++ ) 1230 1261 { 1231 LP .LiPM[j+n+2][ncols] = - ( (mprfloat) (*pQ[i])[k]->point[j] );1232 } 1233 } 1234 } 1235 1236 for ( j = 0; j <= n; j++ ) LP .LiPM[j+2][1] = 1.0;1262 LP->LiPM[j+n+2][LP->n] = - ( (mprfloat) (*pQ[i])[k]->point[j] ); 1263 } 1264 } 1265 } 1266 1267 for ( j = 0; j <= n; j++ ) LP->LiPM[j+2][1] = 1.0; 1237 1268 for ( j= 1; j <= n; j++ ) 1238 1269 { 1239 LP .LiPM[j+n+2][1]= (mprfloat)(*E)[vert]->point[j] - shift[j];1240 } 1241 ncols--;1242 1243 LP .LiPM[1][1] = 0.0;1270 LP->LiPM[j+n+2][1]= (mprfloat)(*E)[vert]->point[j] - shift[j]; 1271 } 1272 LP->n--; 1273 1274 LP->LiPM[1][1] = 0.0; 1244 1275 1245 1276 #ifdef mprDEBUG_ALL 1246 1277 PrintLn(); 1247 Print(" n= %d, NumCons=M= %d, ncols=N= %d\n",n,NumCons,ncols); 1248 print_mat(LP.LiPM, NumCons+1, ncols+1); 1249 #endif 1250 1251 #if 1 1252 if ( NumCons + 1 > LP.LiPM_rows ) 1253 WerrorS("resMatrixSparse::RC: #rows > #LP.LiPM_rows!"); 1254 if ( ncols + 1 > LP.LiPM_cols ) 1255 WerrorS("resMatrixSparse::RC: #cols > #LP.LiPM_cols!"); 1256 #endif 1257 1258 // M N m1 m2 m3, M= m1+m2+m3 1259 simplx(LP.LiPM, NumCons, ncols, 0, 0, NumCons, &icase, LP.izrov, LP.iposv); 1260 1261 if (icase < 0) 1278 Print(" n= %d, LP->m=M= %d, LP->n=N= %d\n",n,LP->m,LP->n); 1279 print_mat(LP->LiPM, LP->m+1, LP->n+1); 1280 #endif 1281 1282 LP->m3= LP->m; 1283 1284 LP->compute(); 1285 1286 if ( LP->icase < 0 ) 1262 1287 { 1263 1288 // infeasibility: the point does not lie in a cell -> remove it … … 1266 1291 1267 1292 // store result 1268 (*E)[vert]->point[E->dim]= (int)(-LP .LiPM[1][1] * SCALEDOWN);1293 (*E)[vert]->point[E->dim]= (int)(-LP->LiPM[1][1] * SCALEDOWN); 1269 1294 1270 1295 #ifdef mprDEBUG_ALL 1271 Print(" simplx returned %d, Objective value = %f\n", icase, LP.LiPM[1][1]);1272 //print_bmat(LP .LiPM, NumCons + 1, ncols+1-NumCons, ncols+1, LP.iposv); // ( rows= M+1, cols= N+1-m3 )1273 //print_mat(LP .LiPM, NumCons+1, ncols);1296 Print(" simplx returned %d, Objective value = %f\n", LP->icase, LP->LiPM[1][1]); 1297 //print_bmat(LP->LiPM, NumCons + 1, LP->n+1-NumCons, LP->n+1, LP->iposv); // ( rows= M+1, cols= N+1-m3 ) 1298 //print_mat(LP->LiPM, NumCons+1, LP->n); 1274 1299 #endif 1275 1300 … … 1279 1304 { 1280 1305 found=false; 1281 for ( i= 1; i < NumCons; i++ )1282 { 1283 if ( LP .iposv[i] > LP.iposv[i+1] )1284 { 1285 1286 c= LP .iposv[i];1287 LP .iposv[i]=LP.iposv[i+1];1288 LP .iposv[i+1]=c;1289 1290 cd=LP .LiPM[i+1][1];1291 LP .LiPM[i+1][1]=LP.LiPM[i+2][1];1292 LP .LiPM[i+2][1]=cd;1306 for ( i= 1; i < LP->m; i++ ) 1307 { 1308 if ( LP->iposv[i] > LP->iposv[i+1] ) 1309 { 1310 1311 c= LP->iposv[i]; 1312 LP->iposv[i]=LP->iposv[i+1]; 1313 LP->iposv[i+1]=c; 1314 1315 cd=LP->LiPM[i+1][1]; 1316 LP->LiPM[i+1][1]=LP->LiPM[i+2][1]; 1317 LP->LiPM[i+2][1]=cd; 1293 1318 1294 1319 found= true; … … 1299 1324 1300 1325 #ifdef mprDEBUG_ALL 1301 print_bmat(LP .LiPM, NumCons + 1, ncols+1-NumCons, ncols+1, LP.iposv);1326 print_bmat(LP->LiPM, LP->m + 1, LP->n+1-LP->m, LP->n+1, LP->iposv); 1302 1327 Print(" now split into sets\n"); 1303 1328 #endif … … 1308 1333 // remap results of LP to sets Qi 1309 1334 c=0; 1310 optSum= (setID*)Alloc( ( NumCons) * sizeof(struct setID) );1311 for ( i= 0; i < NumCons; i++ )1312 { 1313 //Print("% .15f\n",LP .LiPM[i+2][1]);1314 if ( LP .LiPM[i+2][1] > 1e-12 )1315 { 1316 if ( !remapXiToPoint( LP .iposv[i+1], pQ, &(optSum[c].set), &(optSum[c].pnt) ) )1317 { 1318 Werror(" resMatrixSparse::RC: Found bad solution in LP: %d!",LP .iposv[i+1]);1335 optSum= (setID*)Alloc( (LP->m) * sizeof(struct setID) ); 1336 for ( i= 0; i < LP->m; i++ ) 1337 { 1338 //Print("% .15f\n",LP->LiPM[i+2][1]); 1339 if ( LP->LiPM[i+2][1] > 1e-12 ) 1340 { 1341 if ( !remapXiToPoint( LP->iposv[i+1], pQ, &(optSum[c].set), &(optSum[c].pnt) ) ) 1342 { 1343 Werror(" resMatrixSparse::RC: Found bad solution in LP: %d!",LP->iposv[i+1]); 1319 1344 WerrorS(" resMatrixSparse::RC: remapXiToPoint faild!"); 1320 1345 return -1; … … 1348 1373 if ( (*E)[vert]->rc.set == linPolyS ) numSet0++; 1349 1374 1350 #ifdef mprDEBUG_ ALL1375 #ifdef mprDEBUG_PROT 1351 1376 Print("\n Point E[%d] was <",vert);print_exp((*E)[vert],E->dim-1);Print(">, bucket={"); 1352 1377 for ( j= 0; j < E->dim; j++ ) … … 1355 1380 } 1356 1381 Print(" }\n optimal Sum: Qi "); 1357 for ( j= 0; j < NumCons; j++ )1382 for ( j= 0; j < LP->m; j++ ) 1358 1383 { 1359 1384 Print(" [ %d, %d ]",optSum[j].set,optSum[j].pnt); … … 1363 1388 1364 1389 // clean up 1365 Free( (ADDRESS) optSum, ( NumCons) * sizeof(struct setID) );1390 Free( (ADDRESS) optSum, (LP->m) * sizeof(struct setID) ); 1366 1391 1367 1392 mprSTICKYPROT(ST_SPARSE_RC); 1368 1393 1369 return (int)(-LP .LiPM[1][1] * SCALEDOWN);1394 return (int)(-LP->LiPM[1][1] * SCALEDOWN); 1370 1395 } 1371 1396 … … 1465 1490 int i,j; 1466 1491 i= 1; 1467 /* 1468 shift[1]= (mprfloat) (RVMULT*(siRand()%MAXRVVAL)/(mprfloat)MAXRVVAL); 1469 i++; 1470 while ( i <= dim ) 1471 { 1472 shift[i]=shift[1]; 1473 i++; 1474 } 1475 */ 1492 time_t *tp = NULL; 1493 1476 1494 while ( i <= dim ) 1477 1495 { … … 1487 1505 } 1488 1506 } 1489 1490 1507 } 1491 1508 … … 1567 1584 idelem= IDELEMS(gls); // should be n+1 1568 1585 1569 // prepare matrix LP .LiPM for Linear Programming1586 // prepare matrix LP->LiPM for Linear Programming 1570 1587 totverts = 0; 1571 1588 for( i=0; i < idelem; i++) totverts += pLength( (gls->m)[i] ); 1572 1589 1573 LP.LiPM_rows= idelem+totverts*2+5; // very approximal 1574 LP.LiPM_cols= totverts+5; 1575 1576 #ifdef mprDEBUG_ALL 1577 Print("LP.LiPM size: %d, %d\n",LP.LiPM_rows,LP.LiPM_cols); 1578 #endif 1579 1580 // need AllocAligned since we allocate mem for type double 1581 LP.LiPM = (mprfloat **)Alloc( LP.LiPM_rows * sizeof(mprfloat *) ); // LP matrix 1582 for( i= 0; i < LP.LiPM_rows; i++ ) 1583 { 1584 // Mem must be allocated aligned, also for type double! 1585 LP.LiPM[i] = (mprfloat *)AllocAligned0( LP.LiPM_cols * sizeof(mprfloat) ); 1586 // LP.LiPM[i] = (mprfloat *)Alloc0( LP.LiPM_cols * sizeof(mprfloat) ); 1587 } 1588 1589 LP.iposv = (int *)Alloc0( (idelem * MAXPOINTS) * sizeof(int) ); 1590 LP.izrov = (int *)Alloc0( (idelem * MAXPOINTS) * sizeof(int) ); 1590 LP = new simplex( idelem+totverts*2+5, totverts+5 ); // rows, cols 1591 1591 1592 1592 // get shift vector … … 1604 1604 1605 1605 // evaluate convex hull for supports of gls 1606 convexHull chnp( &LP );1607 Qi= chnp.newtonPolytopes ( gls );1606 convexHull chnp( LP ); 1607 Qi= chnp.newtonPolytopesP( gls ); 1608 1608 1609 1609 #ifdef mprMINKSUM … … 1611 1611 #else 1612 1612 // get inner points 1613 mayanPyramidAlg mpa( &LP );1613 mayanPyramidAlg mpa( LP ); 1614 1614 E= mpa.getInnerPoints( Qi, shift ); 1615 1615 #endif 1616 1616 1617 #ifdef mprDEBUG_ ALL1617 #ifdef mprDEBUG_PROT 1618 1618 #ifdef mprMINKSUM 1619 1619 Print("(MinkSum)"); … … 1675 1675 E->sort(); 1676 1676 1677 #ifdef mprDEBUG_ ALL1677 #ifdef mprDEBUG_PROT 1678 1678 Print(" points with a[ij] (%d):\n",E->num); 1679 1679 for ( pnt= 1; pnt <= E->num; pnt++ ) … … 1706 1706 delete E; 1707 1707 1708 for( i= 0; i < LP.LiPM_rows; i++ ) 1709 { 1710 FreeAligned( (ADDRESS) LP.LiPM[i], LP.LiPM_cols * sizeof(mprfloat) ); 1711 // Free( (ADDRESS) LP.LiPM[i], LP.LiPM_cols * sizeof(mprfloat) ); 1712 } 1713 Free( (ADDRESS) LP.LiPM, LP.LiPM_rows * sizeof(mprfloat *) ); 1714 1715 Free( (ADDRESS) LP.iposv, (idelem * MAXPOINTS) * sizeof(int) ); 1716 Free( (ADDRESS) LP.izrov, (idelem * MAXPOINTS) * sizeof(int) ); 1708 delete LP; 1717 1709 } 1718 1710 … … 2534 2526 2535 2527 // evaluate determinant of matrix m using factory singclap_det 2536 #ifdef HAVE_FACTORY2537 2528 poly res= singclap_det( m ); 2538 #else2539 poly res= mpDetBareiss( m );2540 #endif2541 2529 2542 2530 // avoid errors for det==0 … … 2598 2586 } 2599 2587 2600 #ifdef HAVE_FACTORY2601 2588 poly res= singclap_det( mat ); 2602 #else2603 poly res= mpDetBareiss( mat );2604 #endif2605 2589 2606 2590 number numres; … … 2623 2607 2624 2608 #define MAXEVPOINT 1000000 // 0x7fffffff 2609 //#define MPR_MASI 2625 2610 2626 2611 //-> unsigned long over(unsigned long n,unsigned long d) … … 2938 2923 else if ( i <= uvar + 2 ) 2939 2924 { 2940 pevpoint[i]=nInit(1+(siRand() % MAXEVPOINT));2925 pevpoint[i]=nInit(1+siRand()%MAXEVPOINT); 2941 2926 //pevpoint[i]=nInit(383); 2942 2927 } … … 3058 3043 if ( i <= uvar + 2 ) 3059 3044 { 3060 pevpoint[i]=nInit(1+(siRand() % MAXEVPOINT));3045 pevpoint[i]=nInit(1+siRand()%MAXEVPOINT); 3061 3046 //pevpoint[i]=nInit(383); 3062 3047 } else pevpoint[i]=nInit(0); … … 3080 3065 number *ncpoly= (number *)Alloc( (tdg+1) * sizeof(number) ); 3081 3066 3082 #ifdef MPR_TIMING 3083 BOOLEAN masi=true; 3084 #endif 3067 #ifdef MPR_MASI 3068 BOOLEAN masi=true; 3069 #endif 3070 3085 3071 piter= pures; 3086 3072 for ( i= tdg; i >= 0; i-- ) … … 3091 3077 ncpoly[i]= nCopy( pGetCoeff( piter ) ); 3092 3078 pIter( piter ); 3093 #ifdef MPR_ TIMING3094 3079 #ifdef MPR_MASI 3080 masi=false; 3095 3081 #endif 3096 3082 } … … 3101 3087 mprPROTNnl("", ncpoly[i] ); 3102 3088 } 3103 3104 #ifdef MPR_TIMING 3105 if ( masi ) Print("MASI MASI MASI\n"); 3089 #ifdef MPR_MASI 3090 if ( masi ) mprSTICKYPROT("MASI"); 3106 3091 #endif 3107 3092 … … 3149 3134 } 3150 3135 //<- 3136 3137 //----------------------------------------------------------------------------- 3138 3139 //-> loNewtonPolytope(...) 3140 ideal loNewtonPolytope( const ideal id ) 3141 { 3142 simplex * LP; 3143 int i; 3144 int n,totverts,idelem; 3145 ideal idr; 3146 3147 n= pVariables; 3148 idelem= IDELEMS(id); // should be n+1 3149 3150 totverts = 0; 3151 for( i=0; i < idelem; i++) totverts += pLength( (id->m)[i] ); 3152 3153 LP = new simplex( idelem+totverts*2+5, totverts+5 ); // rows, cols 3154 3155 // evaluate convex hull for supports of id 3156 convexHull chnp( LP ); 3157 idr = chnp.newtonPolytopesI( id ); 3158 3159 delete LP; 3160 3161 return idr; 3162 } 3163 //<- 3164 3151 3165 //%e 3152 3166 … … 3164 3178 // leave fold: C-c y 3165 3179 // foldmode: F10 3166 -
Singular/mpr_base.h
r2983b3 rc7f3b7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_base.h,v 1. 4 1999-11-15 17:20:30 obachmanExp $ */6 /* $Id: mpr_base.h,v 1.5 1999-12-02 23:03:50 wenk Exp $ */ 7 7 8 8 /* … … 94 94 }; 95 95 //<- 96 97 ideal loNewtonPolytope( const ideal id ); 96 98 //%e 97 99 #endif MPR_BASE_H -
Singular/mpr_global.h
r2983b3 rc7f3b7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_global.h,v 1. 8 1999-11-15 17:20:30 obachmanExp $ */6 /* $Id: mpr_global.h,v 1.9 1999-12-02 23:03:50 wenk Exp $ */ 7 7 8 8 /* … … 12 12 13 13 // to get detailed timigs, define MPR_TIMING 14 // 14 //#define MPR_TIMING 15 15 16 16 // Set to double or long double. double is recomended. -
Singular/mpr_inout.cc
r2983b3 rc7f3b7 3 3 ****************************************/ 4 4 5 /* $Id: mpr_inout.cc,v 1. 6 1999-11-15 17:20:30 obachmanExp $ */5 /* $Id: mpr_inout.cc,v 1.7 1999-12-02 23:03:51 wenk Exp $ */ 6 6 7 7 /* … … 25 25 #include "numbers.h" 26 26 #include "lists.h" 27 #include "matpol.h" 27 28 28 29 #include <math.h> … … 36 37 #ifdef MPR_TIMING 37 38 #define TIMING 39 #endif 38 40 #include "../factory/timing.h" 39 41 TIMING_DEFINE_PRINT(mpr_overall) … … 44 46 TIMING_DEFINE_PRINT(mpr_arrange) 45 47 TIMING_DEFINE_PRINT(mpr_solver) 48 46 49 #define TIMING_EPR(t,msg) TIMING_END_AND_PRINT(t,msg);TIMING_RESET(t); 47 #else48 #define TIMING_START(x)49 #define TIMING_EPR(x,y)50 #endif51 52 50 53 51 enum mprState … … 181 179 if ( v->Typ() != IDEAL_CMD ) 182 180 return TRUE; 183 else gls= (ideal)( args->Data());181 else gls= (ideal)(v->Data()); 184 182 v= v->next; 185 183 … … 211 209 BOOLEAN interpolate_det= (mtype==uResultant::denseResMat)?TRUE:FALSE; 212 210 213 //emptylist= (lists)Alloc SizeOf( slists);211 //emptylist= (lists)Alloc( sizeof(slists) ); 214 212 //emptylist->Init( 0 ); 215 213 … … 314 312 315 313 //emptylist->Clean(); 316 // Free SizeOf( (ADDRESS) emptylist, slists);314 // Free( (ADDRESS) emptylist, sizeof(slists) ); 317 315 318 316 TIMING_EPR(mpr_overall,"overall time\t\t") … … 356 354 int howclean= (int)arg3->Data(); 357 355 356 if ( !(rField_is_R() || 357 rField_is_Q() || 358 rField_is_long_R() || 359 rField_is_long_C()) ) 360 { 361 WerrorS("Ground field not implemented!"); 362 return TRUE; 363 } 364 358 365 if ( !(rField_is_R()||rField_is_long_R()||rField_is_long_C()) ) 359 366 { 360 367 setGMPFloatDigits( (unsigned long int)arg2->Data() ); 368 } 369 370 if ( gls == NULL || pIsConstant( gls ) ) 371 { 372 WerrorS("Input polynomial is constant!"); 373 return TRUE; 361 374 } 362 375 … … 369 382 lists rlist; 370 383 371 elist= (lists)Alloc SizeOf( slists);384 elist= (lists)Alloc( sizeof(slists) ); 372 385 elist->Init( 0 ); 373 374 if ( !(rField_is_R() ||375 rField_is_Q() ||376 rField_is_long_R() ||377 rField_is_long_C()) )378 {379 WerrorS("Ground field not implemented!");380 return TRUE;381 }382 386 383 387 if ( pVariables > 1 ) … … 395 399 if ( (vpos != i) && (pGetExp( piter, i ) != 0) ) 396 400 { 397 Werror ("The polynomial %s must be univariate!",arg1->Name());401 WerrorS("The input polynomial must be univariate!"); 398 402 return TRUE; 399 403 } … … 438 442 int j; 439 443 440 rlist= (lists)Alloc SizeOf( slists);444 rlist= (lists)Alloc( sizeof(slists) ); 441 445 rlist->Init( elem ); 442 446 … … 461 465 462 466 elist->Clean(); 463 //Free SizeOf( (ADDRESS) elist, slists);467 //Free( (ADDRESS) elist, sizeof(slists) ); 464 468 465 469 for ( i= deg; i >= 0; i-- ) nDelete( &pcoeffs[i] ); … … 629 633 //<- 630 634 635 //-> BOOLEAN loNewtonP( leftv res, leftv arg1 ) 636 BOOLEAN loNewtonP( leftv res, leftv arg1 ) 637 { 638 res->data= (void*)loNewtonPolytope( (ideal)arg1->Data() ); 639 return FALSE; 640 } 641 //<- 642 643 //-> BOOLEAN loSimplex( leftv res, leftv args ) 644 BOOLEAN loSimplex( leftv res, leftv args ) 645 { 646 if ( !(rField_is_long_R()) ) 647 { 648 WerrorS("Ground field not implemented!"); 649 return TRUE; 650 } 651 652 simplex * LP; 653 matrix m; 654 655 leftv v= args; 656 if ( v->Typ() != MATRIX_CMD ) // 1: matrix 657 return TRUE; 658 else 659 m= (matrix)(v->Data()); 660 661 LP = new simplex(MATROWS(m),MATCOLS(m)); 662 LP->mapFromMatrix(m); 663 664 v= v->next; 665 if ( v->Typ() != INT_CMD ) // 2: m = number of constraints 666 return TRUE; 667 else 668 LP->m= (int)(v->Data()); 669 670 v= v->next; 671 if ( v->Typ() != INT_CMD ) // 3: n = number of variables 672 return TRUE; 673 else 674 LP->n= (int)(v->Data()); 675 676 v= v->next; 677 if ( v->Typ() != INT_CMD ) // 4: m1 = number of <= constraints 678 return TRUE; 679 else 680 LP->m1= (int)(v->Data()); 681 682 v= v->next; 683 if ( v->Typ() != INT_CMD ) // 5: m2 = number of >= constraints 684 return TRUE; 685 else 686 LP->m2= (int)(v->Data()); 687 688 v= v->next; 689 if ( v->Typ() != INT_CMD ) // 6: m3 = number of == constraints 690 return TRUE; 691 else 692 LP->m3= (int)(v->Data()); 693 694 #ifdef mprDEBUG_PROT 695 Print("m (constraints) %d\n",LP->m); 696 Print("n (columns) %d\n",LP->n); 697 Print("m1 (<=) %d\n",LP->m1); 698 Print("m2 (>=) %d\n",LP->m2); 699 Print("m3 (==) %d\n",LP->m3); 700 #endif 701 702 LP->compute(); 703 704 lists lres= (lists)Alloc( sizeof(slists) ); 705 lres->Init( 6 ); 706 707 lres->m[0].rtyp= MATRIX_CMD; // output matrix 708 lres->m[0].data=(void*)LP->mapToMatrix(m); 709 710 lres->m[1].rtyp= INT_CMD; // found a solution? 711 lres->m[1].data=(void*)LP->icase; 712 713 lres->m[2].rtyp= INTVEC_CMD; 714 lres->m[2].data=(void*)LP->posvToIV(); 715 716 lres->m[3].rtyp= INTVEC_CMD; 717 lres->m[3].data=(void*)LP->zrovToIV(); 718 719 lres->m[4].rtyp= INT_CMD; 720 lres->m[4].data=(void*)LP->m; 721 722 lres->m[5].rtyp= INT_CMD; 723 lres->m[5].data=(void*)LP->n; 724 725 res->data= (void*)lres; 726 727 return FALSE; 728 } 729 //<- 730 631 731 //----------------------------------------------------------------------------- 632 732 -
Singular/mpr_inout.h
r2983b3 rc7f3b7 5 5 ****************************************/ 6 6 7 /* $Id: mpr_inout.h,v 1. 5 1999-11-15 17:20:31 obachmanExp $ */7 /* $Id: mpr_inout.h,v 1.6 1999-12-02 23:03:51 wenk Exp $ */ 8 8 9 9 /* … … 58 58 BOOLEAN nuVanderSys( leftv res, leftv arg1, leftv arg2, leftv arg3 ); 59 59 60 /** compute Newton Polytopes of input polynomials 61 */ 62 BOOLEAN loNewtonP( leftv res, leftv arg1 ); 63 64 /** Implementation of the Simplex Algorithm. 65 * For args, see class simplex. 66 */ 67 BOOLEAN loSimplex( leftv res, leftv args ); 68 60 69 #endif 61 70 -
Singular/mpr_numeric.cc
r2983b3 rc7f3b7 3 3 ****************************************/ 4 4 5 /* $Id: mpr_numeric.cc,v 1. 6 1999-11-15 17:20:31 obachmanExp $ */5 /* $Id: mpr_numeric.cc,v 1.7 1999-12-02 23:03:51 wenk Exp $ */ 6 6 7 7 /* … … 24 24 #include "intvec.h" 25 25 #include "longalg.h" 26 #include "matpol.h" 26 27 #include "ring.h" 27 28 //#include "longrat.h" … … 749 750 int elem= roots[0]->getAnzElems(); // number of koordinates per root 750 751 751 lists listofroots= (lists)Alloc SizeOf( slists); // must be done this way!752 lists listofroots= (lists)Alloc( sizeof(slists) ); // must be done this way! 752 753 753 754 if ( found_roots ) … … 757 758 for (i=0; i < count; i++) 758 759 { 759 lists onepoint= (lists)Alloc SizeOf(slists); // must be done this way!760 lists onepoint= (lists)Alloc(sizeof(slists)); // must be done this way! 760 761 onepoint->Init(elem); 761 762 for ( j= 0; j < elem; j++ ) … … 791 792 792 793 //----------------------------------------------------------------------------- 793 //-------------- ludcmp/lubksb------------------------------------------------794 //-------------- simplex ----- ------------------------------------------------ 794 795 //----------------------------------------------------------------------------- 795 796 796 //#define error(a) a 797 #define error(a) 798 799 //-> simplex 797 // #ifdef mprDEBUG_PROT 798 // #define error(a) a 799 // #else 800 // #define error(a) 801 // #endif 802 803 #define error(a) a 804 805 #define MAXPOINTS 1000 806 807 //-> simplex::* 800 808 // 801 void simp1( mprfloat **a, int mm, int ll[], int nll, int iabf, int *kp, mprfloat *bmax ); 802 void simp2( mprfloat **a, int n, int l2[], int nl2, int *ip, int kp, mprfloat *q1 ); 803 void simp3( mprfloat **a, int i1, int k1, int ip, int kp ); 804 805 void simplx( mprfloat **a, int m, int n, int m1, int m2, int m3, int *icase, int izrov[], int iposv[] ) 809 simplex::simplex( int rows, int cols ) 810 : LiPM_cols(cols), LiPM_rows(rows) 811 { 812 int i; 813 814 LiPM_rows=LiPM_rows+3; 815 LiPM_cols=LiPM_cols+2; 816 817 LiPM = (mprfloat **)Alloc( LiPM_rows * sizeof(mprfloat *) ); // LP matrix 818 for( i= 0; i < LiPM_rows; i++ ) 819 { 820 // Mem must be allocated aligned, also for type double! 821 LiPM[i] = (mprfloat *)AllocAligned0( LiPM_cols * sizeof(mprfloat) ); 822 } 823 824 iposv = (int *)Alloc0( 2*LiPM_rows*sizeof(int) ); 825 izrov = (int *)Alloc0( 2*LiPM_rows*sizeof(int) ); 826 827 m=n=m1=m2=m3=icase=0; 828 829 #ifdef mprDEBUG_ALL 830 Print("LiPM size: %d, %d\n",LiPM_rows,LiPM_cols); 831 #endif 832 } 833 834 simplex::~simplex() 835 { 836 // clean up 837 int i; 838 for( i= 0; i < LiPM_rows; i++ ) 839 { 840 FreeAligned( (ADDRESS) LiPM[i], LiPM_cols * sizeof(mprfloat) ); 841 } 842 Free( (ADDRESS) LiPM, LiPM_rows * sizeof(mprfloat *) ); 843 844 Free( (ADDRESS) iposv, 2*LiPM_rows*sizeof(int) ); 845 Free( (ADDRESS) izrov, 2*LiPM_rows*sizeof(int) ); 846 } 847 848 BOOLEAN simplex::mapFromMatrix( matrix m ) 849 { 850 int i,j; 851 // if ( MATROWS( m ) > LiPM_rows || MATCOLS( m ) > LiPM_cols ) { 852 // WerrorS(""); 853 // return FALSE; 854 // } 855 856 number coef; 857 for ( i= 1; i <= MATROWS( m ); i++ ) 858 { 859 for ( j= 1; j <= MATCOLS( m ); j++ ) 860 { 861 if ( MATELEM(m,i,j) != NULL ) 862 { 863 coef= pGetCoeff( MATELEM(m,i,j) ); 864 if ( coef != NULL && !nIsZero(coef) ) 865 LiPM[i][j]= (double)(*(gmp_float*)coef); 866 //#ifdef mpr_DEBUG_PROT 867 //Print("%f ",LiPM[i][j]); 868 //#endif 869 } 870 } 871 // PrintLn(); 872 } 873 874 return TRUE; 875 } 876 877 matrix simplex::mapToMatrix( matrix m ) 878 { 879 int i,j; 880 // if ( MATROWS( m ) < LiPM_rows-3 || MATCOLS( m ) < LiPM_cols-2 ) { 881 // WerrorS(""); 882 // return NULL; 883 // } 884 885 //Print(" %d x %d\n",MATROWS( m ),MATCOLS( m )); 886 887 number coef; 888 gmp_float * bla; 889 for ( i= 1; i <= MATROWS( m ); i++ ) 890 { 891 for ( j= 1; j <= MATCOLS( m ); j++ ) 892 { 893 pDelete( &(MATELEM(m,i,j)) ); 894 MATELEM(m,i,j)= NULL; 895 //Print(" %3.0f ",LiPM[i][j]); 896 if ( LiPM[i][j] != 0.0 ) 897 { 898 bla= new gmp_float(LiPM[i][j]); 899 coef= (number)bla; 900 MATELEM(m,i,j)= pOne(); 901 pSetCoeff( MATELEM(m,i,j), coef ); 902 } 903 } 904 //PrintLn(); 905 } 906 907 return m; 908 } 909 910 intvec * simplex::posvToIV() 911 { 912 int i; 913 intvec * iv = new intvec( m ); 914 for ( i= 1; i <= m; i++ ) 915 { 916 IMATELEM(*iv,i,1)= iposv[i]; 917 } 918 return iv; 919 } 920 921 intvec * simplex::zrovToIV() 922 { 923 int i; 924 intvec * iv = new intvec( n ); 925 for ( i= 1; i <= n; i++ ) 926 { 927 IMATELEM(*iv,i,1)= izrov[i]; 928 } 929 return iv; 930 } 931 932 void simplex::compute() 806 933 { 807 934 int i,ip,ir,is,k,kh,kp,m12,nl1,nl2; … … 809 936 mprfloat q1, bmax; 810 937 811 if ( m != (m1+m2+m3) )938 if ( m != (m1+m2+m3) ) 812 939 { 813 940 // error: bad input 814 error(WerrorS(" bad input constraint counts in simplex");)815 *icase=-2;941 error(WerrorS("simplex::compute: Bad input constraint counts!");) 942 icase=-2; 816 943 return; 817 944 } … … 826 953 for ( i=1; i<=m; i++ ) 827 954 { 828 if ( a[i+1][1] < 0.0 )955 if ( LiPM[i+1][1] < 0.0 ) 829 956 { 830 957 // error: bad input 831 error(WerrorS(" bad input tableau in simplex ");) 832 *icase=-2; 958 error(WerrorS("simplex::compute: Bad input tableau!");) 959 error(Werror("simplex::compute: in input Matrix row %d, column 1, value %f",i+1,LiPM[i+1][1]);) 960 icase=-2; 833 961 // free mem l1,l2,l3; 834 962 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); … … 848 976 { 849 977 q1=0.0; 850 for ( i=m1+1; i <= m; i++ ) q1+= a[i+1][k];851 a[m+2][k]= -q1;978 for ( i=m1+1; i <= m; i++ ) q1+= LiPM[i+1][k]; 979 LiPM[m+2][k]= -q1; 852 980 } 853 981 854 982 do 855 983 { 856 simp1( a,m+1,l1,nl1,0,&kp,&bmax);857 if ( bmax <= SIMPLEX_EPS && a[m+2][1] < -SIMPLEX_EPS )858 { 859 *icase= -1; // no solution found984 simp1(LiPM,m+1,l1,nl1,0,&kp,&bmax); 985 if ( bmax <= SIMPLEX_EPS && LiPM[m+2][1] < -SIMPLEX_EPS ) 986 { 987 icase= -1; // no solution found 860 988 // free mem l1,l2,l3; 861 989 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); … … 864 992 return; 865 993 } 866 else if ( bmax <= SIMPLEX_EPS && a[m+2][1] <= SIMPLEX_EPS )994 else if ( bmax <= SIMPLEX_EPS && LiPM[m+2][1] <= SIMPLEX_EPS ) 867 995 { 868 996 m12= m1+m2+1; … … 873 1001 if ( iposv[ip] == (ip+n) ) 874 1002 { 875 simp1( a,ip,l1,nl1,1,&kp,&bmax);1003 simp1(LiPM,ip,l1,nl1,1,&kp,&bmax); 876 1004 if ( fabs(bmax) >= SIMPLEX_EPS) 877 1005 goto one; … … 885 1013 if ( l3[i-m1] == 1 ) 886 1014 for ( k=1; k <= n+1; k++ ) 887 a[i+1][k] = -a[i+1][k];1015 LiPM[i+1][k] = -(LiPM[i+1][k]); 888 1016 break; 889 1017 } … … 891 1019 //print_bmat( a, m+2, n+3); 892 1020 //#endif 893 simp2( a,n,l2,nl2,&ip,kp,&q1);1021 simp2(LiPM,n,l2,nl2,&ip,kp,&q1); 894 1022 if ( ip == 0 ) 895 1023 { 896 *icase = -1; // no solution found1024 icase = -1; // no solution found 897 1025 // free mem l1,l2,l3; 898 1026 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); … … 901 1029 return; 902 1030 } 903 one: simp3( a,m+1,n,ip,kp);1031 one: simp3(LiPM,m+1,n,ip,kp); 904 1032 // #if DEBUG 905 1033 // print_bmat(a,m+2,n+3); … … 907 1035 if ( iposv[ip] >= (n+m1+m2+1)) 908 1036 { 909 for ( k= 1; k<= nl1; k++ )1037 for ( k= 1; k <= nl1; k++ ) 910 1038 if ( l1[k] == kp ) break; 911 1039 --nl1; 912 1040 for ( is=k; is <= nl1; is++ ) l1[is]= l1[is+1]; 913 ++ a[m+2][kp+1];914 for ( i= 1; i <= m+2; i++ ) a[i][kp+1] = -a[i][kp+1];1041 ++(LiPM[m+2][kp+1]); 1042 for ( i= 1; i <= m+2; i++ ) LiPM[i][kp+1] = -(LiPM[i][kp+1]); 915 1043 } 916 1044 else … … 922 1050 { 923 1051 l3[kh]= 0; 924 ++ a[m+2][kp+1];1052 ++(LiPM[m+2][kp+1]); 925 1053 for ( i=1; i<= m+2; i++ ) 926 a[i][kp+1] = -a[i][kp+1];1054 LiPM[i][kp+1] = -(LiPM[i][kp+1]); 927 1055 } 928 1056 } … … 939 1067 // print_bmat( a, m+1, n+5); 940 1068 // #endif 941 simp1( a,0,l1,nl1,0,&kp,&bmax);1069 simp1(LiPM,0,l1,nl1,0,&kp,&bmax); 942 1070 if (bmax <= /*SIMPLEX_EPS*/0.0) 943 1071 { 944 *icase=0; // finite solution found1072 icase=0; // finite solution found 945 1073 // free mem l1,l2,l3 946 1074 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); … … 949 1077 return; 950 1078 } 951 simp2( a,n,l2,nl2,&ip,kp,&q1);1079 simp2(LiPM,n,l2,nl2,&ip,kp,&q1); 952 1080 if (ip == 0) 953 1081 { … … 956 1084 // print_bmat( a, m+1, n+1); 957 1085 // #endif 958 *icase=1; /* unbounded */1086 icase=1; /* unbounded */ 959 1087 // free mem 960 1088 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); … … 963 1091 return; 964 1092 } 965 simp3( a,m,n,ip,kp);1093 simp3(LiPM,m,n,ip,kp); 966 1094 is= izrov[kp]; 967 1095 izrov[kp]= iposv[ip]; … … 970 1098 } 971 1099 972 void simp 1( mprfloat **a, int mm, int ll[], int nll, int iabf, int *kp, mprfloat *bmax )1100 void simplex::simp1( mprfloat **a, int mm, int ll[], int nll, int iabf, int *kp, mprfloat *bmax ) 973 1101 { 974 1102 int k; … … 1005 1133 } 1006 1134 1007 void simp 2( mprfloat **a, int n, int l2[], int nl2, int *ip, int kp, mprfloat *q1 )1135 void simplex::simp2( mprfloat **a, int n, int l2[], int nl2, int *ip, int kp, mprfloat *q1 ) 1008 1136 { 1009 1137 int k,ii,i; … … 1044 1172 } 1045 1173 1046 void simp 3( mprfloat **a, int i1, int k1, int ip, int kp )1174 void simplex::simp3( mprfloat **a, int i1, int k1, int ip, int kp ) 1047 1175 { 1048 1176 int kk,ii; -
Singular/mpr_numeric.h
r2983b3 rc7f3b7 5 5 ****************************************/ 6 6 7 /* $Id: mpr_numeric.h,v 1. 4 1999-11-15 17:20:31 obachmanExp $ */7 /* $Id: mpr_numeric.h,v 1.5 1999-12-02 23:03:52 wenk Exp $ */ 8 8 9 9 /* … … 162 162 #define SIMPLEX_EPS 1.0e-12 163 163 164 void simplx( mprfloat **a, int m, int n, int m1, int m2, int m3, int *icase, int izrov[], int iposv[] ); 164 /** Linear Programming / Linear Optimization using Simplex - Algorithm 165 * 166 * On output, the tableau LiPM is indexed by two arrays of integers. 167 * ipsov[j] contains, for j=1..m, the number i whose original variable 168 * is now represented by row j+1 of LiPM. (left-handed vars in solution) 169 * (first row is the one with the objective function) 170 * izrov[j] contains, for j=1..n, the number i whose original variable 171 * x_i is now a right-handed variable, rep. by column j+1 of LiPM. 172 * These vars are all zero in the solution. The meaning of n<i<n+m1+m2 173 * is the same as above. 174 */ 175 class simplex 176 { 177 public: 178 179 int m; // number of constraints, make sure m == m1 + m2 + m3 !! 180 int n; // # of independent variables 181 int m1,m2,m3; // constraints <=, >= and == 182 int icase; // == 0: finite solution found; 183 // == +1 objective funtion unbound; == -1: no solution 184 int *izrov,*iposv; 185 186 mprfloat **LiPM; // the matrix (of size [m+2, n+1]) 187 188 /** #rows should be >= m+2, #cols >= n+1 189 */ 190 simplex( int rows, int cols ); 191 ~simplex(); 192 193 BOOLEAN mapFromMatrix( matrix m ); 194 matrix mapToMatrix( matrix m ); 195 intvec * posvToIV(); 196 intvec * zrovToIV(); 197 198 void compute(); 199 200 private: 201 simplex( const simplex & ); 202 void simp1( mprfloat **a, int mm, int ll[], int nll, int iabf, int *kp, mprfloat *bmax ); 203 void simp2( mprfloat **a, int n, int l2[], int nl2, int *ip, int kp, mprfloat *q1 ); 204 void simp3( mprfloat **a, int i1, int k1, int ip, int kp ); 205 206 int LiPM_cols,LiPM_rows; 207 }; 208 165 209 //<- 166 210 -
Singular/tok.h
r2983b3 rc7f3b7 7 7 * ABSTRACT: tokens, types for interpreter; general macros 8 8 */ 9 /* $Id: tok.h,v 1.3 3 1999-11-29 14:46:55 SingularExp $ */9 /* $Id: tok.h,v 1.34 1999-12-02 23:03:52 wenk Exp $ */ 10 10 11 11 #ifndef MYYSTYPE … … 89 89 NAMEOF_CMD, 90 90 NAMES_CMD, 91 NEWTONPOLY_CMD, 91 92 NPARS_CMD, 92 93 NVARS_CMD, … … 106 107 RESULTANT_CMD, 107 108 ROWS_CMD, 109 SIMPLEX_CMD, 108 110 SQR_FREE_DEC_CMD, 109 111 STATUS_CMD,
Note: See TracChangeset
for help on using the changeset viewer.