 Timestamp:
 May 25, 2014 9:07:36 PM (7 years ago)
 Location:
 trunk/Cbc
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/Cbc_C_Interface.cpp
r2033 r2036 32 32 { \ 33 33 return m>model_>prop(); \ 34 } 35 36 #define CbcSetSolverProperty(T,prop) \ 37 COINLIBAPI void COINLINKAGE \ 38 Cbc_ ## prop (Cbc_Model *m, int index, T val) \ 39 { \ 40 m>model_>solver()>prop(index,val); \ 34 41 } 35 42 … … 700 707 701 708 CbcGetProperty(const double*, getRowLower) 709 CbcSetSolverProperty(double, setRowLower) 702 710 CbcGetProperty(const double*, getRowUpper) 711 CbcSetSolverProperty(double, setRowUpper) 703 712 CbcGetProperty(const double*, getObjCoefficients) 713 CbcSetSolverProperty(double, setObjCoeff) 704 714 CbcGetProperty(const double*, getColLower) 715 CbcSetSolverProperty(double, setColLower) 705 716 CbcGetProperty(const double*, getColUpper) 717 CbcSetSolverProperty(double, setColUpper) 706 718 707 719 CbcGetProperty(double, getObjValue) … … 824 836 } 825 837 /** Add SOS constraints to the model using roworder matrix */ 838 /* 826 839 COINLIBAPI void COINLINKAGE 827 840 Cbc_addSOS(Cbc_Model * model, int numRows, const int * rowStarts, … … 890 903 if (VERBOSE > 2) { 891 904 printf("%s calling addObjects()\n", prefix); 892 /*893 printf("%s numObjects = %i, objects = %X\n",prefix,numObjects,objects);894 for (row=0; row<numObjects; row++)895 printf("%s objects[%i] = %X\n",prefix,row,objects[row]);896 */905 906 // printf("%s numObjects = %i, objects = %X\n",prefix,numObjects,objects); 907 // for (row=0; row<numObjects; row++) 908 // printf("%s objects[%i] = %X\n",prefix,row,objects[row]); 909 897 910 } 898 911 fflush(stdout); … … 905 918 if (VERBOSE > 0) printf("%sreturn\n", prefix); 906 919 return; 907 } 920 }*/ 908 921 909 922 /** Print the solution */ 
trunk/Cbc/src/Cbc_C_Interface.h
r2033 r2036 173 173 Cbc_getRowLower(Cbc_Model * model) 174 174 ; 175 /** Set the lower bound of a single constraint */ 176 COINLIBAPI void COINLINKAGE 177 Cbc_setRowLower(Cbc_Model * model, int index, double value) 178 ; 175 179 /** Constraint upper bounds */ 176 180 COINLIBAPI const double* COINLINKAGE 177 181 Cbc_getRowUpper(Cbc_Model * model) 178 182 ; 183 /** Set the upper bound of a single constraint */ 184 COINLIBAPI void COINLINKAGE 185 Cbc_setRowUpper(Cbc_Model * model, int index, double value) 186 ; 179 187 /** Objective vector */ 180 188 COINLIBAPI const double * COINLINKAGE 181 189 Cbc_getObjCoefficients(Cbc_Model * model) 182 190 ; 191 /** Set the objective coefficient of a single variable */ 192 COINLIBAPI void COINLINKAGE 193 Cbc_setObjCoeff(Cbc_Model * model, int index, double value) 194 ; 183 195 /** Variable lower bounds */ 184 196 COINLIBAPI const double * COINLINKAGE 185 197 Cbc_getColLower(Cbc_Model * model) 186 198 ; 199 /** Set the lower bound of a single variable */ 200 COINLIBAPI void COINLINKAGE 201 Cbc_setColLower(Cbc_Model * model, int index, double value) 202 ; 187 203 /** Variable upper bounds */ 188 204 COINLIBAPI const double * COINLINKAGE 189 205 Cbc_getColUpper(Cbc_Model * model) 206 ; 207 /** Set the upper bound of a single variable */ 208 COINLIBAPI void COINLINKAGE 209 Cbc_setColUpper(Cbc_Model * model, int index, double value) 190 210 ; 191 211 /** Determine whether the ith variable is integer restricted */ … … 201 221 Cbc_setInteger(Cbc_Model * model, int iColumn) 202 222 ; 203 /** Add SOS constraints to the model using roworder matrix */ 204 COINLIBAPI void COINLINKAGE 223 /* Add SOS constraints to the model using roworder matrix 224 * Unable to confirm that this function is working. */ 225 /*COINLIBAPI void COINLINKAGE 205 226 Cbc_addSOS(Cbc_Model * model, int numRows, const int * rowStarts, 206 227 const int * colIndices, const double * weights, const int type) 207 ; 228 ;*/ 208 229 /** Print the model */ 209 230 COINLIBAPI void COINLINKAGE 
trunk/Cbc/test/CInterfaceTest.c
r2033 r2036 111 111 } 112 112 113 void test SOS() {114 115 Cbc_Model *model = Cbc_newModel(); 116 117 /* 118 M inimize 5x[1] + 3x[2] + 2x[3] + 7x[4] + 4x[5]119 s.t. x[1] + x[2] + x[3] + x[4] + x[5] == 1113 void testProblemModification() { 114 115 Cbc_Model *model = Cbc_newModel(); 116 117 /* Simple knapsack problem 118 Maximize 5x[1] + 3x[2] + 2x[3] + 7x[4] + 4x[5] 119 s.t. 2x[1] + 8x[2] + 4x[3] + 2x[4] + 5x[5] <= 10 120 120 All x binary 121 121 */ 122 122 123 CoinBigIndex start[] = {0, 0, 0, 0, 0, 0, 0};124 /*int rowindex[] = {};*/125 /*double value[] = {};*/123 CoinBigIndex start[] = {0, 1, 2, 3, 4, 5, 6}; 124 int rowindex[] = {0, 0, 0, 0, 0}; 125 double value[] = {2, 8, 4, 2, 5}; 126 126 double collb[] = {0,0,0,0,0}; 127 127 double colub[] = {1,1,1,1,1}; 128 128 double obj[] = {5, 3, 2, 7, 4}; 129 /*double rowlb[] = {};*/ 130 /*double rowub[] = {};*/ 129 double rowlb[] = {INFINITY}; 130 double rowub[] = {10}; 131 const double *sol; 132 int i; 133 134 printf("Interface reports Cbc version %s\n", Cbc_getVersion()); 135 136 Cbc_loadProblem(model, 5, 1, start, rowindex, value, collb, colub, obj, rowlb, rowub); 137 138 for (i = 0; i < 5; i++) { 139 Cbc_setInteger(model, i); 140 assert(Cbc_isInteger(model,i)); 141 } 142 143 Cbc_setObjSense(model, 1); 144 assert(Cbc_getObjSense(model) == 1); 145 146 Cbc_solve(model); 147 148 assert(Cbc_isProvenOptimal(model)); 149 assert(fabs( Cbc_getObjValue(model) (16.0) < 1e6)); 150 151 sol = Cbc_getColSolution(model); 152 153 assert(fabs(sol[0]  1.0) < 1e6); 154 assert(fabs(sol[1]  0.0) < 1e6); 155 assert(fabs(sol[2]  0.0) < 1e6); 156 assert(fabs(sol[3]  1.0) < 1e6); 157 assert(fabs(sol[4]  1.0) < 1e6); 158 159 Cbc_setColUpper(model, 0, 0.0); 160 Cbc_solve(model); 161 162 assert(Cbc_isProvenOptimal(model)); 163 assert(fabs( Cbc_getObjValue(model) (11.0) < 1e6)); 164 165 sol = Cbc_getColSolution(model); 166 167 assert(fabs(sol[0]  0.0) < 1e6); 168 assert(fabs(sol[1]  0.0) < 1e6); 169 assert(fabs(sol[2]  0.0) < 1e6); 170 assert(fabs(sol[3]  1.0) < 1e6); 171 assert(fabs(sol[4]  1.0) < 1e6); 172 173 174 Cbc_setColLower(model, 1, 1.0); 175 176 assert(Cbc_isProvenOptimal(model)); 177 assert(fabs( Cbc_getObjValue(model) (10.0) < 1e6)); 178 179 sol = Cbc_getColSolution(model); 180 181 assert(fabs(sol[0]  0.0) < 1e6); 182 assert(fabs(sol[1]  1.0) < 1e6); 183 assert(fabs(sol[2]  0.0) < 1e6); 184 assert(fabs(sol[3]  1.0) < 1e6); 185 assert(fabs(sol[4]  0.0) < 1e6); 186 187 188 Cbc_deleteModel(model); 189 190 } 191 192 /* 193 void testSOS() { 194 195 Cbc_Model *model = Cbc_newModel(); 196 197 / * 198 Maximize 5x[1] + 3x[2] + 2x[3] + 7x[4] + 4x[5] 199 s.t. x[1] + x[2] + x[3] + x[4] + x[5] == 1 200 All x binary 201 * / 202 203 CoinBigIndex start[] = {0, 0, 0, 0, 0, 0, 0}; 204 double collb[] = {0,0,0,0,0}; 205 double colub[] = {1,1,1,1,1}; 206 double obj[] = {5, 3, 2, 7, 4}; 131 207 int sosrowstart[] = {0,5}; 132 208 int soscolindex[] = {0,1,2,3,4}; … … 144 220 } 145 221 146 assert(Cbc_getObjSense(model) == 1); 222 Cbc_setObjSense(model, 1); 223 assert(Cbc_getObjSense(model) == 1); 147 224 148 225 Cbc_addSOS(model,1,sosrowstart,soscolindex,obj,1); … … 157 234 assert(!Cbc_isSecondsLimitReached(model)); 158 235 assert(!Cbc_isSolutionLimitReached(model)); 159 assert(fabs( Cbc_getObjValue(model) ( 2.0) < 1e6));160 assert(fabs( Cbc_getBestPossibleObjValue(model) ( 2.0) < 1e6));236 assert(fabs( Cbc_getObjValue(model) (7.0) < 1e6)); 237 assert(fabs( Cbc_getBestPossibleObjValue(model) (7.0) < 1e6)); 161 238 162 239 sol = Cbc_getColSolution(model); … … 164 241 assert(fabs(sol[0]  0.0) < 1e6); 165 242 assert(fabs(sol[1]  0.0) < 1e6); 166 assert(fabs(sol[2]  1.0) < 1e6);167 assert(fabs(sol[3]  0.0) < 1e6);243 assert(fabs(sol[2]  0.0) < 1e6); 244 assert(fabs(sol[3]  1.0) < 1e6); 168 245 assert(fabs(sol[4]  0.0) < 1e6); 169 246 … … 171 248 172 249 } 250 */ 173 251 174 252 void testIntegerInfeasible() { … … 250 328 printf("Knapsack test\n"); 251 329 testKnapsack(); 252 printf("SOS test\n");253 testSOS(); 330 /*printf("SOS test\n"); 331 testSOS();*/ 254 332 printf("Infeasible test\n"); 255 333 testIntegerInfeasible(); 256 334 printf("Unbounded test\n"); 257 335 testIntegerUnbounded(); 336 printf("Problem modification test\n"); 337 testProblemModification(); 258 338 259 339 return 0;
Note: See TracChangeset
for help on using the changeset viewer.