 Timestamp:
 Feb 15, 2010 4:09:41 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

stable/BSPsplit/Clp/src/unitTest.cpp
r1344 r1520 782 782 CoinMpsIO m; 783 783 std::string fn = dirSample+"exmip1"; 784 m.readMps(fn.c_str(),"mps"); 785 ClpSimplex solution; 786 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 787 m.getObjCoefficients(), 788 m.getRowLower(),m.getRowUpper()); 789 solution.dual(); 790 // Test event handling 791 MyEventHandler handler; 792 solution.passInEventHandler(&handler); 793 int numberRows=solution.numberRows(); 794 // make sure values pass has something to do 795 for (int i=0;i<numberRows;i++) 796 solution.setRowStatus(i,ClpSimplex::basic); 797 solution.primal(1); 798 assert (solution.secondaryStatus()==102); // Came out at end of pass 784 if (m.readMps(fn.c_str(),"mps") == 0) { 785 ClpSimplex solution; 786 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 787 m.getObjCoefficients(), 788 m.getRowLower(),m.getRowUpper()); 789 solution.dual(); 790 // Test event handling 791 MyEventHandler handler; 792 solution.passInEventHandler(&handler); 793 int numberRows=solution.numberRows(); 794 // make sure values pass has something to do 795 for (int i=0;i<numberRows;i++) 796 solution.setRowStatus(i,ClpSimplex::basic); 797 solution.primal(1); 798 assert (solution.secondaryStatus()==102); // Came out at end of pass 799 } else { 800 std::cerr << "Error reading exmip1 from sample data. Skipping test." << std::endl; 801 } 799 802 } 800 803 // Test Message handler … … 803 806 std::string fn = dirSample+"exmip1"; 804 807 //fn = "Test/subGams4"; 805 m.readMps(fn.c_str(),"mps"); 806 ClpSimplex model; 807 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 808 m.getObjCoefficients(), 809 m.getRowLower(),m.getRowUpper()); 810 // Message handler 811 MyMessageHandler messageHandler(&model); 812 std::cout<<"Testing derived message handler"<<std::endl; 813 model.passInMessageHandler(&messageHandler); 814 model.messagesPointer()>setDetailMessage(1,102); 815 model.setFactorizationFrequency(10); 816 model.primal(); 817 model.primal(0,3); 818 model.setObjCoeff(3,2.9473684210526314); 819 model.primal(0,3); 820 // Write saved solutions 821 int nc = model.getNumCols(); 822 int s; 823 std::deque<StdVectorDouble> fep = messageHandler.getFeasibleExtremePoints(); 824 int numSavedSolutions = fep.size(); 825 for ( s=0; s<numSavedSolutions; ++s ) { 826 const StdVectorDouble & solnVec = fep[s]; 827 for ( int c=0; c<nc; ++c ) { 828 if (fabs(solnVec[c])>1.0e8) 829 std::cout <<"Saved Solution: " <<s <<" ColNum: " <<c <<" Value: " <<solnVec[c] <<std::endl; 830 } 831 } 832 // Solve again without scaling 833 // and maximize then minimize 834 messageHandler.clearFeasibleExtremePoints(); 835 model.scaling(0); 836 model.setOptimizationDirection(1); 837 model.primal(); 838 model.setOptimizationDirection(1); 839 model.primal(); 840 fep = messageHandler.getFeasibleExtremePoints(); 841 numSavedSolutions = fep.size(); 842 for ( s=0; s<numSavedSolutions; ++s ) { 843 const StdVectorDouble & solnVec = fep[s]; 844 for ( int c=0; c<nc; ++c ) { 845 if (fabs(solnVec[c])>1.0e8) 846 std::cout <<"Saved Solution: " <<s <<" ColNum: " <<c <<" Value: " <<solnVec[c] <<std::endl; 847 } 808 if (m.readMps(fn.c_str(),"mps") == 0) { 809 ClpSimplex model; 810 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 811 m.getObjCoefficients(), 812 m.getRowLower(),m.getRowUpper()); 813 // Message handler 814 MyMessageHandler messageHandler(&model); 815 std::cout<<"Testing derived message handler"<<std::endl; 816 model.passInMessageHandler(&messageHandler); 817 model.messagesPointer()>setDetailMessage(1,102); 818 model.setFactorizationFrequency(10); 819 model.primal(); 820 model.primal(0,3); 821 model.setObjCoeff(3,2.9473684210526314); 822 model.primal(0,3); 823 // Write saved solutions 824 int nc = model.getNumCols(); 825 int s; 826 std::deque<StdVectorDouble> fep = messageHandler.getFeasibleExtremePoints(); 827 int numSavedSolutions = fep.size(); 828 for ( s=0; s<numSavedSolutions; ++s ) { 829 const StdVectorDouble & solnVec = fep[s]; 830 for ( int c=0; c<nc; ++c ) { 831 if (fabs(solnVec[c])>1.0e8) 832 std::cout <<"Saved Solution: " <<s <<" ColNum: " <<c <<" Value: " <<solnVec[c] <<std::endl; 833 } 834 } 835 // Solve again without scaling 836 // and maximize then minimize 837 messageHandler.clearFeasibleExtremePoints(); 838 model.scaling(0); 839 model.setOptimizationDirection(1); 840 model.primal(); 841 model.setOptimizationDirection(1); 842 model.primal(); 843 fep = messageHandler.getFeasibleExtremePoints(); 844 numSavedSolutions = fep.size(); 845 for ( s=0; s<numSavedSolutions; ++s ) { 846 const StdVectorDouble & solnVec = fep[s]; 847 for ( int c=0; c<nc; ++c ) { 848 if (fabs(solnVec[c])>1.0e8) 849 std::cout <<"Saved Solution: " <<s <<" ColNum: " <<c <<" Value: " <<solnVec[c] <<std::endl; 850 } 851 } 852 } else { 853 std::cerr << "Error reading exmip1 from sample data. Skipping test." << std::endl; 848 854 } 849 855 } … … 853 859 CoinMpsIO m; 854 860 std::string fn = dirSample+"exmip1"; 855 m.readMps(fn.c_str(),"mps"); 856 ClpSimplex model; 857 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 858 m.getObjCoefficients(), 859 m.getRowLower(),m.getRowUpper()); 860 model.primal(); 861 int which[13] = {0,1,2,3,4,5,6,7,8,9,10,11,12}; 862 double costIncrease[13]; 863 int sequenceIncrease[13]; 864 double costDecrease[13]; 865 int sequenceDecrease[13]; 866 // ranging 867 model.dualRanging(13,which,costIncrease,sequenceIncrease, 868 costDecrease,sequenceDecrease); 869 int i; 870 for ( i=0;i<13;i++) 871 printf("%d increase %g %d, decrease %g %d\n", 872 i,costIncrease[i],sequenceIncrease[i], 873 costDecrease[i],sequenceDecrease[i]); 874 assert (fabs(costDecrease[3])<1.0e4); 875 assert (fabs(costIncrease[7]1.0)<1.0e4); 876 model.setOptimizationDirection(1); 877 { 878 int j; 879 double * obj = model.objective(); 880 int n=model.numberColumns(); 881 for (j=0;j<n;j++) 882 obj[j] *= 1.0; 883 } 884 double costIncrease2[13]; 885 int sequenceIncrease2[13]; 886 double costDecrease2[13]; 887 int sequenceDecrease2[13]; 888 // ranging 889 model.dualRanging(13,which,costIncrease2,sequenceIncrease2, 890 costDecrease2,sequenceDecrease2); 891 for (i=0;i<13;i++) { 892 assert (fabs(costIncrease[i]costDecrease2[i])<1.0e6); 893 assert (fabs(costDecrease[i]costIncrease2[i])<1.0e6); 894 assert (sequenceIncrease[i]==sequenceDecrease2[i]); 895 assert (sequenceDecrease[i]==sequenceIncrease2[i]); 896 } 897 // Now delete all rows and see what happens 898 model.deleteRows(model.numberRows(),which); 899 model.primal(); 900 // ranging 901 if (!model.dualRanging(8,which,costIncrease,sequenceIncrease, 902 costDecrease,sequenceDecrease)) { 903 for (i=0;i<8;i++) { 904 printf("%d increase %g %d, decrease %g %d\n", 905 i,costIncrease[i],sequenceIncrease[i], 906 costDecrease[i],sequenceDecrease[i]); 907 } 861 if (m.readMps(fn.c_str(),"mps") == 0) { 862 ClpSimplex model; 863 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 864 m.getObjCoefficients(), 865 m.getRowLower(),m.getRowUpper()); 866 model.primal(); 867 int which[13] = {0,1,2,3,4,5,6,7,8,9,10,11,12}; 868 double costIncrease[13]; 869 int sequenceIncrease[13]; 870 double costDecrease[13]; 871 int sequenceDecrease[13]; 872 // ranging 873 model.dualRanging(13,which,costIncrease,sequenceIncrease, 874 costDecrease,sequenceDecrease); 875 int i; 876 for ( i=0;i<13;i++) 877 printf("%d increase %g %d, decrease %g %d\n", 878 i,costIncrease[i],sequenceIncrease[i], 879 costDecrease[i],sequenceDecrease[i]); 880 assert (fabs(costDecrease[3])<1.0e4); 881 assert (fabs(costIncrease[7]1.0)<1.0e4); 882 model.setOptimizationDirection(1); 883 { 884 int j; 885 double * obj = model.objective(); 886 int n=model.numberColumns(); 887 for (j=0;j<n;j++) 888 obj[j] *= 1.0; 889 } 890 double costIncrease2[13]; 891 int sequenceIncrease2[13]; 892 double costDecrease2[13]; 893 int sequenceDecrease2[13]; 894 // ranging 895 model.dualRanging(13,which,costIncrease2,sequenceIncrease2, 896 costDecrease2,sequenceDecrease2); 897 for (i=0;i<13;i++) { 898 assert (fabs(costIncrease[i]costDecrease2[i])<1.0e6); 899 assert (fabs(costDecrease[i]costIncrease2[i])<1.0e6); 900 assert (sequenceIncrease[i]==sequenceDecrease2[i]); 901 assert (sequenceDecrease[i]==sequenceIncrease2[i]); 902 } 903 // Now delete all rows and see what happens 904 model.deleteRows(model.numberRows(),which); 905 model.primal(); 906 // ranging 907 if (!model.dualRanging(8,which,costIncrease,sequenceIncrease, 908 costDecrease,sequenceDecrease)) { 909 for (i=0;i<8;i++) { 910 printf("%d increase %g %d, decrease %g %d\n", 911 i,costIncrease[i],sequenceIncrease[i], 912 costDecrease[i],sequenceDecrease[i]); 913 } 914 } 915 } else { 916 std::cerr << "Error reading exmip1 from sample data. Skipping test." << std::endl; 908 917 } 909 918 } … … 912 921 CoinMpsIO m; 913 922 std::string fn = dirSample+"exmip1"; 914 m.readMps(fn.c_str(),"mps"); 915 ClpSimplex model; 916 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 917 m.getObjCoefficients(), 918 m.getRowLower(),m.getRowUpper()); 919 model.primal(); 920 int which[13] = {0,1,2,3,4,5,6,7,8,9,10,11,12}; 921 double valueIncrease[13]; 922 int sequenceIncrease[13]; 923 double valueDecrease[13]; 924 int sequenceDecrease[13]; 925 // ranging 926 model.primalRanging(13,which,valueIncrease,sequenceIncrease, 927 valueDecrease,sequenceDecrease); 928 int i; 929 for ( i=0;i<13;i++) 930 printf("%d increase %g %d, decrease %g %d\n", 931 i,valueIncrease[i],sequenceIncrease[i], 932 valueDecrease[i],sequenceDecrease[i]); 933 assert (fabs(valueIncrease[3]0.642857)<1.0e4); 934 assert (fabs(valueIncrease[8]2.95113)<1.0e4); 923 if (m.readMps(fn.c_str(),"mps") == 0) { 924 ClpSimplex model; 925 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 926 m.getObjCoefficients(), 927 m.getRowLower(),m.getRowUpper()); 928 model.primal(); 929 int which[13] = {0,1,2,3,4,5,6,7,8,9,10,11,12}; 930 double valueIncrease[13]; 931 int sequenceIncrease[13]; 932 double valueDecrease[13]; 933 int sequenceDecrease[13]; 934 // ranging 935 model.primalRanging(13,which,valueIncrease,sequenceIncrease, 936 valueDecrease,sequenceDecrease); 937 int i; 938 for ( i=0;i<13;i++) 939 printf("%d increase %g %d, decrease %g %d\n", 940 i,valueIncrease[i],sequenceIncrease[i], 941 valueDecrease[i],sequenceDecrease[i]); 942 assert (fabs(valueIncrease[3]0.642857)<1.0e4); 943 assert (fabs(valueIncrease[8]2.95113)<1.0e4); 944 } else { 945 std::cerr << "Error reading exmip1 from sample data. Skipping test." << std::endl; 946 } 935 947 #if 0 936 948 // out until I find optimization bug … … 1109 1121 // probable cause is that gz not there 1110 1122 fprintf(stderr,"Unable to open finnis.mps in %s\n", dirSample.c_str()); 1111 fprintf(stderr,"Most probable cause is finnis.mps is gzipped i.e. finnis.mps.gz and libz has not been activated\n");1123 fprintf(stderr,"Most probable cause is that sample data is not available, or finnis.mps is gzipped i.e. finnis.mps.gz and libz has not been activated\n"); 1112 1124 fprintf(stderr,"Either gunzip files or edit Makefiles/Makefile.location to get libz\n"); 1113 exit(999);1114 }1115 ClpModel model;1116 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),1117 m.getColUpper(),1118 m.getObjCoefficients(),1119 m.getRowLower(),m.getRowUpper());1120 ClpSimplex solution(model); 1121 1122 solution.scaling(1);1123 solution.setDualBound(1.0e8);1124 //solution.factorization()>maximumPivots(1);1125 //solution.setLogLevel(3);1126 solution.setDualTolerance(1.0e7);1127 // set objective sense,1128 ClpDualRowSteepest steep;1129 solution.setDualRowPivotAlgorithm(steep);1130 solution.setDblParam(ClpObjOffset,m.objectiveOffset());1131 solution.dual();1125 } else { 1126 ClpModel model; 1127 model.loadProblem(*m.getMatrixByCol(),m.getColLower(), 1128 m.getColUpper(), 1129 m.getObjCoefficients(), 1130 m.getRowLower(),m.getRowUpper()); 1131 ClpSimplex solution(model); 1132 1133 solution.scaling(1); 1134 solution.setDualBound(1.0e8); 1135 //solution.factorization()>maximumPivots(1); 1136 //solution.setLogLevel(3); 1137 solution.setDualTolerance(1.0e7); 1138 // set objective sense, 1139 ClpDualRowSteepest steep; 1140 solution.setDualRowPivotAlgorithm(steep); 1141 solution.setDblParam(ClpObjOffset,m.objectiveOffset()); 1142 solution.dual(); 1143 } 1132 1144 } 1133 1145 // test normal solution … … 1135 1147 CoinMpsIO m; 1136 1148 std::string fn = dirSample+"afiro"; 1137 m.readMps(fn.c_str(),"mps"); 1138 ClpSimplex solution; 1139 ClpModel model; 1140 // do twice  without and with scaling 1141 int iPass; 1142 for (iPass=0;iPass<2;iPass++) { 1143 // explicit row objective for testing 1144 int nr = m.getNumRows(); 1145 double * rowObj = new double[nr]; 1146 CoinFillN(rowObj,nr,0.0); 1147 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1148 m.getObjCoefficients(), 1149 m.getRowLower(),m.getRowUpper(),rowObj); 1150 delete [] rowObj; 1151 solution = ClpSimplex(model); 1152 if (iPass) { 1153 solution.scaling(); 1154 } 1155 solution.dual(); 1156 solution.dual(); 1157 // test optimal 1158 assert (solution.status()==0); 1159 int numberColumns = solution.numberColumns(); 1160 int numberRows = solution.numberRows(); 1161 CoinPackedVector colsol(numberColumns,solution.primalColumnSolution()); 1162 double * objective = solution.objective(); 1163 #ifndef NDEBUG 1164 double objValue = colsol.dotProduct(objective); 1165 #endif 1166 CoinRelFltEq eq(1.0e8); 1167 assert(eq(objValue,4.6475314286e+02)); 1168 solution.dual(); 1169 assert(eq(solution.objectiveValue(),4.6475314286e+02)); 1170 double * lower = solution.columnLower(); 1171 double * upper = solution.columnUpper(); 1172 double * sol = solution.primalColumnSolution(); 1173 double * result = new double[numberColumns]; 1174 CoinFillN ( result, numberColumns,0.0); 1175 solution.matrix()>transposeTimes(solution.dualRowSolution(), result); 1176 int iRow , iColumn; 1177 // see if feasible and dual feasible 1178 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1179 double value = sol[iColumn]; 1180 assert(value<upper[iColumn]+1.0e8); 1181 assert(value>lower[iColumn]1.0e8); 1182 value = objective[iColumn]result[iColumn]; 1183 assert (value>1.0e5); 1184 if (sol[iColumn]>1.0e5) 1185 assert (value<1.0e5); 1186 } 1187 delete [] result; 1188 result = new double[numberRows]; 1189 CoinFillN ( result, numberRows,0.0); 1190 solution.matrix()>times(colsol, result); 1191 lower = solution.rowLower(); 1192 upper = solution.rowUpper(); 1193 sol = solution.primalRowSolution(); 1194 #ifndef NDEBUG 1195 for (iRow=0;iRow<numberRows;iRow++) { 1196 double value = result[iRow]; 1197 assert(eq(value,sol[iRow])); 1198 assert(value<upper[iRow]+1.0e8); 1199 assert(value>lower[iRow]1.0e8); 1200 } 1201 #endif 1202 delete [] result; 1203 // test row objective 1204 double * rowObjective = solution.rowObjective(); 1205 CoinDisjointCopyN(solution.dualRowSolution(),numberRows,rowObjective); 1206 CoinDisjointCopyN(solution.dualColumnSolution(),numberColumns,objective); 1207 // this sets up all slack basis 1208 solution.createStatus(); 1209 solution.dual(); 1210 CoinFillN(rowObjective,numberRows,0.0); 1211 CoinDisjointCopyN(m.getObjCoefficients(),numberColumns,objective); 1212 solution.dual(); 1149 if (m.readMps(fn.c_str(),"mps") == 0) { 1150 ClpSimplex solution; 1151 ClpModel model; 1152 // do twice  without and with scaling 1153 int iPass; 1154 for (iPass=0;iPass<2;iPass++) { 1155 // explicit row objective for testing 1156 int nr = m.getNumRows(); 1157 double * rowObj = new double[nr]; 1158 CoinFillN(rowObj,nr,0.0); 1159 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1160 m.getObjCoefficients(), 1161 m.getRowLower(),m.getRowUpper(),rowObj); 1162 delete [] rowObj; 1163 solution = ClpSimplex(model); 1164 if (iPass) { 1165 solution.scaling(); 1166 } 1167 solution.dual(); 1168 solution.dual(); 1169 // test optimal 1170 assert (solution.status()==0); 1171 int numberColumns = solution.numberColumns(); 1172 int numberRows = solution.numberRows(); 1173 CoinPackedVector colsol(numberColumns,solution.primalColumnSolution()); 1174 double * objective = solution.objective(); 1175 #ifndef NDEBUG 1176 double objValue = colsol.dotProduct(objective); 1177 #endif 1178 CoinRelFltEq eq(1.0e8); 1179 assert(eq(objValue,4.6475314286e+02)); 1180 solution.dual(); 1181 assert(eq(solution.objectiveValue(),4.6475314286e+02)); 1182 double * lower = solution.columnLower(); 1183 double * upper = solution.columnUpper(); 1184 double * sol = solution.primalColumnSolution(); 1185 double * result = new double[numberColumns]; 1186 CoinFillN ( result, numberColumns,0.0); 1187 solution.matrix()>transposeTimes(solution.dualRowSolution(), result); 1188 int iRow , iColumn; 1189 // see if feasible and dual feasible 1190 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1191 double value = sol[iColumn]; 1192 assert(value<upper[iColumn]+1.0e8); 1193 assert(value>lower[iColumn]1.0e8); 1194 value = objective[iColumn]result[iColumn]; 1195 assert (value>1.0e5); 1196 if (sol[iColumn]>1.0e5) 1197 assert (value<1.0e5); 1198 } 1199 delete [] result; 1200 result = new double[numberRows]; 1201 CoinFillN ( result, numberRows,0.0); 1202 solution.matrix()>times(colsol, result); 1203 lower = solution.rowLower(); 1204 upper = solution.rowUpper(); 1205 sol = solution.primalRowSolution(); 1206 #ifndef NDEBUG 1207 for (iRow=0;iRow<numberRows;iRow++) { 1208 double value = result[iRow]; 1209 assert(eq(value,sol[iRow])); 1210 assert(value<upper[iRow]+1.0e8); 1211 assert(value>lower[iRow]1.0e8); 1212 } 1213 #endif 1214 delete [] result; 1215 // test row objective 1216 double * rowObjective = solution.rowObjective(); 1217 CoinDisjointCopyN(solution.dualRowSolution(),numberRows,rowObjective); 1218 CoinDisjointCopyN(solution.dualColumnSolution(),numberColumns,objective); 1219 // this sets up all slack basis 1220 solution.createStatus(); 1221 solution.dual(); 1222 CoinFillN(rowObjective,numberRows,0.0); 1223 CoinDisjointCopyN(m.getObjCoefficients(),numberColumns,objective); 1224 solution.dual(); 1225 } 1226 } else { 1227 std::cerr << "Error reading afiro from sample data. Skipping test." << std::endl; 1213 1228 } 1214 1229 } … … 1217 1232 CoinMpsIO m; 1218 1233 std::string fn = dirSample+"brandy"; 1219 m.readMps(fn.c_str(),"mps"); 1220 ClpSimplex solution; 1221 // do twice  without and with scaling 1222 int iPass; 1223 for (iPass=0;iPass<2;iPass++) { 1224 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1225 m.getObjCoefficients(), 1226 m.getRowLower(),m.getRowUpper()); 1227 if (iPass) 1228 solution.scaling(); 1229 solution.setOptimizationDirection(1); 1230 // test unbounded and ray 1231 #ifdef DUAL 1232 solution.setDualBound(100.0); 1233 solution.dual(); 1234 #else 1235 solution.primal(); 1236 #endif 1237 assert (solution.status()==2); 1238 int numberColumns = solution.numberColumns(); 1239 int numberRows = solution.numberRows(); 1240 double * lower = solution.columnLower(); 1241 double * upper = solution.columnUpper(); 1242 double * sol = solution.primalColumnSolution(); 1243 double * ray = solution.unboundedRay(); 1244 double * objective = solution.objective(); 1245 double objChange=0.0; 1246 int iRow , iColumn; 1247 // make sure feasible and columns form ray 1248 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1249 double value = sol[iColumn]; 1250 assert(value<upper[iColumn]+1.0e8); 1251 assert(value>lower[iColumn]1.0e8); 1252 value = ray[iColumn]; 1253 if (value>0.0) 1254 assert(upper[iColumn]>1.0e30); 1255 else if (value<0.0) 1256 assert(lower[iColumn]<1.0e30); 1257 objChange += value*objective[iColumn]; 1258 } 1259 // make sure increasing objective 1260 assert(objChange>0.0); 1261 double * result = new double[numberRows]; 1262 CoinFillN ( result, numberRows,0.0); 1263 solution.matrix()>times(sol, result); 1264 lower = solution.rowLower(); 1265 upper = solution.rowUpper(); 1266 sol = solution.primalRowSolution(); 1267 #ifndef NDEBUG 1268 for (iRow=0;iRow<numberRows;iRow++) { 1269 double value = result[iRow]; 1270 assert(eq(value,sol[iRow])); 1271 assert(value<upper[iRow]+2.0e8); 1272 assert(value>lower[iRow]2.0e8); 1273 } 1274 #endif 1275 CoinFillN ( result, numberRows,0.0); 1276 solution.matrix()>times(ray, result); 1277 // there may be small differences (especially if scaled) 1278 for (iRow=0;iRow<numberRows;iRow++) { 1279 double value = result[iRow]; 1280 if (value>1.0e8) 1281 assert(upper[iRow]>1.0e30); 1282 else if (value<1.0e8) 1283 assert(lower[iRow]<1.0e30); 1284 } 1285 delete [] result; 1286 delete [] ray; 1234 if (m.readMps(fn.c_str(),"mps") == 0) { 1235 ClpSimplex solution; 1236 // do twice  without and with scaling 1237 int iPass; 1238 for (iPass=0;iPass<2;iPass++) { 1239 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1240 m.getObjCoefficients(), 1241 m.getRowLower(),m.getRowUpper()); 1242 if (iPass) 1243 solution.scaling(); 1244 solution.setOptimizationDirection(1); 1245 // test unbounded and ray 1246 #ifdef DUAL 1247 solution.setDualBound(100.0); 1248 solution.dual(); 1249 #else 1250 solution.primal(); 1251 #endif 1252 assert (solution.status()==2); 1253 int numberColumns = solution.numberColumns(); 1254 int numberRows = solution.numberRows(); 1255 double * lower = solution.columnLower(); 1256 double * upper = solution.columnUpper(); 1257 double * sol = solution.primalColumnSolution(); 1258 double * ray = solution.unboundedRay(); 1259 double * objective = solution.objective(); 1260 double objChange=0.0; 1261 int iRow , iColumn; 1262 // make sure feasible and columns form ray 1263 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1264 double value = sol[iColumn]; 1265 assert(value<upper[iColumn]+1.0e8); 1266 assert(value>lower[iColumn]1.0e8); 1267 value = ray[iColumn]; 1268 if (value>0.0) 1269 assert(upper[iColumn]>1.0e30); 1270 else if (value<0.0) 1271 assert(lower[iColumn]<1.0e30); 1272 objChange += value*objective[iColumn]; 1273 } 1274 // make sure increasing objective 1275 assert(objChange>0.0); 1276 double * result = new double[numberRows]; 1277 CoinFillN ( result, numberRows,0.0); 1278 solution.matrix()>times(sol, result); 1279 lower = solution.rowLower(); 1280 upper = solution.rowUpper(); 1281 sol = solution.primalRowSolution(); 1282 #ifndef NDEBUG 1283 for (iRow=0;iRow<numberRows;iRow++) { 1284 double value = result[iRow]; 1285 assert(eq(value,sol[iRow])); 1286 assert(value<upper[iRow]+2.0e8); 1287 assert(value>lower[iRow]2.0e8); 1288 } 1289 #endif 1290 CoinFillN ( result, numberRows,0.0); 1291 solution.matrix()>times(ray, result); 1292 // there may be small differences (especially if scaled) 1293 for (iRow=0;iRow<numberRows;iRow++) { 1294 double value = result[iRow]; 1295 if (value>1.0e8) 1296 assert(upper[iRow]>1.0e30); 1297 else if (value<1.0e8) 1298 assert(lower[iRow]<1.0e30); 1299 } 1300 delete [] result; 1301 delete [] ray; 1302 } 1303 } else { 1304 std::cerr << "Error reading brandy from sample data. Skipping test." << std::endl; 1287 1305 } 1288 1306 } … … 1291 1309 CoinMpsIO m; 1292 1310 std::string fn = dirSample+"brandy"; 1293 m.readMps(fn.c_str(),"mps"); 1294 ClpSimplex solution; 1295 // do twice  without and with scaling 1296 int iPass; 1297 for (iPass=0;iPass<2;iPass++) { 1298 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1299 m.getObjCoefficients(), 1300 m.getRowLower(),m.getRowUpper()); 1301 if (iPass) 1302 solution.scaling(); 1303 // test infeasible and ray 1304 solution.columnUpper()[0]=0.0; 1305 #ifdef DUAL 1306 solution.setDualBound(100.0); 1307 solution.dual(); 1308 #else 1309 solution.primal(); 1310 #endif 1311 assert (solution.status()==1); 1312 int numberColumns = solution.numberColumns(); 1313 int numberRows = solution.numberRows(); 1314 double * lower = solution.rowLower(); 1315 double * upper = solution.rowUpper(); 1316 double * ray = solution.infeasibilityRay(); 1317 assert(ray); 1318 // construct proof of infeasibility 1319 int iRow , iColumn; 1320 double lo=0.0,up=0.0; 1321 int nl=0,nu=0; 1322 for (iRow=0;iRow<numberRows;iRow++) { 1323 if (lower[iRow]>1.0e20) { 1324 lo += ray[iRow]*lower[iRow]; 1325 } else { 1326 if (ray[iRow]>1.0e8) 1327 nl++; 1328 } 1329 if (upper[iRow]<1.0e20) { 1330 up += ray[iRow]*upper[iRow]; 1331 } else { 1332 if (ray[iRow]>1.0e8) 1333 nu++; 1334 } 1335 } 1336 if (nl) 1337 lo=1.0e100; 1338 if (nu) 1339 up=1.0e100; 1340 double * result = new double[numberColumns]; 1341 double lo2=0.0,up2=0.0; 1342 CoinFillN ( result, numberColumns,0.0); 1343 solution.matrix()>transposeTimes(ray, result); 1344 lower = solution.columnLower(); 1345 upper = solution.columnUpper(); 1346 nl=nu=0; 1347 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1348 if (result[iColumn]>1.0e8) { 1349 if (lower[iColumn]>1.0e20) 1350 lo2 += result[iColumn]*lower[iColumn]; 1351 else 1352 nl++; 1353 if (upper[iColumn]<1.0e20) 1354 up2 += result[iColumn]*upper[iColumn]; 1355 else 1356 nu++; 1357 } else if (result[iColumn]<1.0e8) { 1358 if (lower[iColumn]>1.0e20) 1359 up2 += result[iColumn]*lower[iColumn]; 1360 else 1361 nu++; 1362 if (upper[iColumn]<1.0e20) 1363 lo2 += result[iColumn]*upper[iColumn]; 1364 else 1365 nl++; 1366 } 1367 } 1368 if (nl) 1369 lo2=1.0e100; 1370 if (nu) 1371 up2=1.0e100; 1372 // make sure inconsistency 1373 assert(lo2>upup2<lo); 1374 delete [] result; 1375 delete [] ray; 1311 if (m.readMps(fn.c_str(),"mps") == 0) { 1312 ClpSimplex solution; 1313 // do twice  without and with scaling 1314 int iPass; 1315 for (iPass=0;iPass<2;iPass++) { 1316 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1317 m.getObjCoefficients(), 1318 m.getRowLower(),m.getRowUpper()); 1319 if (iPass) 1320 solution.scaling(); 1321 // test infeasible and ray 1322 solution.columnUpper()[0]=0.0; 1323 #ifdef DUAL 1324 solution.setDualBound(100.0); 1325 solution.dual(); 1326 #else 1327 solution.primal(); 1328 #endif 1329 assert (solution.status()==1); 1330 int numberColumns = solution.numberColumns(); 1331 int numberRows = solution.numberRows(); 1332 double * lower = solution.rowLower(); 1333 double * upper = solution.rowUpper(); 1334 double * ray = solution.infeasibilityRay(); 1335 assert(ray); 1336 // construct proof of infeasibility 1337 int iRow , iColumn; 1338 double lo=0.0,up=0.0; 1339 int nl=0,nu=0; 1340 for (iRow=0;iRow<numberRows;iRow++) { 1341 if (lower[iRow]>1.0e20) { 1342 lo += ray[iRow]*lower[iRow]; 1343 } else { 1344 if (ray[iRow]>1.0e8) 1345 nl++; 1346 } 1347 if (upper[iRow]<1.0e20) { 1348 up += ray[iRow]*upper[iRow]; 1349 } else { 1350 if (ray[iRow]>1.0e8) 1351 nu++; 1352 } 1353 } 1354 if (nl) 1355 lo=1.0e100; 1356 if (nu) 1357 up=1.0e100; 1358 double * result = new double[numberColumns]; 1359 double lo2=0.0,up2=0.0; 1360 CoinFillN ( result, numberColumns,0.0); 1361 solution.matrix()>transposeTimes(ray, result); 1362 lower = solution.columnLower(); 1363 upper = solution.columnUpper(); 1364 nl=nu=0; 1365 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1366 if (result[iColumn]>1.0e8) { 1367 if (lower[iColumn]>1.0e20) 1368 lo2 += result[iColumn]*lower[iColumn]; 1369 else 1370 nl++; 1371 if (upper[iColumn]<1.0e20) 1372 up2 += result[iColumn]*upper[iColumn]; 1373 else 1374 nu++; 1375 } else if (result[iColumn]<1.0e8) { 1376 if (lower[iColumn]>1.0e20) 1377 up2 += result[iColumn]*lower[iColumn]; 1378 else 1379 nu++; 1380 if (upper[iColumn]<1.0e20) 1381 lo2 += result[iColumn]*upper[iColumn]; 1382 else 1383 nl++; 1384 } 1385 } 1386 if (nl) 1387 lo2=1.0e100; 1388 if (nu) 1389 up2=1.0e100; 1390 // make sure inconsistency 1391 assert(lo2>upup2<lo); 1392 delete [] result; 1393 delete [] ray; 1394 } 1395 } else { 1396 std::cerr << "Error reading brandy from sample data. Skipping test." << std::endl; 1376 1397 } 1377 1398 } … … 1380 1401 CoinMpsIO m; 1381 1402 std::string fn = dirSample+"brandy"; 1382 m.readMps(fn.c_str(),"mps"); 1383 ClpSimplex solution; 1384 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1385 m.getObjCoefficients(), 1386 m.getRowLower(),m.getRowUpper()); 1387 solution.dual(); 1388 CoinRelFltEq eq(1.0e8); 1389 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1390 1391 int numberColumns = solution.numberColumns(); 1392 int numberRows = solution.numberRows(); 1393 double * saveObj = new double [numberColumns]; 1394 double * saveLower = new double[numberRows+numberColumns]; 1395 double * saveUpper = new double[numberRows+numberColumns]; 1396 int * which = new int [numberRows+numberColumns]; 1397 1398 int numberElements = m.getMatrixByCol()>getNumElements(); 1399 int * starts = new int[numberRows+numberColumns]; 1400 int * index = new int[numberElements]; 1401 double * element = new double[numberElements]; 1402 1403 const CoinBigIndex * startM; 1404 const int * lengthM; 1405 const int * indexM; 1406 const double * elementM; 1407 1408 int n,nel; 1409 1410 // delete non basic columns 1411 n=0; 1412 nel=0; 1413 int iRow , iColumn; 1414 const double * lower = m.getColLower(); 1415 const double * upper = m.getColUpper(); 1416 const double * objective = m.getObjCoefficients(); 1417 startM = m.getMatrixByCol()>getVectorStarts(); 1418 lengthM = m.getMatrixByCol()>getVectorLengths(); 1419 indexM = m.getMatrixByCol()>getIndices(); 1420 elementM = m.getMatrixByCol()>getElements(); 1421 starts[0]=0; 1422 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1423 if (solution.getColumnStatus(iColumn)!=ClpSimplex::basic) { 1403 if (m.readMps(fn.c_str(),"mps") == 0) { 1404 ClpSimplex solution; 1405 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1406 m.getObjCoefficients(), 1407 m.getRowLower(),m.getRowUpper()); 1408 solution.dual(); 1409 CoinRelFltEq eq(1.0e8); 1410 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1411 1412 int numberColumns = solution.numberColumns(); 1413 int numberRows = solution.numberRows(); 1414 double * saveObj = new double [numberColumns]; 1415 double * saveLower = new double[numberRows+numberColumns]; 1416 double * saveUpper = new double[numberRows+numberColumns]; 1417 int * which = new int [numberRows+numberColumns]; 1418 1419 int numberElements = m.getMatrixByCol()>getNumElements(); 1420 int * starts = new int[numberRows+numberColumns]; 1421 int * index = new int[numberElements]; 1422 double * element = new double[numberElements]; 1423 1424 const CoinBigIndex * startM; 1425 const int * lengthM; 1426 const int * indexM; 1427 const double * elementM; 1428 1429 int n,nel; 1430 1431 // delete non basic columns 1432 n=0; 1433 nel=0; 1434 int iRow , iColumn; 1435 const double * lower = m.getColLower(); 1436 const double * upper = m.getColUpper(); 1437 const double * objective = m.getObjCoefficients(); 1438 startM = m.getMatrixByCol()>getVectorStarts(); 1439 lengthM = m.getMatrixByCol()>getVectorLengths(); 1440 indexM = m.getMatrixByCol()>getIndices(); 1441 elementM = m.getMatrixByCol()>getElements(); 1442 starts[0]=0; 1443 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1444 if (solution.getColumnStatus(iColumn)!=ClpSimplex::basic) { 1445 saveObj[n]=objective[iColumn]; 1446 saveLower[n]=lower[iColumn]; 1447 saveUpper[n]=upper[iColumn]; 1448 int j; 1449 for (j=startM[iColumn];j<startM[iColumn]+lengthM[iColumn];j++) { 1450 index[nel]=indexM[j]; 1451 element[nel++]=elementM[j]; 1452 } 1453 which[n++]=iColumn; 1454 starts[n]=nel; 1455 } 1456 } 1457 solution.deleteColumns(n,which); 1458 solution.dual(); 1459 // Put back 1460 solution.addColumns(n,saveLower,saveUpper,saveObj, 1461 starts,index,element); 1462 solution.dual(); 1463 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1464 // Delete all columns and add back 1465 n=0; 1466 nel=0; 1467 starts[0]=0; 1468 lower = m.getColLower(); 1469 upper = m.getColUpper(); 1470 objective = m.getObjCoefficients(); 1471 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1424 1472 saveObj[n]=objective[iColumn]; 1425 1473 saveLower[n]=lower[iColumn]; … … 1433 1481 starts[n]=nel; 1434 1482 } 1435 } 1436 solution.deleteColumns(n,which); 1437 solution.dual(); 1438 // Put back 1439 solution.addColumns(n,saveLower,saveUpper,saveObj, 1440 starts,index,element); 1441 solution.dual(); 1442 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1443 // Delete all columns and add back 1444 n=0; 1445 nel=0; 1446 starts[0]=0; 1447 lower = m.getColLower(); 1448 upper = m.getColUpper(); 1449 objective = m.getObjCoefficients(); 1450 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1451 saveObj[n]=objective[iColumn]; 1452 saveLower[n]=lower[iColumn]; 1453 saveUpper[n]=upper[iColumn]; 1454 int j; 1455 for (j=startM[iColumn];j<startM[iColumn]+lengthM[iColumn];j++) { 1456 index[nel]=indexM[j]; 1457 element[nel++]=elementM[j]; 1458 } 1459 which[n++]=iColumn; 1460 starts[n]=nel; 1461 } 1462 solution.deleteColumns(n,which); 1463 solution.dual(); 1464 // Put back 1465 solution.addColumns(n,saveLower,saveUpper,saveObj, 1466 starts,index,element); 1467 solution.dual(); 1468 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1469 1470 // reload with original 1471 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1472 m.getObjCoefficients(), 1473 m.getRowLower(),m.getRowUpper()); 1474 // delete half rows 1475 n=0; 1476 nel=0; 1477 lower = m.getRowLower(); 1478 upper = m.getRowUpper(); 1479 startM = m.getMatrixByRow()>getVectorStarts(); 1480 lengthM = m.getMatrixByRow()>getVectorLengths(); 1481 indexM = m.getMatrixByRow()>getIndices(); 1482 elementM = m.getMatrixByRow()>getElements(); 1483 starts[0]=0; 1484 for (iRow=0;iRow<numberRows;iRow++) { 1485 if ((iRow&1)==0) { 1483 solution.deleteColumns(n,which); 1484 solution.dual(); 1485 // Put back 1486 solution.addColumns(n,saveLower,saveUpper,saveObj, 1487 starts,index,element); 1488 solution.dual(); 1489 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1490 1491 // reload with original 1492 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1493 m.getObjCoefficients(), 1494 m.getRowLower(),m.getRowUpper()); 1495 // delete half rows 1496 n=0; 1497 nel=0; 1498 lower = m.getRowLower(); 1499 upper = m.getRowUpper(); 1500 startM = m.getMatrixByRow()>getVectorStarts(); 1501 lengthM = m.getMatrixByRow()>getVectorLengths(); 1502 indexM = m.getMatrixByRow()>getIndices(); 1503 elementM = m.getMatrixByRow()>getElements(); 1504 starts[0]=0; 1505 for (iRow=0;iRow<numberRows;iRow++) { 1506 if ((iRow&1)==0) { 1507 saveLower[n]=lower[iRow]; 1508 saveUpper[n]=upper[iRow]; 1509 int j; 1510 for (j=startM[iRow];j<startM[iRow]+lengthM[iRow];j++) { 1511 index[nel]=indexM[j]; 1512 element[nel++]=elementM[j]; 1513 } 1514 which[n++]=iRow; 1515 starts[n]=nel; 1516 } 1517 } 1518 solution.deleteRows(n,which); 1519 solution.dual(); 1520 // Put back 1521 solution.addRows(n,saveLower,saveUpper, 1522 starts,index,element); 1523 solution.dual(); 1524 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1525 solution.writeMps("yy.mps"); 1526 // Delete all rows 1527 n=0; 1528 nel=0; 1529 lower = m.getRowLower(); 1530 upper = m.getRowUpper(); 1531 starts[0]=0; 1532 for (iRow=0;iRow<numberRows;iRow++) { 1486 1533 saveLower[n]=lower[iRow]; 1487 1534 saveUpper[n]=upper[iRow]; … … 1494 1541 starts[n]=nel; 1495 1542 } 1496 } 1497 solution.deleteRows(n,which); 1498 solution.dual(); 1499 // Put back 1500 solution.addRows(n,saveLower,saveUpper, 1501 starts,index,element); 1502 solution.dual(); 1503 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1504 solution.writeMps("yy.mps"); 1505 // Delete all rows 1506 n=0; 1507 nel=0; 1508 lower = m.getRowLower(); 1509 upper = m.getRowUpper(); 1510 starts[0]=0; 1511 for (iRow=0;iRow<numberRows;iRow++) { 1512 saveLower[n]=lower[iRow]; 1513 saveUpper[n]=upper[iRow]; 1514 int j; 1515 for (j=startM[iRow];j<startM[iRow]+lengthM[iRow];j++) { 1516 index[nel]=indexM[j]; 1517 element[nel++]=elementM[j]; 1518 } 1519 which[n++]=iRow; 1520 starts[n]=nel; 1521 } 1522 solution.deleteRows(n,which); 1523 solution.dual(); 1524 // Put back 1525 solution.addRows(n,saveLower,saveUpper, 1526 starts,index,element); 1527 solution.dual(); 1528 solution.writeMps("xx.mps"); 1529 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1530 // Zero out status array to give some interest 1531 memset(solution.statusArray()+numberColumns,0,numberRows); 1532 solution.primal(1); 1533 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1534 // Delete all columns and rows 1535 n=0; 1536 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1537 which[n++]=iColumn; 1538 starts[n]=nel; 1539 } 1540 solution.deleteColumns(n,which); 1541 n=0; 1542 for (iRow=0;iRow<numberRows;iRow++) { 1543 which[n++]=iRow; 1544 starts[n]=nel; 1545 } 1546 solution.deleteRows(n,which); 1547 1548 delete [] saveObj; 1549 delete [] saveLower; 1550 delete [] saveUpper; 1551 delete [] which; 1552 delete [] starts; 1553 delete [] index; 1554 delete [] element; 1543 solution.deleteRows(n,which); 1544 solution.dual(); 1545 // Put back 1546 solution.addRows(n,saveLower,saveUpper, 1547 starts,index,element); 1548 solution.dual(); 1549 solution.writeMps("xx.mps"); 1550 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1551 // Zero out status array to give some interest 1552 memset(solution.statusArray()+numberColumns,0,numberRows); 1553 solution.primal(1); 1554 assert(eq(solution.objectiveValue(),1.5185098965e+03)); 1555 // Delete all columns and rows 1556 n=0; 1557 for (iColumn=0;iColumn<numberColumns;iColumn++) { 1558 which[n++]=iColumn; 1559 starts[n]=nel; 1560 } 1561 solution.deleteColumns(n,which); 1562 n=0; 1563 for (iRow=0;iRow<numberRows;iRow++) { 1564 which[n++]=iRow; 1565 starts[n]=nel; 1566 } 1567 solution.deleteRows(n,which); 1568 1569 delete [] saveObj; 1570 delete [] saveLower; 1571 delete [] saveUpper; 1572 delete [] which; 1573 delete [] starts; 1574 delete [] index; 1575 delete [] element; 1576 } else { 1577 std::cerr << "Error reading brandy from sample data. Skipping test." << std::endl; 1578 } 1555 1579 } 1556 1580 #if 1 … … 1559 1583 CoinMpsIO m; 1560 1584 std::string fn = dirSample+"exmip1"; 1561 m.readMps(fn.c_str(),"mps"); 1562 ClpInterior solution; 1563 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1564 m.getObjCoefficients(), 1565 m.getRowLower(),m.getRowUpper()); 1566 solution.primalDual(); 1585 if (m.readMps(fn.c_str(),"mps") == 0) { 1586 ClpInterior solution; 1587 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1588 m.getObjCoefficients(), 1589 m.getRowLower(),m.getRowUpper()); 1590 solution.primalDual(); 1591 } else { 1592 std::cerr << "Error reading exmip1 from sample data. Skipping test." << std::endl; 1593 } 1567 1594 } 1568 1595 #endif 1569 1596 // test network 1570 1597 #define QUADRATIC 1571 if (1) { 1598 if (1) { 1572 1599 std::string fn = dirSample+"input.130"; 1573 1600 int numberColumns; … … 1748 1775 CoinMpsIO m; 1749 1776 std::string fn = dirSample+"exmip1"; 1750 m.readMps(fn.c_str(),"mps"); 1751 ClpSimplex solution; 1752 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1753 m.getObjCoefficients(), 1754 m.getRowLower(),m.getRowUpper()); 1755 //solution.dual(); 1756 // get quadratic part 1757 int numberColumns=solution.numberColumns(); 1758 int * start=new int [numberColumns+1]; 1759 int * column = new int[numberColumns]; 1760 double * element = new double[numberColumns]; 1761 int i; 1762 start[0]=0; 1763 int n=0; 1764 int kk=numberColumns1; 1765 int kk2=numberColumns1; 1766 for (i=0;i<numberColumns;i++) { 1767 if (i>=kk) { 1768 column[n]=i; 1769 if (i>=kk2) 1770 element[n]=1.0e1; 1771 else 1772 element[n]=0.0; 1773 n++; 1774 } 1775 start[i+1]=n; 1776 } 1777 // Load up objective 1778 solution.loadQuadraticObjective(numberColumns,start,column,element); 1779 delete [] start; 1780 delete [] column; 1781 delete [] element; 1782 //solution.quadraticSLP(50,1.0e4); 1783 CoinRelFltEq eq(1.0e4); 1784 //assert(eq(objValue,820.0)); 1785 //solution.setLogLevel(63); 1786 solution.primal(); 1787 printSol(solution); 1788 //assert(eq(objValue,3.2368421)); 1789 //exit(77); 1777 if (m.readMps(fn.c_str(),"mps") == 0) { 1778 ClpSimplex solution; 1779 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1780 m.getObjCoefficients(), 1781 m.getRowLower(),m.getRowUpper()); 1782 //solution.dual(); 1783 // get quadratic part 1784 int numberColumns=solution.numberColumns(); 1785 int * start=new int [numberColumns+1]; 1786 int * column = new int[numberColumns]; 1787 double * element = new double[numberColumns]; 1788 int i; 1789 start[0]=0; 1790 int n=0; 1791 int kk=numberColumns1; 1792 int kk2=numberColumns1; 1793 for (i=0;i<numberColumns;i++) { 1794 if (i>=kk) { 1795 column[n]=i; 1796 if (i>=kk2) 1797 element[n]=1.0e1; 1798 else 1799 element[n]=0.0; 1800 n++; 1801 } 1802 start[i+1]=n; 1803 } 1804 // Load up objective 1805 solution.loadQuadraticObjective(numberColumns,start,column,element); 1806 delete [] start; 1807 delete [] column; 1808 delete [] element; 1809 //solution.quadraticSLP(50,1.0e4); 1810 CoinRelFltEq eq(1.0e4); 1811 //assert(eq(objValue,820.0)); 1812 //solution.setLogLevel(63); 1813 solution.primal(); 1814 printSol(solution); 1815 //assert(eq(objValue,3.2368421)); 1816 //exit(77); 1817 } else { 1818 std::cerr << "Error reading exmip1 from sample data. Skipping test." << std::endl; 1819 } 1790 1820 } 1791 1821 // Test quadratic … … 1794 1824 std::string fn = dirSample+"share2qp"; 1795 1825 //fn = "share2qpb"; 1796 m.readMps(fn.c_str(),"mps"); 1797 ClpSimplex model; 1798 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1799 m.getObjCoefficients(), 1800 m.getRowLower(),m.getRowUpper()); 1801 model.dual(); 1802 // get quadratic part 1803 int * start=NULL; 1804 int * column = NULL; 1805 double * element = NULL; 1806 m.readQuadraticMps(NULL,start,column,element,2); 1807 int column2[200]; 1808 double element2[200]; 1809 int start2[80]; 1810 int j; 1811 start2[0]=0; 1812 int nel=0; 1813 bool good=false; 1814 for (j=0;j<79;j++) { 1815 if (start[j]==start[j+1]) { 1816 column2[nel]=j; 1817 element2[nel]=0.0; 1818 nel++; 1819 } else { 1820 int i; 1821 for (i=start[j];i<start[j+1];i++) { 1822 column2[nel]=column[i]; 1823 element2[nel++]=element[i]; 1824 } 1825 } 1826 start2[j+1]=nel; 1827 } 1828 // Load up objective 1829 if (good) 1830 model.loadQuadraticObjective(model.numberColumns(),start2,column2,element2); 1831 else 1832 model.loadQuadraticObjective(model.numberColumns(),start,column,element); 1833 delete [] start; 1834 delete [] column; 1835 delete [] element; 1836 int numberColumns=model.numberColumns(); 1837 model.scaling(0); 1838 #if 0 1839 model.nonlinearSLP(50,1.0e4); 1840 #else 1841 // Get feasible 1842 ClpObjective * saveObjective = model.objectiveAsObject()>clone(); 1843 ClpLinearObjective zeroObjective(NULL,numberColumns); 1844 model.setObjective(&zeroObjective); 1845 model.dual(); 1846 model.setObjective(saveObjective); 1847 delete saveObjective; 1848 #endif 1849 //model.setLogLevel(63); 1850 //exit(77); 1851 model.setFactorizationFrequency(10); 1852 model.primal(); 1853 printSol(model); 1854 #ifndef NDEBUG 1855 double objValue = model.getObjValue(); 1856 #endif 1857 CoinRelFltEq eq(1.0e4); 1858 assert(eq(objValue,400.92)); 1859 // and again for barrier 1860 model.barrier(false); 1861 //printSol(model); 1862 model.allSlackBasis(); 1863 model.primal(); 1864 //printSol(model); 1826 if (m.readMps(fn.c_str(),"mps") == 0) { 1827 ClpSimplex model; 1828 model.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1829 m.getObjCoefficients(), 1830 m.getRowLower(),m.getRowUpper()); 1831 model.dual(); 1832 // get quadratic part 1833 int * start=NULL; 1834 int * column = NULL; 1835 double * element = NULL; 1836 m.readQuadraticMps(NULL,start,column,element,2); 1837 int column2[200]; 1838 double element2[200]; 1839 int start2[80]; 1840 int j; 1841 start2[0]=0; 1842 int nel=0; 1843 bool good=false; 1844 for (j=0;j<79;j++) { 1845 if (start[j]==start[j+1]) { 1846 column2[nel]=j; 1847 element2[nel]=0.0; 1848 nel++; 1849 } else { 1850 int i; 1851 for (i=start[j];i<start[j+1];i++) { 1852 column2[nel]=column[i]; 1853 element2[nel++]=element[i]; 1854 } 1855 } 1856 start2[j+1]=nel; 1857 } 1858 // Load up objective 1859 if (good) 1860 model.loadQuadraticObjective(model.numberColumns(),start2,column2,element2); 1861 else 1862 model.loadQuadraticObjective(model.numberColumns(),start,column,element); 1863 delete [] start; 1864 delete [] column; 1865 delete [] element; 1866 int numberColumns=model.numberColumns(); 1867 model.scaling(0); 1868 #if 0 1869 model.nonlinearSLP(50,1.0e4); 1870 #else 1871 // Get feasible 1872 ClpObjective * saveObjective = model.objectiveAsObject()>clone(); 1873 ClpLinearObjective zeroObjective(NULL,numberColumns); 1874 model.setObjective(&zeroObjective); 1875 model.dual(); 1876 model.setObjective(saveObjective); 1877 delete saveObjective; 1878 #endif 1879 //model.setLogLevel(63); 1880 //exit(77); 1881 model.setFactorizationFrequency(10); 1882 model.primal(); 1883 printSol(model); 1884 #ifndef NDEBUG 1885 double objValue = model.getObjValue(); 1886 #endif 1887 CoinRelFltEq eq(1.0e4); 1888 assert(eq(objValue,400.92)); 1889 // and again for barrier 1890 model.barrier(false); 1891 //printSol(model); 1892 model.allSlackBasis(); 1893 model.primal(); 1894 //printSol(model); 1895 } else { 1896 std::cerr << "Error reading share2qp from sample data. Skipping test." << std::endl; 1897 } 1865 1898 } 1866 1899 if (0) { … … 1868 1901 std::string fn = "./beale"; 1869 1902 //fn = "./jensen"; 1870 m.readMps(fn.c_str(),"mps"); 1871 ClpSimplex solution; 1872 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1873 m.getObjCoefficients(), 1874 m.getRowLower(),m.getRowUpper()); 1875 solution.setDblParam(ClpObjOffset,m.objectiveOffset()); 1876 solution.dual(); 1877 // get quadratic part 1878 int * start=NULL; 1879 int * column = NULL; 1880 double * element = NULL; 1881 m.readQuadraticMps(NULL,start,column,element,2); 1882 // Load up objective 1883 solution.loadQuadraticObjective(solution.numberColumns(),start,column,element); 1884 delete [] start; 1885 delete [] column; 1886 delete [] element; 1887 solution.primal(1); 1888 solution.nonlinearSLP(50,1.0e4); 1889 double objValue = solution.getObjValue(); 1890 CoinRelFltEq eq(1.0e4); 1891 assert(eq(objValue,0.5)); 1892 solution.primal(); 1893 objValue = solution.getObjValue(); 1894 assert(eq(objValue,0.5)); 1903 if (m.readMps(fn.c_str(),"mps") == 0) { 1904 ClpSimplex solution; 1905 solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(), 1906 m.getObjCoefficients(), 1907 m.getRowLower(),m.getRowUpper()); 1908 solution.setDblParam(ClpObjOffset,m.objectiveOffset()); 1909 solution.dual(); 1910 // get quadratic part 1911 int * start=NULL; 1912 int * column = NULL; 1913 double * element = NULL; 1914 m.readQuadraticMps(NULL,start,column,element,2); 1915 // Load up objective 1916 solution.loadQuadraticObjective(solution.numberColumns(),start,column,element); 1917 delete [] start; 1918 delete [] column; 1919 delete [] element; 1920 solution.primal(1); 1921 solution.nonlinearSLP(50,1.0e4); 1922 double objValue = solution.getObjValue(); 1923 CoinRelFltEq eq(1.0e4); 1924 assert(eq(objValue,0.5)); 1925 solution.primal(); 1926 objValue = solution.getObjValue(); 1927 assert(eq(objValue,0.5)); 1928 } else { 1929 std::cerr << "Error reading beale.mps. Skipping test." << std::endl; 1930 } 1895 1931 } 1896 1932 #endif
Note: See TracChangeset
for help on using the changeset viewer.