Changeset 2881


Ignore:
Timestamp:
Feb 23, 2020 8:15:08 PM (20 months ago)
Author:
unxusr
Message:

Option to round integer variables before saving: default to false. Round when all variables are integral.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/CbcModel.cpp

    r2873 r2881  
    57275727  , threadMode_(0)
    57285728  , numberGlobalCutsIn_(0)
     5729  , roundIntVars_(false)
    57295730  , master_(NULL)
    57305731  , masterThread_(NULL)
     
    59025903  , threadMode_(0)
    59035904  , numberGlobalCutsIn_(0)
     5905  , roundIntVars_(false)
    59045906  , master_(NULL)
    59055907  , masterThread_(NULL)
     
    61936195  , threadMode_(rhs.threadMode_)
    61946196  , numberGlobalCutsIn_(rhs.numberGlobalCutsIn_)
     6197  , roundIntVars_(rhs.roundIntVars_)
    61956198  , master_(NULL)
    61966199  , masterThread_(NULL)
     
    66076610    threadMode_ = rhs.threadMode_;
    66086611    numberGlobalCutsIn_ = rhs.numberGlobalCutsIn_;
     6612    roundIntVars_ = rhs.roundIntVars_;
    66096613    delete master_;
    66106614    master_ = NULL;
     
    70237027  threadMode_ = rhs.threadMode_;
    70247028  numberGlobalCutsIn_ = rhs.numberGlobalCutsIn_;
     7029  roundIntVars_ = rhs.roundIntVars_;
    70257030  delete master_;
    70267031  master_ = NULL;
     
    1779117796      save[1] = objectiveValue;
    1779217797      memcpy(save + 2, solution, n * sizeof(double));
     17798      bool allInt = (solver_->getNumIntegers() == solver_->getNumCols());
     17799      double *x = save + 2;
     17800      if (roundIntVars_ || allInt) {
     17801        for ( int i=0 ; (i<n) ; ++i )
     17802          if (solver_->isInteger(i))
     17803            x[i] = floor(x[i] + 0.5);
     17804      }
    1779317805    }
    1779417806  }
     
    1780417816  bestObjective_ = objectiveValue;
    1780517817  memcpy(bestSolution_, solution, n * sizeof(double));
     17818  bool allInt = (solver_->getNumIntegers() == solver_->getNumCols());
     17819  if (roundIntVars_ || allInt) {
     17820    for ( int i=0 ; (i<n) ; ++i )
     17821      if (solver_->isInteger(i))
     17822        bestSolution_[i] = floor(bestSolution_[i] + 0.5);
     17823  }
    1780617824  if ((moreSpecialOptions2_&65536)!=0) {
    1780717825    // save a copy of solver with constraints
     
    1975119769}
    1975219770
     19771void CbcModel::setRoundIntegerVariables( bool round_ ) {
     19772  this->roundIntVars_ = round_;
     19773}
     19774
     19775/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
     19776*/
  • trunk/src/CbcModel.hpp

    r2865 r2881  
    624624    return getIntParam(CbcMaxNumNode);
    625625  }
     626
     627  /// If integer variables should be rounded before saving a solution.
     628  //  For some problems with integer and continuous variables, rounding can
     629  //  increase the infeasibilities, but it can make sense if all variables
     630  //  are integral. Default is false.
     631  void setRoundIntegerVariables( bool round_ );
    626632
    627633  /** Set the
     
    32623268  /// Number of global cuts on entry to a node
    32633269  int numberGlobalCutsIn_;
     3270
     3271  // if values of integer variables should be rounded before saving,
     3272  // default false
     3273  bool roundIntVars_;
     3274
    32643275  /// Thread stuff for master
    32653276  CbcBaseModel *master_;
  • trunk/src/Cbc_C_Interface.cpp

    r2875 r2881  
    18581858    }
    18591859#endif
     1860    model->cbcModel_->setRoundIntegerVariables( model->int_param[INT_PARAM_ROUND_INT_VARS] );
    18601861    CbcMain1( nargs, args, *model->cbcModel_, cbc_callb, cbcData );
    18611862
     
    38693870  model->int_param[INT_PARAM_MULTIPLE_ROOTS]   =        0;
    38703871  model->int_param[INT_PARAM_THREADS]          =       -1;
     3872  model->int_param[INT_PARAM_ROUND_INT_VARS]   =        1;
    38713873
    38723874  model->dbl_param[DBL_PARAM_PRIMAL_TOL]       =          1e-6;
  • trunk/src/Cbc_C_Interface.h

    r2877 r2881  
    9292  INT_PARAM_CUT_DEPTH           = 3,  /*! Sets the application of cuts to every depth multiple of this value. -1, the default value, let the solve decide. */
    9393  INT_PARAM_MAX_NODES           = 4,  /*! Maximum number of nodes to be explored in the search tree */
    94   INT_PARAM_NUMBER_BEFORE       = 5,  /*! Number of branche before trusting pseudocodes computed in strong branching. */
     94  INT_PARAM_NUMBER_BEFORE       = 5,  /*! Number of branches before trusting pseudocodes computed in strong branching. */
    9595  INT_PARAM_FPUMP_ITS           = 6,  /*! Maximum number of iterations in the feasibility pump method. */
    9696  INT_PARAM_MAX_SOLS            = 7,  /*! Maximum number of solutions generated during the search. Stops the search when this number of solutions is found. */
    97   INT_PARAM_CUT_PASS_IN_TREE    = 8, /*! Maxinum number of cuts passes in the search tree (with the exception of the root node). Default 1. */
    98   INT_PARAM_THREADS             = 9, /*! Number of threads that can be used in the branch-and-bound method.*/
     97  INT_PARAM_CUT_PASS_IN_TREE    = 8,  /*! Maximum number of cuts passes in the search tree (with the exception of the root node). Default 1. */
     98  INT_PARAM_THREADS             = 9,  /*! Number of threads that can be used in the branch-and-bound method.*/
    9999  INT_PARAM_CUT_PASS            = 10, /*! Number of cut passes in the root node. Default -1, solver decides */
    100100  INT_PARAM_LOG_LEVEL           = 11, /*! Verbosity level, from 0 to 2 */
    101101  INT_PARAM_MAX_SAVED_SOLS      = 12, /*! Size of the pool to save the best solutions found during the search. */
    102   INT_PARAM_MULTIPLE_ROOTS      = 13 /*! Multiple root passes to get additional cuts and solutions. */
     102  INT_PARAM_MULTIPLE_ROOTS      = 13, /*! Multiple root passes to get additional cuts and solutions. */
     103  INT_PARAM_ROUND_INT_VARS      = 14  /*! If integer variables should be round to remove small infeasibilities. This can increase the overall amount of infeasibilities in problems with both continuous and integer variables */
    103104};
    104 #define N_INT_PARAMS 14
     105#define N_INT_PARAMS 15
    105106 
    106107/** typedef for cbc callback to monitor the progress of the search
Note: See TracChangeset for help on using the changeset viewer.