Changeset 2384 for trunk


Ignore:
Timestamp:
Dec 24, 2018 11:07:36 AM (10 months ago)
Author:
forrest
Message:

Allow a strategy for initial solve where code analyzes problem and guesses at parameters

Location:
trunk/Clp/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/CbcOrClpParam.cpp

    r2374 r2384  
    12411241extern int CbcOrClpRead_mode;
    12421242int CbcOrClpEnvironmentIndex = -1;
     1243// Alternative to environment
     1244char * alternativeEnvironment = NULL;
    12431245static size_t fillEnv()
    12441246{
     
    12471249#else
    12481250     // Don't think it will work on Windows
    1249      char * environ = getenv("CBC_CLP_ENVIRONMENT");
     1251     char * environ;
     1252     if (!alternativeEnvironment)
     1253       environ = getenv("CBC_CLP_ENVIRONMENT");
     1254     else
     1255       environ = alternativeEnvironment;
    12501256     size_t length = 0;
    12511257     if (environ) {
     
    12751281          }
    12761282     }
    1277      if (!length)
     1283     if (!length) {
    12781284          CbcOrClpEnvironmentIndex = -1;
     1285          if (alternativeEnvironment) {
     1286            delete [] alternativeEnvironment;
     1287            alternativeEnvironment = NULL;
     1288          }
     1289     }
    12791290     return length;
    12801291#endif
     
    24782489 is initialized to 'stdout' (this defaults to ordinary solution if stdout). \
    24792490If problem created from gmpl model - will do any reports."
     2491     );
     2492     parameters[numberParameters++] =
     2493          CbcOrClpParam("guess", "Guesses at good parameters",
     2494                        CLP_PARAM_ACTION_GUESS, 7);
     2495     parameters[numberParameters-1].setLonghelp
     2496     (
     2497          "This looks at model statistics and does an initial solve \
     2498setting some parameters which may help you to think of possibilities."
    24802499     );
    24812500#ifdef COIN_HAS_CBC
  • trunk/Clp/src/CbcOrClpParam.hpp

    r2371 r2384  
    277277     CLP_PARAM_ACTION_GMPL_SOLUTION,
    278278     CLP_PARAM_ACTION_RESTORESOL,
     279     CLP_PARAM_ACTION_GUESS,
    279280
    280281     CBC_PARAM_ACTION_BAB = 501,
  • trunk/Clp/src/ClpSimplexOther.cpp

    r2380 r2384  
    1059410594  delete info;
    1059510595}
     10596// Create a string of commands to guess at best strategy for model
     10597// At present mode is ignored
     10598char *
     10599ClpSimplexOther::guess(int mode) const
     10600{
     10601  if (!numberColumns_) {
     10602    handler_->message(CLP_GENERAL, messages_)
     10603      << "Null model" << CoinMessageEol;
     10604    return NULL;
     10605  }
     10606  char * environment = new char [100];
     10607  double * obj = CoinCopyOfArray(objective(),numberColumns_);
     10608  std::sort(obj,obj+numberColumns_);
     10609  bool allInt=true;
     10610  double average = 0.0;
     10611  double median = obj[numberColumns_/2];
     10612  for (int i=0;i<numberColumns_;i++) {
     10613    if (!isInteger(i))
     10614      allInt=false;
     10615    average += obj[i];
     10616  }
     10617  delete [] obj;
     10618  average /= numberColumns_;
     10619  if (allInt) {
     10620    if (average <= 0.009)
     10621      sprintf(environment,"-idiot 60 -primals");
     10622    else
     10623      sprintf(environment,"-idiot 30 -pertvalue -1483 -primals");
     10624  } else {
     10625    if (median <= 0.75)
     10626      sprintf(environment,"-dualpivot pesteep -psi -1.0 -pertv 52 -duals");
     10627    else
     10628      sprintf(environment,"-idiot 80 -primals");
     10629  }
     10630  char line[140];
     10631  sprintf(line,"%s %s","Commands generated by guess -",environment);
     10632  handler_->message(CLP_GENERAL, messages_)
     10633    << line << CoinMessageEol;
     10634  return environment;
     10635}
  • trunk/Clp/src/ClpSimplexOther.hpp

    r2070 r2384  
    273273                        double * buildObj, CoinBigIndex * buildStart,
    274274                        int * buildRow, double * buildElement, int reConstruct = -1) const;
     275     /// Create a string of commands to guess at best strategy for model
     276     /// At present mode is ignored
     277     char * guess(int mode) const;
    275278     //@}
    276279};
  • trunk/Clp/src/ClpSolver.cpp

    r2383 r2384  
    135135int CbcOrClpRead_mode = 1;
    136136FILE * CbcOrClpReadCommand = stdin;
     137// Alternative to environment
     138extern char * alternativeEnvironment;
    137139extern int CbcOrClpEnvironmentIndex;
    138140#ifdef CLP_USER_DRIVEN1
     
    29382940                         case CLP_PARAM_ACTION_ENVIRONMENT:
    29392941                              CbcOrClpEnvironmentIndex = 0;
     2942                              break;
     2943                         case CLP_PARAM_ACTION_GUESS:
     2944                              if (goodModels[iModel]) {
     2945                                delete [] alternativeEnvironment;
     2946                                ClpSimplexOther * model2 =
     2947                                  static_cast<ClpSimplexOther *> (models+iModel);
     2948                                alternativeEnvironment =
     2949                                  model2->guess(0);
     2950                                if (alternativeEnvironment)
     2951                                  CbcOrClpEnvironmentIndex = 0;
     2952                                else
     2953                                   std::cout << "** Guess unable to generate commands" << std::endl;
     2954                              } else {
     2955                                   std::cout << "** Guess needs a valid model" << std::endl;
     2956                              }
    29402957                              break;
    29412958                         default:
Note: See TracChangeset for help on using the changeset viewer.