Changeset 530


Ignore:
Timestamp:
May 4, 2007 12:38:18 PM (12 years ago)
Author:
ladanyi
Message:

prepare Bcp for changing some LPs into TM storage places. Serial version works, currently debugging parallel version.

Location:
trunk/Bonmin/experimental/Bcp
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bonmin/experimental/Bcp/BB_cut.cpp

    r1 r530  
    1 // Copyright (C) 2003, International Business Machines
    2 // Corporation and others.  All Rights Reserved.
    3 // File from COIN project Examples/Bac/BB_cut.cpp
     1// (C) Copyright International Business Machines Corporation 2006, 2007
     2// All Rights Reserved.
     3// This code is published under the Common Public License.
     4//
     5// Authors :
     6// Laszlo Ladanyi, International Business Machines Corporation
     7// Pierre Bonami, Carnegie Mellon University
     8
    49#include "BCP_buffer.hpp"
    510#include "BB_cut.hpp"
    611
    712/****************************************************************************/
     13
     14BB_cut* BB_cut::clone() const
     15{
     16    return new BB_cut(dynamic_cast<const OsiRowCut&>(*this));
     17}
     18
     19/****************************************************************************/
     20
    821void
    922BB_cut::pack(BCP_buffer& buf) const
  • trunk/Bonmin/experimental/Bcp/BB_cut.hpp

    r1 r530  
    1 // Copyright (C) 2003, International Business Machines
    2 // Corporation and others.  All Rights Reserved.
    3 // File from COIN project Examples/Bac/BB_cut.hpp
     1// (C) Copyright International Business Machines Corporation 2006, 2007
     2// All Rights Reserved.
     3// This code is published under the Common Public License.
     4//
     5// Authors :
     6// Laszlo Ladanyi, International Business Machines Corporation
     7// Pierre Bonami, Carnegie Mellon University
     8
    49#ifndef _BB_CUT_H
    510#define _BB_CUT_H
     
    4348    /// Destructor
    4449    ~BB_cut() {}
     50
     51    /// clone
     52    virtual BB_cut* clone() const;
    4553};
    4654
    47 /****************************************************************************/
    48 
    49 static inline void
    50 BB_pack_cut(const BCP_cut_algo* cut, BCP_buffer& buf)
    51 {
    52     const BB_cut* bb_cut = dynamic_cast<const BB_cut*>(cut);
    53     if (!bb_cut)
    54         throw BCP_fatal_error("pack_cut_algo() : unknown cut type!\n");
    55     bb_cut->pack(buf);
    56 }
    57 
    58 static inline BCP_cut_algo*
    59 BB_unpack_cut(BCP_buffer& buf)
    60 {
    61     return new BB_cut(buf);
    62 }
    63 
    64 /****************************************************************************/
    65 
    6655#endif
  • trunk/Bonmin/experimental/Bcp/BM.cpp

    r508 r530  
    131131    return tm;
    132132}
     133
     134/****************************************************************************/
     135
     136BCP_user_pack *
     137BM_init::packer_init(BCP_user_class* p)
     138{
     139    return new BM_pack;
     140}
  • trunk/Bonmin/experimental/Bcp/BM.hpp

    r508 r530  
    1414
    1515#include "BCP_USER.hpp"
     16#include "BCP_parameters.hpp"
    1617#include "BCP_tm_user.hpp"
    1718#include "BCP_lp_user.hpp"
     
    3435    }
    3536    ~BM_node() {}
     37
     38    virtual BM_node* clone() const {
     39        return new BM_node(*this);
     40    }
    3641
    3742    inline void pack(BCP_buffer& buf) const {
     
    131136    virtual void pack_module_data(BCP_buffer& buf, BCP_process_t ptype);
    132137
    133     virtual void pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf) {
    134         BB_pack_cut(cut, buf);
    135     }
    136     virtual BCP_cut_algo* unpack_cut_algo(BCP_buffer& buf) {
    137         return BB_unpack_cut(buf);
    138     }
    139 
    140138    virtual BCP_solution* unpack_feasible_solution(BCP_buffer& buf);
    141 
    142     /// Packing of user data
    143     virtual void pack_user_data(const BCP_user_data* ud, BCP_buffer& buf);
    144 
    145     /// Unpacking of user_data
    146     virtual BCP_user_data* unpack_user_data(BCP_buffer& buf);
    147139    //@}
    148140
     
    166158    virtual void display_feasible_solution(const BCP_solution* sol);
    167159
    168     /** What is the process id of the current process */
    169     const BCP_proc_id*
    170     process_id() const;
    171     /** Send a message to a particular process */
    172     void
    173     send_message(const BCP_proc_id* const target, const BCP_buffer& buf);
    174     /** Broadcast the message to all processes of the given type */
    175     void
    176     broadcast_message(const BCP_process_t proc_type, const BCP_buffer& buf);
    177160    /** Process a message that has been sent by another process' user part to
    178161        this process' user part. */
     
    233216    double cutOffDecrement_;
    234217
    235 #if 0
    236     /* A couple of cut generators to be used in the hybrid method */
    237     CglGomory miGGen_;
    238     CglProbing probGen_;
    239     CglKnapsackCover knapsackGen_;
    240     CglMixedIntegerRounding mixedGen_;
    241     Bonmin::OaNlpOptim oaGen_;
    242     Bonmin::EcpCuts ecpGen_;
    243     Bonmin::OACutGenerator2 oaDec_;
    244     Bonmin::OaFeasibilityChecker feasCheck_;
    245 #endif
    246218    /* FIXME: gross cheating. works only for serial mode. Store the warmstart
    247219       informations in the lp process, do not send them over in user data or
     
    276248    unpack_module_data(BCP_buffer& buf);
    277249
    278     virtual void pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf) {
    279         BB_pack_cut(cut, buf);
    280     }
    281     virtual BCP_cut_algo* unpack_cut_algo(BCP_buffer& buf) {
    282         return BB_unpack_cut(buf);
    283     }
    284 
    285250    virtual void
    286251    pack_feasible_solution(BCP_buffer& buf, const BCP_solution* sol);
    287252
    288     virtual void
    289     pack_user_data(const BCP_user_data* ud, BCP_buffer& buf);
    290     virtual BCP_user_data*
    291     unpack_user_data(BCP_buffer& buf);
    292 
    293     /** What is the process id of the current process */
    294     const BCP_proc_id*
    295     process_id() const;
    296     /** Send a message to a particular process */
    297     void
    298     send_message(const BCP_proc_id* const target, const BCP_buffer& buf);
    299     /** Broadcast the message to all processes of the given type */
    300     void
    301     broadcast_message(const BCP_process_t proc_type, const BCP_buffer& buf);
    302253    /** Process a message that has been sent by another process' user part to
    303254        this process' user part. */
     
    377328#include "BCP_USER.hpp"
    378329
     330class BM_pack : public BCP_user_pack {
     331public:
     332    virtual ~BM_pack() {}
     333
     334    virtual void pack_user_data(const BCP_user_data* ud, BCP_buffer& buf);
     335    virtual BCP_user_data* unpack_user_data(BCP_buffer& buf);
     336
     337    virtual void pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf);
     338    virtual BCP_cut_algo* unpack_cut_algo(BCP_buffer& buf);
     339
     340};
     341
     342
     343//#############################################################################
     344
    379345class BM_init : public USER_initialize {
    380346
     
    386352
    387353    virtual BCP_lp_user * lp_init(BCP_lp_prob& p);
     354
     355    virtual BCP_user_pack * packer_init(BCP_user_class* p);
    388356};
    389357
  • trunk/Bonmin/experimental/Bcp/BM_lp.cpp

    r508 r530  
    1111#include "BCP_message_mpi.hpp"
    1212#include "BCP_lp_node.hpp"
     13#include "BCP_lp.hpp"
    1314
    1415#include "BonOACutGenerator2.hpp"
     
    7172                                       BCP_vec<double>& cut_new_bd)
    7273{
     74    BM_node* data = dynamic_cast<BM_node*>(get_user_data());
     75    if (data) {
     76        numNlpFailed_ = data->numNlpFailed_;
     77    }
     78
    7379    int i;
    7480    // First copy the bounds into nlp. That way all the branching decisions
  • trunk/Bonmin/experimental/Bcp/BM_lp_branch.cpp

    r508 r530  
    99#include "CoinHelperFunctions.hpp"
    1010#include "BCP_lp_node.hpp"
     11#include "BCP_lp.hpp"
    1112#include "BM.hpp"
    1213#include "BonCurvBranching.hpp"
     
    275276//#############################################################################
    276277
    277 const BCP_proc_id*
    278 BM_lp::process_id() const
    279 {
    280 }
    281 
    282 void
    283 BM_lp::send_message(const BCP_proc_id* const target, const BCP_buffer& buf)
    284 {
    285 }
    286 
    287 void
    288 BM_lp::broadcast_message(const BCP_process_t proc_type, const BCP_buffer& buf)
    289 {
    290 }
    291 
    292278void
    293279BM_lp::process_message(BCP_buffer& buf)
  • trunk/Bonmin/experimental/Bcp/BM_pack.cpp

    r508 r530  
    66// Laszlo Ladanyi, International Business Machines Corporation
    77
    8 
    98#include "BM.hpp"
     9#include "BCP_lp.hpp"
    1010
    1111#include "BonAmplSetup.hpp"
     
    7373    std::string nl_content(nl_file_content.c_str());
    7474
    75     /* PIERRE create the setup for algorithm, last argument indicates that continuous relaxation
    76       should not be created.*/
     75    /* PIERRE create the setup for algorithm, last argument indicates that
     76      continuous relaxation should not be created.*/
    7777    bonmin_.initializeBonmin(argv, ipopt_content, nl_content, false);
    7878    bonmin_.nonlinearSolver()->Set_expose_warm_start(true);
    7979    babSolver_.setSolver(bonmin_.nonlinearSolver());
    8080
    81 
    82    
    8381    free(argv[1]);
    8482    if (! get_param(BCP_lp_par::MessagePassingIsSerial) &&
     
    9593    Ipopt::SmartPtr<Ipopt::OptionsList> options = bonmin_.options();
    9694
    97     /* PIERRE This should be already done with new code.
    98     int nlpLogLevel;
    99     options->GetIntegerValue("nlp_log_level", nlpLogLevel, "bonmin.");
    100     nlp_.messageHandler()->setLogLevel(nlpLogLevel);
    101 */
    102     /** update getting options directly from setup*/
    103     double bm_intTol = bonmin_.getDoubleParameter(BabSetupBase::IntTol);
    104     double bm_cutoffIncr = bonmin_.getDoubleParameter(BabSetupBase::CutoffDecr); // could be negative
    105 //PIERRE deprecated    options->GetNumericValue("integer_tolerance",bm_intTol,"bonmin.");
    106 //PIERRE deprecated    options->GetNumericValue("cutoff_decr",bm_cutoffIncr,"bonmin.");
     95    /** update getting options directly from setup and store them in vars
     96        local to the BM_lp object */
     97    integerTolerance_ = bonmin_.getDoubleParameter(BabSetupBase::IntTol);
     98    // cutOffDecrement_ could be negative
     99    cutOffDecrement_ = bonmin_.getDoubleParameter(BabSetupBase::CutoffDecr);
    107100
    108101    BCP_lp_prob* bcp_lp = getLpProblemPointer();
     
    110103    const double bcp_cutoffIncr = bcp_lp->par.entry(BCP_lp_par::Granularity);
    111104
    112     if (fabs(bm_intTol - bcp_intTol) > 1e-10) {
     105    if (fabs(integerTolerance_ - bcp_intTol) > 1e-10) {
    113106        printf("WARNING!\n");
    114107        printf("   The integrality tolerance parameters are different for\n");
    115108        printf("   BCP (%f) and bonmin (%f). They should be identical.\n",
    116                bcp_intTol, bm_intTol);
     109               bcp_intTol, integerTolerance_);
    117110        printf("   For now both will be set to that of bonmin.\n");
    118111    }
    119     if (fabs(bm_cutoffIncr - bcp_cutoffIncr) > 1e-10) {
     112    if (fabs(cutOffDecrement_ - cutOffDecrement_) > 1e-10) {
    120113        printf("WARNING!\n");
    121114        printf("   The granularity (cutoff increment) parameters are different\n");
    122115        printf("   BCP (%f) and bonmin (%f). They should be identical.\n",
    123                bcp_cutoffIncr, bm_cutoffIncr);
     116               bcp_cutoffIncr, cutOffDecrement_);
    124117        printf("   For now both will be set to that of bonmin.\n");
    125118    }
    126     bcp_lp->par.set_entry(BCP_lp_par::IntegerTolerance, bm_intTol);
    127     bcp_lp->par.set_entry(BCP_lp_par::Granularity, bm_cutoffIncr);
    128 
    129     /* Store a few options in local variables */
    130 
    131     /** update getting options directly from setup*/
    132     double integerTolerance_ = bonmin_.getDoubleParameter(BabSetupBase::IntTol);
    133     double cutOffDecrement_ = bonmin_.getDoubleParameter(BabSetupBase::CutoffDecr);
    134    
    135     //PIERRE deprecated    options->GetNumericValue("integer_tolerance",integerTolerance_,"bonmin.");
    136     //PIERRE deprecated    options->GetNumericValue("cutoff_decr",cutOffDecrement_,"bonmin.");
    137    
     119    bcp_lp->par.set_entry(BCP_lp_par::IntegerTolerance, integerTolerance_);
     120    bcp_lp->par.set_entry(BCP_lp_par::Granularity, cutOffDecrement_);
     121
     122    /* Store a few more options in vars local to the BM_lp object */
     123
    138124    // Getting the options for the choose variable object
    139125    if (!options->GetEnumValue("varselect_stra",varselect_,"bonmin.")) {
     
    267253
    268254void
    269 BM_tm::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf)
     255BM_pack::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf)
    270256{
    271257    const BM_node* data = dynamic_cast<const BM_node*>(ud);
     
    276262
    277263BCP_user_data*
    278 BM_tm::unpack_user_data(BCP_buffer& buf)
     264BM_pack::unpack_user_data(BCP_buffer& buf)
    279265{
    280266    return new BM_node(buf);
    281267}
    282268
    283 /*****************************************************************************/
    284 
    285 void
    286 BM_lp::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf)
    287 {
    288     const BM_node* data = dynamic_cast<const BM_node*>(ud);
    289     data->pack(buf);
    290 }
    291 
    292269/*---------------------------------------------------------------------------*/
    293270
    294 BCP_user_data*
    295 BM_lp::unpack_user_data(BCP_buffer& buf)
    296 {
    297     BM_node* data = new BM_node(buf);
    298     numNlpFailed_ = data->numNlpFailed_;
    299     return data;
    300 }
    301 
    302 //#############################################################################
     271void
     272BM_pack::pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf)
     273{
     274    const BB_cut* bb_cut = dynamic_cast<const BB_cut*>(cut);
     275    if (!bb_cut)
     276        throw BCP_fatal_error("pack_cut_algo() : unknown cut type!\n");
     277    bb_cut->pack(buf);
     278}
     279
     280/*---------------------------------------------------------------------------*/
     281BCP_cut_algo* BM_pack::unpack_cut_algo(BCP_buffer& buf)
     282{
     283    return new BB_cut(buf);
     284}
  • trunk/Bonmin/experimental/Bcp/BM_tm.cpp

    r508 r530  
    1 #include "OsiClpSolverInterface.hpp"
    21// (C) Copyright International Business Machines Corporation 2006, 2007
    32// All Rights Reserved.
     
    87// Pierre Bonami, Carnegie Mellon University
    98
    10 #include "BonIpoptSolver.hpp"
    11 #ifdef COIN_HAS_FILTERSQP
    12 # include "BonFilterSolver.hpp"
    13 #endif
     9#include "OsiClpSolverInterface.hpp"
     10
    1411#include "BCP_problem_core.hpp"
     12#include "BCP_tm.hpp"
     13#include "BCP_lp.hpp"
     14
     15// #include "BonIpoptSolver.hpp"
     16// #ifdef COIN_HAS_FILTERSQP
     17// # include "BonFilterSolver.hpp"
     18// #endif
     19// #include "BonOACutGenerator2.hpp"
     20// #include "BonEcpCuts.hpp"
     21// #include "BonOaNlpOptim.hpp"
     22#include "BonAmplSetup.hpp"
     23
    1524#include "BM.hpp"
    16 
    17 
    18 #include "BonOACutGenerator2.hpp"
    19 #include "BonEcpCuts.hpp"
    20 #include "BonOaNlpOptim.hpp"
    21 
    22 #include "BonAmplSetup.hpp"
    2325
    2426//#############################################################################
     
    7173    bonmin.readOptionsFile(par.entry(BM_par::IpoptParamfile).c_str());
    7274    bonmin.initializeBonmin(argv);   
    73    
    74     Bonmin::OsiTMINLPInterface& nlpSolver = *bonmin.nonlinearSolver();
    7575   
    7676    free(argv[1]);
     
    211211//#############################################################################
    212212
    213 const BCP_proc_id*
    214 BM_tm::process_id() const
    215 {
    216 }
    217 
    218 void
    219 BM_tm::send_message(const BCP_proc_id* const target, const BCP_buffer& buf)
    220 {
    221 }
    222 
    223 void
    224 BM_tm::broadcast_message(const BCP_process_t proc_type, const BCP_buffer& buf)
    225 {
    226 }
    227 
    228213void
    229214BM_tm::process_message(BCP_buffer& buf)
     
    274259                         const CoinTreeSiblings* y) const {
    275260    double allowable_gap = 1e-8;
    276     return ((x->currentNode()->quality_ <
    277              y->currentNode()->quality_-allowable_gap) ||
    278             ((x->currentNode()->quality_ <= y->currentNode()->quality_+allowable_gap) &&
    279              x->currentNode()->depth_ > y->currentNode()->depth_));
     261    const double xq = x->currentNode()->getQuality();
     262    const double yq = y->currentNode()->getQuality();
     263    const int xd = x->currentNode()->getDepth();
     264    const int yd = y->currentNode()->getDepth();
     265    return ((xq < yq-allowable_gap) ||
     266            (xq <= yq+allowable_gap && xd > yd));
    280267    }
    281268};
Note: See TracChangeset for help on using the changeset viewer.