Changeset 2036 for trunk/Cbc/test
 Timestamp:
 May 25, 2014 9:07:36 PM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

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.