Changeset 591 for branches


Ignore:
Timestamp:
Mar 30, 2007 5:12:48 PM (12 years ago)
Author:
lou
Message:

Initial commit of cbc-generic source.

Location:
branches/devel/Cbc/src
Files:
14 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/src/CbcGeneric.cpp

    r519 r591  
    1 // copyright (C) 2002, International Business Machines
    2 // Corporation and others.  All Rights Reserved.
     1/*
     2  Copyright (C) 2007, Lou Hafer, International Business Machines Corporation
     3  and others.  All Rights Reserved.
     4
     5  This file is part of cbc-generic.
     6*/
    37
    48#include "CbcConfig.h"
     
    5559#include "CbcGenOsiParam.hpp"
    5660
    57 namespace CbcSolvers
     61namespace CbcGenSolvers
    5862{
    5963  OsiSolverInterface *setupSolvers() ;
     
    121125*/
    122126  CbcGenCtlBlk ctlBlk ;
    123   OsiSolverInterface *dfltSolver = CbcSolvers::setupSolvers() ;
     127  OsiSolverInterface *dfltSolver = CbcGenSolvers::setupSolvers() ;
    124128  ctlBlk.dfltSolver_ = dfltSolver ;
    125129  assert (ctlBlk.dfltSolver_) ;
    126   dfltSolver->messageHandler()->setLogLevel(0) ;
    127   CbcOsiParamUtils::setOsiSolverInterfaceDefaults(dfltSolver) ;
    128130/*
    129131  Now we can begin to initialise the parameter vector. Create a vector of the
     
    189191  bool forceImport = false ;
    190192  std::string forceImportFile = "" ;
     193  std::string prompt = "cbcGen: " ;
     194  std::string pfx = "" ;
    191195  while (keepParsing)
    192   { std::string paramName = CoinParamUtils::getCommand(argc,argv);
     196  { std::string paramName = CoinParamUtils::getCommand(argc,argv,prompt,&pfx);
    193197    if (paramName.length() == 0)
    194198    { if (ctlBlk.paramsProcessed_ == 0)
     
    207211        if (ctlBlk.goodModel_ == true &&
    208212            ctlBlk.bab_.majorStatus_ == CbcGenCtlBlk::BACNotRun)
    209         { paramName = "branchAndCut" ; } } }
     213        { paramName = "branchAndCut" ;
     214          pfx = "-" ; } } }
    210215    if (paramName == "")
    211216    { continue ; }
    212217/*
    213   Do we have a parameter we recognise? If matchNdx is positive, we have a
    214   unique parameter match and we can get on with processing. If the return value
    215   is negative, and we're not interactive, quit. If we're interactive, react
    216   as appropriate:
     218  Do we have a parameter we recognise? In command line mode, if there was no
     219  prefix (either `-' or `--'), the user didn't intend this as a command
     220  keyword.
     221*/
     222    int matchNdx ;
     223    if (!CoinParamUtils::isCommandLine() || pfx == "-" || pfx == "--")
     224    { matchNdx = CoinParamUtils::lookupParam(paramName,paramVec) ; }
     225    else
     226    { matchNdx = -3 ; }
     227    std::cout
     228      << "Command is `" << paramName
     229      << "', pfx `" << pfx
     230      << "', match = " << matchNdx << std::endl ;
     231/*
     232  If matchNdx is positive, we have a unique parameter match and we can get on
     233  with processing. If the return value is negative, and we're not
     234  interactive, quit. If we're interactive, react as appropriate:
    217235    -1: There was a `?' in the command string. Prompt again.
    218236    -2: No `?', and one or more short matches. Prompt again.
    219237    -3: No `?', but we didn't match anything either. If we're in command line
    220         mode, try forcing `import' (but just once, eh). This is the other
    221         piece required to get `cbc-generic [parameters] foo.mps' to work as
    222         expected.) In interactive mode, we'll require the user to say `import'.
    223         Interactive mode and no history of successful commands gets the help
    224         message.
     238        mode, and there was no `-' or `--' prefix, try forcing `import' (but
     239        just once, eh). This is the other piece required to get `cbc-generic
     240        [parameters] foo.mps' to work as expected.) In interactive mode,
     241        we'll require the user to say `import'.  Interactive mode and no
     242        history of successful commands gets the help message.
    225243    -4: Configuration error, offer `report to maintainers' message.
    226244*/
    227     int matchNdx = CoinParamUtils::lookupParam(paramName,paramVec) ;
    228245    if (matchNdx < 0)
    229246    { if (matchNdx == -3)
    230       { if (!CoinParamUtils::isInteractive())
     247      { if (CoinParamUtils::isCommandLine() && pfx == "")
    231248        { if (!forceImport)
    232249          { forceImportFile = paramName ;
     
    267284      case CoinParam::coinParamInt:
    268285      { int ival = CoinParamUtils::getIntField(argc,argv,&valid) ;
    269         if (valid != 2)
     286        if (valid == 0)
    270287        { param->setIntVal(ival) ; }
    271288        break ; }
    272289      case CoinParam::coinParamDbl:
    273290      { double dval = CoinParamUtils::getDoubleField(argc,argv,&valid) ;
    274         if (valid != 2)
     291        if (valid == 0)
    275292        { param->setDblVal(dval) ; }
    276293        break ; }
     
    281298        { const std::string tmp =
    282299                CoinParamUtils::getStringField(argc,argv,&valid) ;
    283           if (valid != 2)
     300          if (valid == 0)
    284301          { param->setStrVal(tmp) ; } }
    285302        break ; }
     
    287304      { const std::string tmp =
    288305                CoinParamUtils::getStringField(argc,argv,&valid) ;
    289         if (valid != 2)
     306        if (valid == 0)
    290307        { param->setKwdVal(tmp) ;
    291308          if (param->kwdVal() != tmp)
     
    294311              << param->name() << std::endl ;
    295312            param->printKwds() ;
    296             std::cout << std::endl ; } }
     313            std::cout << std::endl ;
     314            valid = 1 ; } }
    297315        break ; }
    298316      default:
     
    300318        break ; } }
    301319/*
     320  Deal with missing or incorrect values.
     321
    302322  If valid came back as 2, we're short a parameter. This is interpreted as a
    303   request to tell the user the current value. Note that this will never happenf
    304   for an action parameter.
    305 */
    306     if (valid == 2)
    307     { std::cout
    308         << "Current value of " << param->name() << " parameter is `"
    309         << *param << "'." << std::endl ;
     323  request to tell the user the current value.  If valid came back as 1, we
     324  had some sort of parse error. Print an error message.
     325*/
     326    if (valid != 0)
     327    { switch (valid)
     328      { case 1:
     329        { std::cout
     330            << "Could not parse the value given for parameter `"
     331            << param->name() << "'." << std::endl ;
     332          break ; }
     333        case 2:
     334        { std::cout
     335            << "Current value of " << param->name() << " parameter is `"
     336            << *param << "'." << std::endl ;
     337          break ; }
     338        default:
     339        { std::cout
     340            << "Parse status is " << valid
     341            << "; this indicates internal confusion." << std::endl
     342            << "Please report this error by filing a ticket at "
     343            << "https://projects.coin-or.org/Cbc/wiki."
     344            << std::endl ; } }
     345      keepParsing = CoinParamUtils::isInteractive() ;
    310346      continue ; }
    311347/*
     
    327363*/
    328364    ctlBlk.dfltSolver_ = 0 ;
    329     CbcSolvers::deleteSolvers() ;
     365    CbcGenSolvers::deleteSolvers() ;
    330366    for (int i = 0 ; i < paramVec.size() ; i++)
    331367    { if (paramVec[i] != 0) delete paramVec[i] ; }
Note: See TracChangeset for help on using the changeset viewer.