Changeset 2021
 Timestamp:
 Mar 17, 2014 4:21:18 PM (5 years ago)
 Location:
 trunk/Cbc
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/Cbc_C_Interface.cpp
r2020 r2021 4 4 // This code is licensed under the terms of the Eclipse Public License (EPL). 5 5 6 #include < math.h>6 #include <cmath> 7 7 #include <cfloat> 8 8 … … 220 220 221 221 /* Version */ 222 COINLIBAPI double COINLINKAGE Cbc_getVersion() 223 { 224 double v = 1.0; 225 return v; 222 COINLIBAPI const char* COINLINKAGE Cbc_getVersion() 223 { 224 return CBC_VERSION; 226 225 } 227 226 … … 485 484 return (result) ? 1 : 0; 486 485 } 487 /* Status of problem: 488 0  optimal 489 1  primal infeasible 490 2  dual infeasible 491 3  stopped on iterations etc 492 4  stopped due to errors 493 */ 486 494 487 CbcGetProperty(int, status) 495 488 496 /* Secondary status of problem  may get extended497 0  none498 1  primal infeasible because dual limit reached499 2  scaled problem optimal  unscaled has primal infeasibilities500 3  scaled problem optimal  unscaled has dual infeasibilities501 4  scaled problem optimal  unscaled has both dual and primal infeasibilities502 */503 489 CbcGetProperty(int, secondaryStatus) 504 505 COINLIBAPI void COINLINKAGE506 Cbc_setSecondaryStatus(Cbc_Model * /*model*/, int /*status*/)507 {508 const char prefix[] = "Cbc_C_Interface::Cbc_setSecondaryStatus(): ";509 // const int VERBOSE = 1;510 if (VERBOSE > 0) printf("%s begin\n", prefix);511 512 // cannot find this in Cbc, Osi, or OsiClp513 //tbd model>model_>setSecondaryStatus(status);514 if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix);515 516 if (VERBOSE > 0) printf("%s return\n", prefix);517 }518 490 519 491 /* Number of elements in matrix */ … … 558 530 } 559 531 560 // Column vector lengths in matrix561 COINLIBAPI const int * COINLINKAGE562 Cbc_getVectorLengths(Cbc_Model * model)563 {564 const char prefix[] = "Cbc_C_Interface::Cbc_getVectorLengths(): ";565 // const int VERBOSE = 1;566 if (VERBOSE > 0) printf("%s begin\n", prefix);567 568 const int * result = NULL;569 const CoinPackedMatrix * matrix = NULL;570 matrix = model>model_>solver()>getMatrixByCol();571 result = (matrix == NULL) ? NULL : matrix>getVectorLengths();572 573 if (VERBOSE > 0)574 printf("%s return %p\n", prefix, static_cast<const void*>(result));575 return result;576 }577 532 578 533 // Element values in matrix … … 606 561 if (VERBOSE > 0) printf("%s begin\n", prefix); 607 562 608 // reuse existing log level609 int oldLogLevel = model>model_>messageHandler()>logLevel();610 563 // Will be copy of users one 611 564 delete model>handler_; … … 614 567 model>handler_>setModel(model); 615 568 model>model_>passInMessageHandler(model>handler_); 616 model>model_>messageHandler()>setLogLevel(oldLogLevel);617 569 618 570 if (VERBOSE > 0) printf("%s return\n", prefix); … … 632 584 } 633 585 /* length of names (0 means no names0 */ 634 COINLIBAPI int COINLINKAGE 635 Cbc_lengthNames(Cbc_Model * /*model*/) 636 { 637 const char prefix[] = "Cbc_C_Interface::Cbc_lengthNames(): "; 638 // const int VERBOSE = 1; 639 if (VERBOSE > 0) printf("%s begin\n", prefix); 640 641 int result = 0; 642 // cannot find names in Cbc, Osi, or OsiClp 643 //tbd result = model>model_>lengthNames(); 644 if (VERBOSE > 0) printf("%s WARNING: NOT IMPLEMENTED\n", prefix); 645 646 if (VERBOSE > 0) printf("%s return %i\n", prefix, result); 586 COINLIBAPI size_t COINLINKAGE 587 Cbc_maxNameLength(Cbc_Model * model) 588 { 589 size_t result = 0; 590 OsiSolverInterface::OsiNameVec const & rownames = model>model_>solver()>getRowNames(); 591 for (size_t i = 0; i < rownames.size(); i++) { 592 if (rownames[i].length() > result) result = rownames[i].length(); 593 } 594 OsiSolverInterface::OsiNameVec const & colnames = model>model_>solver()>getColNames(); 595 for (size_t i = 0; i < colnames.size(); i++) { 596 if (colnames[i].length() > result) result = colnames[i].length(); 597 } 647 598 return result; 648 599 } 649 /* Fill in array (at least lengthNames+1 long) with a row name */ 650 COINLIBAPI void COINLINKAGE 651 Cbc_rowName(Cbc_Model * /*model*/, int iRow, char * name) 652 { 653 const char prefix[] = "Cbc_C_Interface::Cbc_rowName(): "; 654 // const int VERBOSE = 1; 655 if (VERBOSE > 0) printf("%s begin\n", prefix); 656 657 sprintf(name, "ROW%5i", iRow); 658 // cannot find names in Cbc, Osi, or OsiClp 659 //tbd std::string rowName=model>model_>rowName(iRow); 660 //tbd strcpy(name,rowName.c_str()); 661 662 if (VERBOSE > 0) printf("%s return\n", prefix); 663 } 664 /* Fill in array (at least lengthNames+1 long) with a column name */ 665 // cannot find names in Cbc, Osi, or OsiClp 666 COINLIBAPI void COINLINKAGE 667 Cbc_columnName(Cbc_Model * /*model*/, int iColumn, char * name) 668 { 669 const char prefix[] = "Cbc_C_Interface::Cbc_columnName(): "; 670 // const int VERBOSE = 1; 671 if (VERBOSE > 0) printf("%s begin\n", prefix); 672 673 sprintf(name, "COL%5i", iColumn); 674 //tbd std::string columnName= model>model_>columnName(iColumn); 675 //tbd strcpy(name,columnName.c_str()); 676 677 if (VERBOSE > 0) printf("%s return\n", prefix); 678 } 600 COINLIBAPI void COINLINKAGE 601 Cbc_getRowName(Cbc_Model * model, int iRow, char * name, size_t maxLength) 602 { 603 std::string rowname = model>model_>solver()>getRowName(iRow); 604 strncpy(name, rowname.c_str(), maxLength); 605 name[maxLength1] = '\0'; 606 } 607 COINLIBAPI void COINLINKAGE 608 Cbc_getColName(Cbc_Model * model, int iRow, char * name, size_t maxLength) 609 { 610 std::string colname = model>model_>solver()>getColName(iRow); 611 strncpy(name, colname.c_str(), maxLength); 612 name[maxLength1] = '\0'; 613 } 614 615 COINLIBAPI void COINLINKAGE 616 Cbc_setColName(Cbc_Model * model, int iColumn, const char * name) 617 { 618 model>model_>solver()>setColName(iColumn, name); 619 } 620 621 COINLIBAPI void COINLINKAGE 622 Cbc_setRowName(Cbc_Model * model, int iRow, const char * name) 623 { 624 model>model_>solver()>setRowName(iRow, name); 625 } 626 679 627 680 628 COINLIBAPI int COINLINKAGE … … 782 730 CbcGetProperty(const double*, getColSolution) 783 731 784 COINLIBAPI void COINLINKAGE785 Cbc_setColSolution(Cbc_Model * model, const double * input)786 {787 const char prefix[] = "Cbc_C_Interface::Cbc_setColSolution(): ";788 // const int VERBOSE = 1;789 if (VERBOSE > 0) printf("%s begin\n", prefix);790 791 OsiSolverInterface * solver = model>model_>solver();792 solver>setColSolution(input);793 794 if (VERBOSE > 0) printf("%s return\n", prefix);795 return;796 }797 798 732 CbcGetProperty(const double*, getRowLower) 799 733 CbcGetProperty(const double*, getRowUpper) … … 803 737 804 738 CbcGetProperty(double, getObjValue) 739 CbcGetProperty(double, getBestPossibleObjValue) 805 740 806 741 /* Print model */ … … 874 809 } 875 810 876 COINLIBAPI double COINLINKAGE877 Cbc_cpuTime(Cbc_Model * /*model*/)878 {879 const char prefix[] = "Cbc_C_Interface::Cbc_cpuTime(): ";880 // const int VERBOSE = 1;881 if (VERBOSE > 0) printf("%s begin\n", prefix);882 883 double result = 0;884 result = CoinCpuTime() ;885 886 if (VERBOSE > 0) printf("%s return %g\n", prefix, result);887 return result;888 }889 890 811 CbcGetProperty(int, getNodeCount) 891 812 … … 902 823 result>solver_ = dynamic_cast< OsiClpSolverInterface*> (result>model_>solver()); 903 824 result>handler_ = NULL; 825 result>cmdargs_ = model>cmdargs_; 904 826 905 827 if (VERBOSE > 0) printf("%s return\n", prefix); … … 1075 997 } 1076 998 1077 /** Delete all object information */1078 COINLIBAPI void COINLINKAGE1079 Cbc_deleteObjects(Cbc_Model * model)1080 {1081 const char prefix[] = "Cbc_C_Interface::Cbc_deleteObjects(): ";1082 // const int VERBOSE = 2;1083 if (VERBOSE > 0) printf("%s begin\n", prefix);1084 1085 model>model_>deleteObjects();1086 1087 if (VERBOSE > 0) printf("%s return\n", prefix);1088 return;1089 }1090 1091 999 /** Print the solution */ 1092 1000 COINLIBAPI void COINLINKAGE 
trunk/Cbc/src/Cbc_C_Interface.h
r2020 r2021 11 11 /* include all defines and ugly stuff */ 12 12 #include "Coin_C_defines.h" 13 14 /** This is a first "C" interface to Cbc. 15 It is mostly similar to the "C" interface to Clp and 16 was contributed by Bob Entriken. 13 #include <stddef.h> 14 15 /** This is a "C" interface to Cbc. 16 Original verison contributed by Bob Entriken, 17 significantly updated by Miles Lubin. 17 18 */ 18 19 … … 22 23 23 24 /**@name Constructors and destructor 24 These do not have an exact analogue in C++.25 25 The user does not need to know structure of Cbc_Model. 26 27 For all functions outside this group there is an exact C++ 28 analogue created by taking the first parameter out, removing the Cbc_ 29 from name and applying the method to an object of type ClpSimplex. 30 */ 31 /*@{*/ 32 33 /** Version */ 34 COINLIBAPI double COINLINKAGE Cbc_getVersion() 35 ; 26 */ 27 /*@{*/ 28 36 29 /** Default Cbc_Model constructor */ 37 30 COINLIBAPI Cbc_Model * COINLINKAGE 38 Cbc_newModel( )31 Cbc_newModel(void) 39 32 ; 40 33 /** Cbc_Model Destructor */ … … 42 35 Cbc_deleteModel(Cbc_Model * model) 43 36 ; 44 /*@}*/ 45 46 /**@name Load model  loads some stuff and initializes others */ 47 /*@{*/ 48 /* Loads a problem (the constraints on the 37 /** Current version of Cbc */ 38 COINLIBAPI const char* COINLINKAGE Cbc_getVersion(void) 39 ; 40 /*@}*/ 41 42 /**@name Getting and setting model data */ 43 /*@{*/ 44 /** Loads a problem (the constraints on the 49 45 rows are given by lower and upper bounds). If a pointer is NULL then the 50 46 following values are the default: … … 57 53 </ul> 58 54 59 Just like the other loadProblem() method except that the matrix is 60 given in a standard column major ordered format (without gaps). 55 The constraint matrix is 56 given in standard compressed sparse column (without gaps). 57 <ul> 58 <li> <code>start[i]</code> stores the starting index of the ith column 59 <li> <code>index[k]</code> stores the row index of the kth nonzero element 60 <li> <code>value[k]</code> stores the coefficient of the kth nonzero element 61 </ul> 61 62 */ 62 63 COINLIBAPI void COINLINKAGE … … 109 110 ; 110 111 111 /*@}*/112 /**@name gets and sets  you will find some synonyms at the end of this file */113 /*@{*/114 /** Set parameter "name" to value "value". Note that this115 * translates directly to using "name value" as a116 * commandline argument to Cbc.*/117 COINLIBAPI void COINLINKAGE118 Cbc_setParameter(Cbc_Model * model, const char * name, const char * value)119 ;120 112 /** Fills in array with problem name */ 121 113 COINLIBAPI void COINLINKAGE … … 129 121 Cbc_setProblemName(Cbc_Model * model, const char * array) 130 122 ; 131 /** Status of problem: 132 0  optimal 133 1  primal infeasible 134 2  dual infeasible 135 3  stopped on iterations etc 136 4  stopped due to errors 137 */ 138 COINLIBAPI int COINLINKAGE 139 Cbc_status(Cbc_Model * model) 140 ; 141 /** Secondary status of problem  may get extended 142 0  none 143 1  primal infeasible because dual limit reached 144 2  scaled problem optimal  unscaled has primal infeasibilities 145 3  scaled problem optimal  unscaled has dual infeasibilities 146 4  scaled problem optimal  unscaled has both dual and primal infeasibilities 147 */ 148 COINLIBAPI int COINLINKAGE 149 Cbc_secondaryStatus(Cbc_Model * model) 150 ; 151 COINLIBAPI void COINLINKAGE 152 Cbc_setSecondaryStatus(Cbc_Model * model, int status) 153 ; 154 /** Number of elements in matrix */ 123 124 /** Number of nonzero elements in constraint matrix */ 155 125 COINLIBAPI int COINLINKAGE 156 126 Cbc_getNumElements(Cbc_Model * model) 157 127 ; 158 /** Column starts in matrix*/128 /** "Column start" vector of constraint matrix. Same format as Cbc_loadProblem() */ 159 129 COINLIBAPI const CoinBigIndex * COINLINKAGE 160 130 Cbc_getVectorStarts(Cbc_Model * model) 161 131 ; 162 /** Row indices inmatrix */132 /** "Row index" vector of constraint matrix */ 163 133 COINLIBAPI const int * COINLINKAGE 164 134 Cbc_getIndices(Cbc_Model * model) 165 135 ; 166 /** Column vector lengths in matrix */ 167 COINLIBAPI const int * COINLINKAGE 168 Cbc_getVectorLengths(Cbc_Model * model) 169 ; 170 /** Element values in matrix */ 136 /** Coefficient vector of constraint matrix */ 171 137 COINLIBAPI const double * COINLINKAGE 172 138 Cbc_getElements(Cbc_Model * model) 173 139 ; 174 175 /*@}*/ 176 /**@name Message handling. Call backs are handled by ONE function */ 177 /*@{*/ 178 /** Pass in Callback function. 179 Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */ 180 COINLIBAPI void COINLINKAGE 181 Cbc_registerCallBack(Cbc_Model * model, 182 cbc_callback userCallBack) 183 ; 184 /** Unset Callback function */ 185 COINLIBAPI void COINLINKAGE 186 Cbc_clearCallBack(Cbc_Model * model) 187 ; 188 /** length of names (0 means no names0 */ 189 COINLIBAPI int COINLINKAGE 190 Cbc_lengthNames(Cbc_Model * model) 191 ; 192 /** Fill in array (at least lengthNames+1 long) with a row name */ 193 COINLIBAPI void COINLINKAGE 194 Cbc_rowName(Cbc_Model * model, int iRow, char * name) 195 ; 196 /** Fill in array (at least lengthNames+1 long) with a column name */ 197 COINLIBAPI void COINLINKAGE 198 Cbc_columnName(Cbc_Model * model, int iColumn, char * name) 199 ; 200 201 /*@}*/ 202 203 204 /**@name Functions most useful to user */ 205 /*@{*/ 206 /* Solve using CbcMain1. This is the recommended default solve function. 207 */ 208 COINLIBAPI int COINLINKAGE 209 Cbc_solve(Cbc_Model * model) 210 ; 211 /*@}*/ 212 213 214 /**@name most useful gets and sets */ 215 /*@{*/ 216 /** Sum of primal infeasibilities */ 217 COINLIBAPI double COINLINKAGE 218 Cbc_sumPrimalInfeasibilities(Cbc_Model * model) 219 ; 220 /** Number of primal infeasibilities */ 221 COINLIBAPI int COINLINKAGE 222 Cbc_numberPrimalInfeasibilities(Cbc_Model * model) 223 ; 224 225 /** Just check solution (for external use)  sets sum of 226 infeasibilities etc */ 227 COINLIBAPI void COINLINKAGE 228 Cbc_checkSolution(Cbc_Model * model) 229 ; 230 /*@}*/ 231 232 /******************** End of most useful part **************/ 233 /**@name gets and sets  some synonyms */ 234 /*@{*/ 235 /** Number of rows */ 140 141 /** Maximum lenght of a row or column name */ 142 COINLIBAPI size_t COINLINKAGE 143 Cbc_maxNameLength(Cbc_Model * model) 144 ; 145 /** Fill in first maxLength bytes of name array with a row name */ 146 COINLIBAPI void COINLINKAGE 147 Cbc_getRowName(Cbc_Model * model, int iRow, char * name, size_t maxLength) 148 ; 149 /** Fill in first maxLength bytes of name array with a column name */ 150 COINLIBAPI void COINLINKAGE 151 Cbc_getColName(Cbc_Model * model, int iColumn, char * name, size_t maxLength) 152 ; 153 /** Set the name of a column */ 154 COINLIBAPI void COINLINKAGE 155 Cbc_setColName(Cbc_Model * model, int iColumn, const char * name) 156 ; 157 /** Set the name of a row */ 158 COINLIBAPI void COINLINKAGE 159 Cbc_setRowName(Cbc_Model * model, int iRow, const char * name) 160 ; 161 /** Number of constraints in the model */ 236 162 COINLIBAPI int COINLINKAGE 237 163 Cbc_getNumRows(Cbc_Model * model) 238 164 ; 239 /** Number of columns*/165 /** Number of variables in the model */ 240 166 COINLIBAPI int COINLINKAGE 241 167 Cbc_getNumCols(Cbc_Model * model) 242 ;243 /** Number of iterations */244 COINLIBAPI int COINLINKAGE245 Cbc_getIterationCount(Cbc_Model * model)246 ;247 /** Are there a numerical difficulties? */248 COINLIBAPI int COINLINKAGE249 Cbc_isAbandoned(Cbc_Model * model)250 ;251 /** Is optimality proven? */252 COINLIBAPI int COINLINKAGE253 Cbc_isProvenOptimal(Cbc_Model * model)254 ;255 /** Is infeasiblity proven (or none better than cutoff)? */256 COINLIBAPI int COINLINKAGE257 Cbc_isProvenInfeasible(Cbc_Model * model)258 ;259 /** Was continuous solution unbounded? */260 COINLIBAPI int COINLINKAGE261 Cbc_isContinuousUnbounded(Cbc_Model * model)262 ;263 /** Node limit reached? */264 COINLIBAPI int COINLINKAGE265 Cbc_isNodeLimitReached(Cbc_Model * model)266 ;267 /** Time limit reached? */268 COINLIBAPI int COINLINKAGE269 Cbc_isSecondsLimitReached(Cbc_Model * model)270 ;271 /** Solution limit reached? */272 COINLIBAPI int COINLINKAGE273 Cbc_isSolutionLimitReached(Cbc_Model * model)274 ;275 /** Are there numerical difficulties (for initialSolve) ? */276 COINLIBAPI int COINLINKAGE277 Cbc_isInitialSolveAbandoned(Cbc_Model * model)278 ;279 /** Is optimality proven (for initialSolve) ? */280 COINLIBAPI int COINLINKAGE281 Cbc_isInitialSolveProvenOptimal(Cbc_Model * model)282 ;283 /** Is primal infeasiblity proven (for initialSolve) ? */284 COINLIBAPI int COINLINKAGE285 Cbc_isInitialSolveProvenPrimalInfeasible(Cbc_Model * model)286 168 ; 287 169 /** Direction of optimization (1  minimize, 1  maximize, 0  ignore) */ … … 293 175 Cbc_getObjSense(Cbc_Model * model) 294 176 ; 295 /** Primal row solution 296 * This is the vector A*x, where A is the constraint matrix 297 * and x is the current solution. */ 298 COINLIBAPI const double * COINLINKAGE 299 Cbc_getRowActivity(Cbc_Model * model) 300 ; 301 /** Primal column solution */ 302 COINLIBAPI const double * COINLINKAGE 303 Cbc_getColSolution(Cbc_Model * model) 304 ; 305 COINLIBAPI void COINLINKAGE 306 Cbc_setColSolution(Cbc_Model * model, const double * input) 307 ; 308 /** Row lower */ 177 /** Constraint lower bounds */ 309 178 COINLIBAPI const double* COINLINKAGE 310 179 Cbc_getRowLower(Cbc_Model * model) 311 180 ; 312 /** Row upper*/181 /** Constraint upper bounds */ 313 182 COINLIBAPI const double* COINLINKAGE 314 183 Cbc_getRowUpper(Cbc_Model * model) 315 184 ; 316 /** Objective */185 /** Objective vector */ 317 186 COINLIBAPI const double * COINLINKAGE 318 187 Cbc_getObjCoefficients(Cbc_Model * model) 319 188 ; 320 /** Column Lower*/189 /** Variable lower bounds */ 321 190 COINLIBAPI const double * COINLINKAGE 322 191 Cbc_getColLower(Cbc_Model * model) 323 192 ; 324 /** Column Upper*/193 /** Variable upper bounds */ 325 194 COINLIBAPI const double * COINLINKAGE 326 195 Cbc_getColUpper(Cbc_Model * model) 327 196 ; 328 /** Objective value */ 329 COINLIBAPI double COINLINKAGE 330 Cbc_getObjValue(Cbc_Model * model) 331 ; 332 /** Print the model */ 333 COINLIBAPI void COINLINKAGE 334 Cbc_printModel(Cbc_Model * model, const char * argPrefix) 335 ; 336 /** Determine whether the variable at location i is integer restricted */ 197 /** Determine whether the ith variable is integer restricted */ 337 198 COINLIBAPI int COINLINKAGE 338 199 Cbc_isInteger(Cbc_Model * model, int i) 339 200 ; 340 /** Return CPU time */ 341 COINLIBAPI double COINLINKAGE 342 Cbc_cpuTime(Cbc_Model * model) 343 ; 344 /** Number of nodes explored in B&B tree */ 345 COINLIBAPI int COINLINKAGE 346 Cbc_getNodeCount(Cbc_Model * model) 347 ; 348 /** Return a copy of this model */ 349 COINLIBAPI Cbc_Model * COINLINKAGE 350 Cbc_clone(Cbc_Model * model) 351 ; 352 /** Set this the variable to be continuous */ 201 /** Set this variable to be continuous */ 353 202 COINLIBAPI Cbc_Model * COINLINKAGE 354 203 Cbc_setContinuous(Cbc_Model * model, int iColumn) 355 204 ; 356 /** Set this thevariable to be integer */205 /** Set this variable to be integer */ 357 206 COINLIBAPI Cbc_Model * COINLINKAGE 358 207 Cbc_setInteger(Cbc_Model * model, int iColumn) … … 368 217 const int * rowIndices, const double * weights, const int type) 369 218 ; 370 /** Delete all object information */ 371 COINLIBAPI void COINLINKAGE 372 Cbc_deleteObjects(Cbc_Model * model) 219 /** Print the model */ 220 COINLIBAPI void COINLINKAGE 221 Cbc_printModel(Cbc_Model * model, const char * argPrefix) 222 ; 223 /** Return a copy of this model */ 224 COINLIBAPI Cbc_Model * COINLINKAGE 225 Cbc_clone(Cbc_Model * model) 226 ; 227 /*@}*/ 228 /**@name Solver parameters */ 229 /*@{*/ 230 /** Set parameter "name" to value "value". Note that this 231 * translates directly to using "name value" as a 232 * commandline argument to Cbc.*/ 233 COINLIBAPI void COINLINKAGE 234 Cbc_setParameter(Cbc_Model * model, const char * name, const char * value) 235 ; 236 237 238 /*@}*/ 239 /**@name Message handling. Call backs are handled by ONE function */ 240 /*@{*/ 241 /** Pass in Callback function. 242 Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */ 243 COINLIBAPI void COINLINKAGE 244 Cbc_registerCallBack(Cbc_Model * model, 245 cbc_callback userCallBack) 246 ; 247 /** Unset Callback function */ 248 COINLIBAPI void COINLINKAGE 249 Cbc_clearCallBack(Cbc_Model * model) 250 ; 251 252 /*@}*/ 253 254 255 /**@name Solving the model */ 256 /*@{*/ 257 /* Solve the model with Cbc (using CbcMain1). 258 */ 259 COINLIBAPI int COINLINKAGE 260 Cbc_solve(Cbc_Model * model) 261 ; 262 /*@}*/ 263 264 265 /**@name Accessing the solution and solution status */ 266 /*@{*/ 267 268 /** Sum of primal infeasibilities */ 269 COINLIBAPI double COINLINKAGE 270 Cbc_sumPrimalInfeasibilities(Cbc_Model * model) 271 ; 272 /** Number of primal infeasibilities */ 273 COINLIBAPI int COINLINKAGE 274 Cbc_numberPrimalInfeasibilities(Cbc_Model * model) 275 ; 276 277 /** Just check solution (for external use)  sets sum of 278 infeasibilities etc */ 279 COINLIBAPI void COINLINKAGE 280 Cbc_checkSolution(Cbc_Model * model) 281 ; 282 283 /** Number of iterations */ 284 COINLIBAPI int COINLINKAGE 285 Cbc_getIterationCount(Cbc_Model * model) 286 ; 287 /** Are there a numerical difficulties? */ 288 COINLIBAPI int COINLINKAGE 289 Cbc_isAbandoned(Cbc_Model * model) 290 ; 291 /** Is optimality proven? */ 292 COINLIBAPI int COINLINKAGE 293 Cbc_isProvenOptimal(Cbc_Model * model) 294 ; 295 /** Is infeasiblity proven (or none better than cutoff)? */ 296 COINLIBAPI int COINLINKAGE 297 Cbc_isProvenInfeasible(Cbc_Model * model) 298 ; 299 /** Was continuous solution unbounded? */ 300 COINLIBAPI int COINLINKAGE 301 Cbc_isContinuousUnbounded(Cbc_Model * model) 302 ; 303 /** Node limit reached? */ 304 COINLIBAPI int COINLINKAGE 305 Cbc_isNodeLimitReached(Cbc_Model * model) 306 ; 307 /** Time limit reached? */ 308 COINLIBAPI int COINLINKAGE 309 Cbc_isSecondsLimitReached(Cbc_Model * model) 310 ; 311 /** Solution limit reached? */ 312 COINLIBAPI int COINLINKAGE 313 Cbc_isSolutionLimitReached(Cbc_Model * model) 314 ; 315 /** Are there numerical difficulties (for initialSolve) ? */ 316 COINLIBAPI int COINLINKAGE 317 Cbc_isInitialSolveAbandoned(Cbc_Model * model) 318 ; 319 /** Is optimality proven (for initialSolve) ? */ 320 COINLIBAPI int COINLINKAGE 321 Cbc_isInitialSolveProvenOptimal(Cbc_Model * model) 322 ; 323 /** Is primal infeasiblity proven (for initialSolve) ? */ 324 COINLIBAPI int COINLINKAGE 325 Cbc_isInitialSolveProvenPrimalInfeasible(Cbc_Model * model) 326 ; 327 /** "row" solution 328 * This is the vector A*x, where A is the constraint matrix 329 * and x is the current solution. */ 330 COINLIBAPI const double * COINLINKAGE 331 Cbc_getRowActivity(Cbc_Model * model) 332 ; 333 /** Best feasible solution vector */ 334 COINLIBAPI const double * COINLINKAGE 335 Cbc_getColSolution(Cbc_Model * model) 336 ; 337 /** Objective value of best feasible solution */ 338 COINLIBAPI double COINLINKAGE 339 Cbc_getObjValue(Cbc_Model * model) 340 ; 341 /** Best known bound on the optimal objective value */ 342 COINLIBAPI double COINLINKAGE 343 Cbc_getBestPossibleObjValue(Cbc_Model * model) 344 ; 345 /** Number of nodes explored in B&B tree */ 346 COINLIBAPI int COINLINKAGE 347 Cbc_getNodeCount(Cbc_Model * model) 373 348 ; 374 349 /** Print the solution */ 375 350 COINLIBAPI void COINLINKAGE 376 351 Cbc_printSolution(Cbc_Model * model) 352 ; 353 /** Final status of problem 354 Some of these can be found out by is...... functions 355 1 before branchAndBound 356 0 finished  check isProvenOptimal or isProvenInfeasible to see if solution found 357 (or check value of best solution) 358 1 stopped  on maxnodes, maxsols, maxtime 359 2 difficulties so run was abandoned 360 (5 event user programmed event occurred) 361 */ 362 COINLIBAPI int COINLINKAGE 363 Cbc_status(Cbc_Model * model) 364 ; 365 /** Secondary status of problem 366 1 unset (status_ will also be 1) 367 0 search completed with solution 368 1 linear relaxation not feasible (or worse than cutoff) 369 2 stopped on gap 370 3 stopped on nodes 371 4 stopped on time 372 5 stopped on user event 373 6 stopped on solutions 374 7 linear relaxation unbounded 375 8 stopped on iteration limit 376 */ 377 COINLIBAPI int COINLINKAGE 378 Cbc_secondaryStatus(Cbc_Model * model) 377 379 ; 378 380 /*@}*/ 
trunk/Cbc/test/CInterfaceTest.c
r2020 r2021 10 10 #include <stdio.h> 11 11 #include <string.h> 12 13 14 static int callback_called = 0; 15 16 void (COINLINKAGE_CB test_callback)(Cbc_Model * model,int msgno, int ndouble, 17 const double * dvec, int nint, const int * ivec, 18 int nchar, char ** cvec) { 19 20 callback_called = 1; 21 printf("In callback: message %d\n", msgno); 22 23 } 12 24 13 25 … … 35 47 int i; 36 48 49 printf("Interface reports Cbc version %s\n", Cbc_getVersion()); 50 37 51 Cbc_loadProblem(model, 5, 1, start, rowindex, value, collb, colub, obj, rowlb, rowub); 52 53 Cbc_setColName(model, 2, "var2"); 54 Cbc_setRowName(model, 0, "constr0"); 55 38 56 39 57 assert(Cbc_getNumCols(model) == 5); … … 50 68 Cbc_setProblemName(model, setname); 51 69 70 Cbc_registerCallBack(model, test_callback); 71 52 72 Cbc_solve(model); 53 73 … … 60 80 assert(!Cbc_isSolutionLimitReached(model)); 61 81 assert(fabs( Cbc_getObjValue(model) (16.0) < 1e6)); 82 assert(fabs( Cbc_getBestPossibleObjValue(model) (16.0) < 1e6)); 83 84 assert(callback_called == 1); 62 85 63 86 sol = Cbc_getColSolution(model); … … 72 95 i = strcmp(getname,setname); 73 96 assert( (i == 0) ); 97 98 Cbc_getColName(model, 2, getname, 20); 99 i = strcmp(getname, "var2"); 100 assert( (i == 0) ); 101 Cbc_getRowName(model, 0, getname, 20); 102 i = strcmp(getname, "constr0"); 103 assert( (i == 0) ); 104 assert( Cbc_maxNameLength(model) >= 7 ); 74 105 75 106 Cbc_deleteModel(model);
Note: See TracChangeset
for help on using the changeset viewer.