Changeset 1593
- Timestamp:
- Feb 9, 2011 6:09:03 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CbcSolver.cpp
r1592 r1593 48 48 49 49 #include "CbcSolverHeuristics.hpp" 50 #ifdef COIN_HAS_GLPK 51 #include "glpk.h" 52 extern glp_tran* cbc_glp_tran; 53 extern glp_prob* cbc_glp_prob; 54 #endif 50 55 51 56 //#define USER_HAS_FAKE_CLP … … 7513 7518 break; 7514 7519 case CLP_PARAM_ACTION_SOLUTION: 7520 case CLP_PARAM_ACTION_GMPL_SOLUTION: 7515 7521 if (goodModel) { 7516 7522 // get next field … … 7570 7576 if (fp) { 7571 7577 #ifndef CBC_OTHER_SOLVER 7578 // See if Glpk 7579 if (type == CLP_PARAM_ACTION_GMPL_SOLUTION) { 7580 int numberRows = lpSolver->getNumRows(); 7581 int numberColumns = lpSolver->getNumCols(); 7582 int numberGlpkRows=numberRows+1; 7583 if (cbc_glp_prob) { 7584 // from gmpl 7585 numberGlpkRows=glp_get_num_rows(cbc_glp_prob); 7586 if (numberGlpkRows!=numberRows) 7587 printf("Mismatch - cbc %d rows, glpk %d\n", 7588 numberRows,numberGlpkRows); 7589 } 7590 fprintf(fp,"%d %d\n",numberGlpkRows, 7591 numberColumns); 7592 int iStat = lpSolver->status(); 7593 int iStat2 = GLP_UNDEF; 7594 bool integerProblem = false; 7595 if (integerStatus >= 0){ 7596 iStat = integerStatus; 7597 integerProblem = true; 7598 } 7599 if (iStat == 0) { 7600 // optimal 7601 if (integerProblem) 7602 iStat2 = GLP_OPT; 7603 else 7604 iStat2 = GLP_FEAS; 7605 } else if (iStat == 1) { 7606 // infeasible 7607 iStat2 = GLP_NOFEAS; 7608 } else if (iStat == 2) { 7609 // unbounded 7610 // leave as 1 7611 } else if (iStat >= 3 && iStat <= 5) { 7612 if (babModel_ && !babModel_->bestSolution()) 7613 iStat2 = GLP_NOFEAS; 7614 else 7615 iStat2 = GLP_FEAS; 7616 } else if (iStat == 6) { 7617 // bab infeasible 7618 iStat2 = GLP_NOFEAS; 7619 } 7620 lpSolver->computeObjectiveValue(false); 7621 double objValue = clpSolver->getObjValue() 7622 * clpSolver->getObjSense(); 7623 if (integerProblem) 7624 fprintf(fp,"%d %g\n",iStat2,objValue); 7625 else 7626 fprintf(fp,"%d 2 %g\n",iStat2,objValue); 7627 if (numberGlpkRows > numberRows) { 7628 // objective as row 7629 if (integerProblem) { 7630 fprintf(fp,"%g\n",objValue); 7631 } else { 7632 fprintf(fp,"4 %g 1.0\n",objValue); 7633 } 7634 } 7635 int lookup[6]= 7636 {4,1,3,2,4,5}; 7637 const double * primalRowSolution = 7638 lpSolver->primalRowSolution(); 7639 const double * dualRowSolution = 7640 lpSolver->dualRowSolution(); 7641 for (int i=0;i<numberRows;i++) { 7642 if (integerProblem) { 7643 fprintf(fp,"%g\n",primalRowSolution[i]); 7644 } else { 7645 fprintf(fp,"%d %g %g\n",lookup[lpSolver->getRowStatus(i)], 7646 primalRowSolution[i],dualRowSolution[i]); 7647 } 7648 } 7649 const double * primalColumnSolution = 7650 lpSolver->primalColumnSolution(); 7651 const double * dualColumnSolution = 7652 lpSolver->dualColumnSolution(); 7653 for (int i=0;i<numberColumns;i++) { 7654 if (integerProblem) { 7655 fprintf(fp,"%g\n",primalColumnSolution[i]); 7656 } else { 7657 fprintf(fp,"%d %g %g\n",lookup[lpSolver->getColumnStatus(i)], 7658 primalColumnSolution[i],dualColumnSolution[i]); 7659 } 7660 } 7661 fclose(fp); 7662 #ifdef COIN_HAS_GLPK 7663 if (cbc_glp_prob) { 7664 if (integerProblem) { 7665 glp_read_mip(cbc_glp_prob,fileName.c_str()); 7666 glp_mpl_postsolve(cbc_glp_tran, 7667 cbc_glp_prob, 7668 GLP_MIP); 7669 } else { 7670 glp_read_sol(cbc_glp_prob,fileName.c_str()); 7671 glp_mpl_postsolve(cbc_glp_tran, 7672 cbc_glp_prob, 7673 GLP_SOL); 7674 } 7675 // free up as much as possible 7676 glp_free(cbc_glp_prob); 7677 glp_mpl_free_wksp(cbc_glp_tran); 7678 //gmp_free_mem(); 7679 /* check that no memory blocks are still allocated */ 7680 glp_free_env(); 7681 } 7682 #endif 7683 break; 7684 } 7572 7685 if (printMode < 5) { 7573 7686 // Write solution header (suggested by Luigi Poderico)
Note: See TracChangeset
for help on using the changeset viewer.