Changeset 1361


Ignore:
Timestamp:
Dec 4, 2009 5:15:40 PM (10 years ago)
Author:
bjarni
Message:

Added Lou's annotations to Cbc_ampl.cpp, CbcSolver?.cpp, CbcSolver?.hpp, CbcStrategy?.cpp, CbcTreeLocal?.cpp, ClpAmplStuff?.cpp, CoinSolve?.cpp, and unitTestClp.cpp

Location:
branches/sandbox/Cbc/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/Cbc/src/CbcSolver.cpp

    r1336 r1361  
    22// Copyright (C) 2007, International Business Machines
    33// Corporation and others.  All Rights Reserved.
     4
     5/*! \file CbcSolver.cpp
     6    \brief Second level routines for the cbc stand-alone solver.
     7*/
    48
    59#include "CbcConfig.h"
     
    535539        delete clpSolver;
    536540}
     541
     542/*
     543  Initialise a subset of the parameters prior to processing any input from
     544  the user.
     545
     546  Why this choice of subset?
     547*/
     548/*!
     549  \todo Guard/replace clp-specific code
     550*/
    537551void CbcSolver::fillValuesInSolver()
    538552{
    539553    OsiSolverInterface * solver = model_.solver();
    540     OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver);
     554    OsiClpSolverInterface * clpSolver =
     555                dynamic_cast< OsiClpSolverInterface*> (solver);
    541556    assert (clpSolver);
    542     noPrinting_ = (clpSolver->getModelPtr()->logLevel() == 0);
     557        ClpSimplex * lpSolver = clpSolver->getModelPtr();
     558
     559    /*
     560      Why are we reaching into the underlying solver(s) for these settings?
     561      Shouldn't CbcSolver have its own defaults, which are then imposed on the
     562      underlying solver?
     563
     564      Coming at if from the other side, if CbcSolver had the capability to use
     565      multiple solvers then it definitely makes sense to acquire the defaults from
     566      the solver (on the assumption that we haven't processed command line
     567      parameters yet, which can then override the defaults). But then it's more of
     568      a challenge to avoid solver-specific coding here.
     569    */
     570    noPrinting_ = (lpSolver->logLevel() == 0);
    543571    CoinMessageHandler * generalMessageHandler = clpSolver->messageHandler();
    544572    generalMessageHandler->setPrefix(true);
    545     ClpSimplex * lpSolver = clpSolver->getModelPtr();
    546     lpSolver->setPerturbation(50);
     573
     574        lpSolver->setPerturbation(50);
    547575    lpSolver->messageHandler()->setPrefix(false);
     576
    548577    parameters_[whichParam(DUALBOUND, numberParameters_, parameters_)].setDoubleValue(lpSolver->dualBound());
    549578    parameters_[whichParam(DUALTOLERANCE, numberParameters_, parameters_)].setDoubleValue(lpSolver->dualTolerance());
     579    /*
     580      Why are we doing this? We read the log level from parameters_, set it into
     581      the message handlers for cbc and the underlying solver. Then we read the
     582      log level back from the handlers and use it to set the values in
     583      parameters_!
     584    */
    550585    int iParam = whichParam(SOLVERLOGLEVEL, numberParameters_, parameters_);
    551586    int value = parameters_[iParam].intValue();
  • branches/sandbox/Cbc/src/CbcSolver.hpp

    r1286 r1361  
    22// Copyright (C) 2007, International Business Machines
    33// Corporation and others.  All Rights Reserved.
     4
     5/*! \file CbcSolver.hpp
     6    \brief Defines CbcSolver, the top-level class for the new-style cbc solver.
     7*/
     8
    49#ifndef CbcSolver_H
    510#define CbcSolver_H
     
    2126//#############################################################################
    2227
    23 /** This allows the use of the standalone solver in a flexible manner
    24     It has an original OsiClpSolverInterface and CbcModel which
    25     it can use repeatedly e.g. get a heuristic solution and then start again
    26 
    27     So I will need a primitive scripting language which can then call solve
    28     and manipulate solution value and solution arrays.
    29 
     28/*! \brief This allows the use of the standalone solver in a flexible manner.
     29
     30    It has an original OsiClpSolverInterface and CbcModel which it can use
     31    repeatedly, e.g., to get a heuristic solution and then start again.
     32
     33    So I [jjf] will need a primitive scripting language which can then call
     34    solve and manipulate solution value and solution arrays.
     35
     36    Also provides for user callback functions. Currently two ideas in
     37    gestation, CbcUser and CbcStopNow. The latter seems limited to deciding
     38    whether or not to stop. The former seems completely general, with a notion
     39    of importing and exporting, and a `solve', which should be interpreted as
     40    `do whatever this user function does'.
     41
     42    Parameter initialisation is at last centralised in fillParameters().
    3043*/
    3144
    32 class CbcSolver  {
     45class CbcSolver {
    3346
    3447public:
     
    7285    /// Fill with standard parameters
    7386    void fillParameters();
    74     /// Set default values in solvers from parameters
     87    /*! \brief Set default values in solvers from parameters
     88
     89      Misleading. The current code actually reads default values from
     90      the underlying solvers and installs them as default values for a subset of
     91      parameters in #parameters_.
     92    */
    7593    void fillValuesInSolver();
    7694    /// Add user function
     
    207225};
    208226//#############################################################################
     227
    209228/// Structure to hold useful arrays
    210229typedef struct {
     
    222241    double * pseudoUp_;
    223242} CbcSolverUsefulData;
    224 /** This allows the use of an unknown user stuff including modeling languages
    225  */
    226 
    227 class CbcUser  {
     243
     244
     245/*! \brief A class to allow the use of unknown user functionality
     246
     247    For example, access to a modelling language (CbcAmpl).
     248*/
     249class CbcUser {
    228250
    229251public:
    230252    ///@name import/export methods
    231253    //@{
    232     /** Import - gets full command arguments
    233         Returns -1 - no action
    234                  0 - data read in without error
    235              1 - errors
     254    /*! \brief Import - gets full command arguments
     255
     256      \return
     257      - -1 - no action
     258      -  0 - data read in without error
     259      -  1 - errors
    236260    */
    237261    virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
    238262        return -1;
    239263    }
    240     /// Export 1 OsiClpSolver, 2 CbcModel - add 10 if infeasible from odd situation
     264
     265    /*! \brief Export
     266
     267      \param mode
     268      - 1 OsiClpSolver
     269      - 2 CbcModel
     270      - add 10 if infeasible from odd situation
     271    */
    241272    virtual void exportSolution(CbcSolver * /*model*/,
    242273                                int /*mode*/, const char * /*message*/ = NULL) {}
     274
    243275    /// Export Data (i.e. at very end)
    244276    virtual void exportData(CbcSolver * /*model*/) {}
     277
    245278    /// Get useful stuff
    246279    virtual void fillInformation(CbcSolver * /*model*/,
    247280                                 CbcSolverUsefulData & /*info*/) {}
    248 
    249     //@}
     281    //@}
     282
    250283    ///@name usage methods
    251284    //@{
    252285    /// CoinModel if valid
    253     inline CoinModel * coinModel() const {
     286    inline CoinModel *coinModel() const {
    254287        return coinModel_;
    255288    }
     
    267300    virtual bool canDo(const char * options) = 0;
    268301    //@}
     302
    269303    ///@name Constructors and destructors etc
    270304    //@{
     
    272306    CbcUser();
    273307
    274     /** Copy constructor .
    275      */
     308    /// Copy constructor
    276309    CbcUser(const CbcUser & rhs);
    277310
     
    300333//#############################################################################
    301334
    302 /** This allows the use of a call back class to decide whether to stop
    303  */
    304 
    305 class CbcStopNow  {
     335/*! \brief Support the use of a call back class to decide whether to stop
     336
     337  Definitely under construction.
     338*/
     339
     340class CbcStopNow {
    306341
    307342public:
    308343    ///@name Decision methods
    309344    //@{
    310     /// Import - 0 if good
    311     /** Meaning of whereFrom:
    312        1 after initial solve by dualsimplex etc
    313        2 after preprocessing
    314        3 just before branchAndBound (so user can override)
    315        4 just after branchAndBound (before postprocessing)
    316        5 after postprocessing
    317        6 after a user called heuristic phase
     345    /*! \brief Import
     346
     347      \param whereFrom
     348       - 1 after initial solve by dualsimplex etc
     349       - 2 after preprocessing
     350       - 3 just before branchAndBound (so user can override)
     351       - 4 just after branchAndBound (before postprocessing)
     352       - 5 after postprocessing
     353       - 6 after a user called heuristic phase
     354
     355      \return 0 if good
    318356       nonzero return code to stop
    319357    */
    320     virtual int callBack(CbcModel * /*currentSolver*/,
    321                          int /*whereFrom*/) {
     358    virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
    322359        return 0;
    323360    }
    324361    //@}
     362
    325363    ///@name Constructors and destructors etc
    326364    //@{
  • branches/sandbox/Cbc/src/CbcStrategy.cpp

    r1357 r1361  
    141141    // Set up some cut generators and defaults
    142142    // Probing first as gets tight bounds on continuous
    143     // See flags for Probing, Gomory, Knapsack, Clique, FlowCover, MixedIntegerRounding2 below
     143    // See flags for Probing, Gomory, Knapsack, Clique, FlowCover, MixedIntegerRounding2 below (BK: lou removed this comment, why??)
    144144    int genFlags = 63;
    145145    //#define CBC_GENERATE_TEST
     
    332332    }
    333333}
     334
     335/*
     336 Aside from setting CbcModel::numberStrong_ and numberBeforeTrust, the big
     337 activity is integer preprocessing. Surely this code to do preprocessing
     338 duplicates code to do preprocessing up in the solver main routine. Most of the
     339 effort goes into manipulating SOS sets.
     340*/
    334341// Other stuff e.g. strong branching
    335342void
     
    339346    if (desiredPreProcess_) {
    340347        delete process_;
     348        /*
     349          Inaccurate as of 080122 --- assignSolver (below) can now be instructed not to
     350          delete the existing solver when the preprocessed solver is assigned to the
     351          model. 'Course, we do need to hold on to a pointer somewhere, and that must
     352          be captured before this call.
     353        */
    341354        // solver_ should have been cloned outside
    342355        CglPreProcess * process = new CglPreProcess();
     
    414427            memset(prohibited, 0, numberColumns);
    415428            int numberProhibited = 0;
     429            /*
     430              Create CbcSimpleInteger objects would be more accurate in the general
     431              case.  The `false' parameter says we won't delete existing objects.
     432
     433              Only Clp will produce SOS objects in findIntegers (080122), and that's
     434              where a possible conversion can occur. If clp is holding OsiSOS objects,
     435              they'll be converted to CbcSOS objects.
     436            */
    416437            // convert to Cbc integers
    417438            model.findIntegers(false);
  • branches/sandbox/Cbc/src/CbcTreeLocal.cpp

    r1286 r1361  
    747747            int iColumn = integerVariable[i];
    748748            double value = floor(solution[iColumn] + 0.5);
     749            /*
     750              typeCuts_ == 0 restricts to binary, 1 allows general integer. But we're
     751              still restricted to being up against a bound. Consider: the notion is that
     752              the cut restricts us to a k-neighbourhood. For binary variables, this
     753              amounts to k variables which change value. For general integer, we could
     754              end up with a single variable sucking up all of k (hence mu --- the
     755              variable must swing to its other bound to look like a movement of 1).  For
     756              variables in the middle of a range, we're talking about fabs(sol<j> - x<j>).
     757            */
    749758            if (!typeCuts_ && originalUpper_[i] - originalLower_[i] > 1.0)
    750759                continue; // skip as not 0-1
  • branches/sandbox/Cbc/src/Cbc_ampl.cpp

    r1289 r1361  
    2424THIS SOFTWARE.
    2525****************************************************************/
     26
     27/*! \file Cbc_ampl.cpp
     28
     29  Interface routines for AMPL.
     30*/
     31
    2632#ifdef COIN_HAS_ASL
    2733
     
    345351    }
    346352}
     353
    347354int
    348355readAmpl(ampl_info * info, int argc, char **argv, void ** coinModel)
  • branches/sandbox/Cbc/src/ClpAmplStuff.cpp

    r1286 r1361  
    22// Corporation and others.  All Rights Reserved.
    33/* $Id: ClpAmplStuff.cpp 1200 2009-07-25 08:44:13Z forrest $ */
     4
     5/*! \file ClpAmplStuff.cpp
     6    \brief Hooks to Ampl (for the new-style solver?)
     7*/
    48
    59#include "ClpConfig.h"
     
    2428#include "CoinModel.hpp"
    2529#include "CbcLinked.hpp"
     30
     31/*! \brief Extension of CbcUser for Ampl.
     32
     33  Beyond that, can't say yet what this does. A CbcAmpl object can be installed
     34  in a CbcSolver object using CbcSolver::addUserFunction.
     35*/
     36
    2637class CbcAmpl  : public CbcUser {
    2738
     
    2940    ///@name usage methods
    3041    //@{
     42
    3143    /// Solve (whatever that means)
    3244    virtual void solve(CbcSolver * model, const char * options);
    33     /// Returns true if function knows about option
    34     virtual bool canDo(const char * options) ;
    35     /** Import - gets full command arguments
    36         Returns -1 - no action
    37                  0 - data read in without error
    38              1 - errors
     45
     46    /*! \brief Returns true if function knows about option
     47
     48      Currently knows about
     49        - cbc_load
     50        - cbc_quit
     51    */
     52    virtual bool canDo(const char * option) ;
     53
     54    /*! \brief Import - gets full command arguments
     55
     56      \return
     57      - -1 - no action
     58      -  0 - data read in without error
     59      -  1 - errors
    3960    */
    4061    virtual int importData(CbcSolver * model, int & argc, char ** & argv);
    41     /// Export 1 OsiClpSolver, 2 CbcModel - add 10 if infeasible from odd situation
     62
     63    /*! \brief Export
     64
     65      \param mode
     66      - 1 OsiClpSolver
     67      - 2 CbcModel
     68      - add 10 if infeasible from odd situation
     69    */
    4270    virtual void exportSolution(CbcSolver * model, int mode, const char * message = NULL) ;
    4371    /// Export Data (i.e. at very end)
     
    120148// Returns true if function knows about option
    121149bool
    122 CbcAmpl::canDo(const char * options)
    123 {
    124     return (!strcmp(options, "cbc_load") || !strcmp(options, "cbc_quit"));
     150CbcAmpl::canDo(const char * option)
     151{
     152    return (!strcmp(option, "cbc_load") || !strcmp(option, "cbc_quit"));
    125153}
    126154/* Import - gets full command arguments
     
    135163    assert (babModel);
    136164    CoinMessageHandler * generalMessageHandler = babModel->messageHandler();
    137     OsiClpSolverInterface * solver = dynamic_cast< OsiClpSolverInterface*> (control->model()->solver());
     165    OsiClpSolverInterface * solver =
     166        dynamic_cast< OsiClpSolverInterface*> (control->model()->solver());
    138167    assert (solver);
    139168    CoinMessages generalMessages = solver->getModelPtr()->messages();
    140169    char generalPrint[10000];
    141170    OsiSolverLink * si = NULL;
     171    /*
     172      Poke through the arguments looking for a log level. If we find it, write it
     173      into the info block we'll use to load from AMPL, and set a magic number to
     174      indicate the log level is valid.
     175
     176      This looks brittle, in several different directions.
     177    */
    142178    ClpSimplex * lpSolver = solver->getModelPtr();
    143179    if (argc > 2 && !strcmp(argv[2], "-AMPL")) {
  • branches/sandbox/Cbc/src/CoinSolve.cpp

    r1286 r1361  
    22// Copyright (C) 2007, International Business Machines
    33// Corporation and others.  All Rights Reserved.
     4
     5/*! \file CbcSolver.cpp
     6    \brief Main routine for the cbc stand-alone solver.
     7*/
    48
    59#include "CbcConfig.h"
     
    812#include "CbcOrClpParam.hpp"
    913#include "OsiClpSolverInterface.hpp"
     14
     15/*
     16  We have the following compile-time symbols.
     17
     18  NEW_STYLE_SOLVER      CoinSolve.cpp, CbcSolver.cpp
     19
     20    Unclear what this does just yet. A value of 0 seems to be `old style
     21    solver'.
     22
     23
     24  CBC_OTHER_SOLVER      CoinSolve.cpp, CbcSolver.[cpp,hpp], CbcModel.cpp
     25
     26    Usage in CbcSolver.hpp says `other solver' is Cplex (only).
     27
     28    Here in CoinSolver, CBC_OTHER_SOLVER dominates NEW_STYLE_SOLVER.
     29
     30    Usage in CbcModel is a fake; a small bit of code that's now `#if 0'.
     31
     32
     33  CPX_KEEP_RESULTS      CoinSolve.cpp, CbcSolver.cpp
     34
     35    Unclear what this does just yet. The name seems clear, but how / what is
     36    affected is not. Defining this symbol forces CBC_OTHER_SOLVER.
     37
     38
     39  CLP_DEBUG_MALLOC
     40
     41    This ties in with the functions clp_malloc, clp_free, and clp_memory,
     42    which are defined in CoinOslFactorization.cpp. (Right where you'd expect
     43    to find them, eh?).  Looks to be a relatively nice debugging wrapper for
     44    standard C malloc.  Calls standard C malloc/free directly if
     45    CLP_DEBUG_MALLOC is not defined.  Worth consideration for breaking out as
     46    a separate utility.  The hooks for new and delete defined here should be
     47    incorporated.
     48
     49    Absolutely not thread safe --- lots of static variables.
     50
     51    Hmmm ... is it still the case that standard C malloc and C++ new/delete
     52    do not play well together? 'Cause the hooks here for new and delete will
     53    not escape from this file.
     54
     55*/
     56
     57
     58/*
     59  Allow (force?) use of cplex for something.
     60*/
     61
    1062#ifdef CPX_KEEP_RESULTS
    1163#define CBC_OTHER_SOLVER 1
     
    1466#include "OsiCpxSolverInterface.hpp"
    1567#endif
     68
     69/*
     70  Hooks for a debugging wrapper for malloc/free. This bit of definition hooks
     71  C++ new / delete and diverts them into the debugging wrapper.
     72*/
    1673//#define CLP_DEBUG_MALLOC
    1774#ifdef CLP_DEBUG_MALLOC
     
    3390    clp_free(p);
    3491}
    35 #endif
     92#endif          // CLP_DEBUG_MALLOC
    3693
    3794#include <cassert>
     
    4198#include <cstring>
    4299#include <iostream>
     100
     101/*
     102  The subtleties are unclear, but the gross action is that CBC_OTHER_SOLVER
     103  will overrule NEW_STYLE_SOLVER. NEW_STYLE_SOLVER undefined or 0 seems to
     104  mean `old style solver'.
     105*/
    43106#ifndef NEW_STYLE_SOLVER
    44 #define NEW_STYLE_SOLVER 0
     107 #define NEW_STYLE_SOLVER 0
    45108#endif
    46109#ifdef CBC_OTHER_SOLVER
    47 #undef NEW_STYLE_SOLVER
    48 #define NEW_STYLE_SOLVER 0
    49 #endif
    50 #if NEW_STYLE_SOLVER==0
     110 #undef NEW_STYLE_SOLVER
     111 #define NEW_STYLE_SOLVER 0
     112#endif
     113
     114
     115
     116#if NEW_STYLE_SOLVER == 0
    51117// define TEST_MESSAGE_HANDLER to check works on all messages
    52 //#define TEST_MESSAGE_HANDLER
     118// #define TEST_MESSAGE_HANDLER
    53119#ifdef TEST_MESSAGE_HANDLER
    54120// This driver shows how to trap messages - this is just as in unitTest.cpp
     
    61127
    62128    The file pointer is just there as an example of user stuff.
     129
     130  -- lh 071026 -- An accurate summary. Nothing is actually happening here
     131  except that messages will be prefixed with "==", which serves the purpose
     132  of demonstrating that this message handler is active. The extra parameters
     133  (CbcModel, FILE) are unused.
    63134
    64135*/
     
    193264    model_ = model;
    194265}
    195 #endif
     266#endif /* TEST_MESSAGE_HANDLER */
     267
    196268//#############################################################################
     269
    197270// To use USERCBC or USERCLP change 0 to 1 in defines and add in your fake main program(s) and any other code
    198271//#define USER_HAS_FAKE_CBC
    199272//#define USER_HAS_FAKE_CLP
     273
    200274#ifdef USER_HAS_FAKE_CBC
    201275#endif
     
    212286#endif
    213287}
     288
    214289// Clp stuff
    215290#ifdef USER_HAS_FAKE_CLP
     
    228303}
    229304//  End any fake main program
     305
    230306//#############################################################################
     307
    231308// void CbcClpUnitTest (const CbcModel & saveModel);
     309
    232310#ifdef CBC_STATISTICS
    233311int osi_crunch = 0;
     
    247325}
    248326#endif
     327
    249328int main (int argc, const char *argv[])
    250329{
     
    260339#endif
    261340        CbcModel model(solver1);
     341
    262342        // define TEST_MESSAGE_HANDLER at top of file to check works on all messages
    263343#ifdef TEST_MESSAGE_HANDLER
     
    270350        //clpSolver->getModelPtr()->passInMessageHandler(&messageHandler);
    271351#endif
     352
    272353        // initialize
    273354        CbcMain0(model);
     355
    274356#ifdef TEST_MESSAGE_HANDLER
    275357        // Set log levels same so can use one message handler
     
    280362        setCbcOrClpPrinting(false);
    281363#endif
     364
    282365        returnCode = CbcMain1 (argc, argv, model);
    283366    }
     367
    284368#ifdef CLP_DEBUG_MALLOC
    285369    clp_memory(1);
    286370#endif
     371
    287372#ifdef CBC_STATISTICS
    288373#endif
     374
    289375    if (returnCode != 777) {
    290376        return returnCode;
     
    293379    }
    294380}
    295 #else
     381
     382
     383
     384#else   /* NEW_STYLE_SOLVER */
     385
     386/*
     387  As best I can see, this is not yet fully functional. NEW_STYLE_SOLVER is
     388  normally undefined or forced to 0. See CbcSolver.hpp for jjf's thoughts on
     389  where this is going (a good direction, in my opinion [lh]).
     390*/
     391
    296392#include "CbcSolver.hpp"
     393
     394/*
     395  ClpAmplStuff.cpp
     396*/
    297397void addAmplToCbc(CbcSolver *);
     398
    298399int main (int argc, const char *argv[])
    299400{
    300401    int returnCode;
    301     // Only active if malloc switched on in CbcSolver.cpp
     402
     403    /*
     404      // Only active if malloc switched on in CbcSolver.cpp
     405
     406      Magic value 0 initialises the package. Anything else dumps statistics.
     407    */
    302408#ifdef CLP_DEBUG_MALLOC
    303409    clp_memory(0);
    304410#endif
     411
     412    // Open a block to ease memory leak checks.
    305413    {
    306414        OsiClpSolverInterface solver1;
     
    308416        // initialize
    309417        control.fillValuesInSolver();
     418
    310419#ifdef COIN_HAS_ASL
    311420        addAmplToCbc(&control);
    312421#endif
     422
    313423        returnCode = control.solve (argc, argv, 1);
    314424    }
     
    318428    return returnCode;
    319429}
    320 #endif
     430
     431#endif  /* NEW_STYLE_SOLVER */
     432
     433
     434
    321435/*
    322436  Version 1.00.00 November 16 2005.
  • branches/sandbox/Cbc/src/unitTestClp.cpp

    r1315 r1361  
    276276
    277277            /*
    278             Stage 2: Call solver to solve the problem.
    279             then check the return code and objective.
     278              Stage 2: Call solver to solve the problem.  then check the return code and
     279                  objective.
    280280            */
    281281
     
    692692            delete model;
    693693        }
    694     }
     694    }   // end main loop on MPS problem
    695695    int returnCode = 0;
    696696    std::cout
Note: See TracChangeset for help on using the changeset viewer.