Changeset 1314 for branches/sandbox


Ignore:
Timestamp:
Nov 25, 2009 12:58:07 PM (10 years ago)
Author:
EdwinStraver
Message:

Broke up CbcCompareActual?.cpp into CbcCompareDepth?, CbcCompareDefault?, CbcCompareObjective? and CbcCompareEstimate?.
Carved CbcCutModifier? and CbcCutSubsetModifier? out of CbcCutGenerator?.
Updated spreadsheets.

Location:
branches/sandbox/Cbc
Files:
12 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/Cbc/CbcSourceFilesTable2.csv

    r1313 r1314  
    3636,CbcSimpleIntegerDynamicPseudoCost,Branch,Edwin,,,,,,,,,,,,
    3737CbcBranchLotsize.cpp,,Branch,Edwin,,15,809,250,1059,x,,,,CbcLotsize,CbcLotsizeBranchingObject,
    38 CbcCbcParam.cpp,,Solver,Bjarni,,24,1,,1,x,,,,"#include ""CbcOrClpParam.cpp""",,
    39 CbcCompareActual.cpp,,Compare,,,8,463,165,628,x,,,,CbcCompareDepth,"CbcCompareObjective, CbcCompareDefault, CbcCompareEstimate",
    40 CbcCompareBase.hpp,,Compare,,,24,,170,170,x,,,,CbcCompareBase,"CbcCompare, CbcChooseVariable",
    41 ,CbcCompare,,,,,,,,,,,,,,
    42 ,CbcChooseVariable,,,,,,,,,,,,,,
     38CbcCbcParam.cpp,,API,Bjarni,,24,1,,1,x,,,,"#include ""CbcOrClpParam.cpp""",,
     39CbcCompareActual.cpp,,NodeStrat,Edwin,,8,463,165,628,x,,,,CbcCompareDepth,"CbcCompareObjective, CbcCompareDefault, CbcCompareEstimate",
     40,CbcCompareDefault,NodeStrat,Edwin,,,,,,,,,,,,
     41,CbcCompareDepth,NodeStrat,Edwin,,,,,,,,,,,,
     42,CbcCompareEstimate,NodeStrat,Edwin,,,,,,,,,,,,
     43,CbcCmopareObjective,NodeStrat,Edwin,,,,,,,,,,,,
     44CbcCompareBase.hpp,,NodeStrat,,,24,,170,170,x,,,,CbcCompareBase,"CbcCompare, CbcChooseVariable",
     45,CbcCompare,NodeStrat,,,,,,,,,,,,,
     46,CbcChooseVariable,NodeStrat,,,,,,,,,,,,,
    4347CbcConfig.h,,,,,20,,102,102,x,,,,#defines,,
    44 CbcCountRowCut.cpp,,,,,10,126,115,241,x,,,,CbcCountRowCut,,
    45 CbcCutGenerator.cpp,,,,,2,1223,510,1733,x,,,,CbcCutGenerator,"CbcCutModifier, CbcCutSubsetModifier",
    46 CbcEventHandler.cpp,,,,,36,101,221,322,x,,,,CbcEventHandler,,
    47 CbcFathom.cpp,,,,,19,106,126,232,x,,,,CbcFathom,CbcOsiSolver,
    48 CbcFathomDynamicProgramming.cpp,,,,,10,1051,166,1217,x,,,,CbcFathomDynamicProgramming,,
    49 CbcFeasibilityBase.hpp,,,,,24,,53,53,x,,,,CbcFeasibilityBase,,
     48CbcCountRowCut.cpp,,Cuts,,,10,126,115,241,x,,,,CbcCountRowCut,,
     49CbcCutGenerator.cpp,,Cuts,,,2,1223,510,1733,x,,,,CbcCutGenerator,"CbcCutModifier, CbcCutSubsetModifier",
     50,CbcCutModifier,Cuts,,,,,,,,,,,,,
     51,CbcCutSubsetModifier,Cuts,,,,,,,,,,,,,
     52CbcEventHandler.cpp,,API,,,36,101,221,322,x,,,,CbcEventHandler,,
     53CbcFathom.cpp,,NodeStrat,,,19,106,126,232,x,,,,CbcFathom,CbcOsiSolver,
     54CbcFathomDynamicProgramming.cpp,,NodeStrat,,,10,1051,166,1217,x,,,,CbcFathomDynamicProgramming,,
     55CbcFeasibilityBase.hpp,,API,,,24,,53,53,x,,,,CbcFeasibilityBase,,
    5056CbcGenBaB.cpp,,Generic,Lou,,14,886,,886,,,x,,namespace CbcGenParamUtils,namespace,The support functions for the main branch-and-cut action routine.
    5157CbcGenCbcParam.cpp,,Generic,Lou,,24,155,189,344,,,x,,CbcCbcParam,,Constructors and destructors for CbcCbcParam
     
    7480CbcHeuristicRandRound.cpp,,Heuristic,,,10,514,55,569,x,,,,CbcHeuristicRandRound,,
    7581CbcHeuristicRINS.cpp,,Heuristic,,,10,1207,296,1503,x,,,,CbcHeuristicRINS,"CbcHeuristicRENS, CbcHeuristicDINS, CbcHeuristicVND",
    76 CbcLinked.cpp,,,,,10,8302,1403,9705,x,,,,OsiSolverLink,"OsiLinkedBound, OsiHeuristicDynamic3, OsiOldLink, OsiBiLinear*, OsiSimpleFixedInteger, Multiple",
    77 CbcMain.cpp,,,,,14,1651,,1651,,,,x,main,"CbcCompareUser, namespace",
    78 CbcMessage.cpp,,,,,13,104,87,191,x,,,,CbcMessage,,
    79 CbcModel.cpp,,,,,0,16557,2622,19179,x,,,,CbcModel,,
    80 CbcNode.cpp,,Node,Edwin,,0,5135,806,5941,x,,,,CbcNode,"CbcNodeInfo, CbcFullNodeInfo, CbcPartialNodeInfo, ",
    81 ,CbcFullNodeInfo.cpp,Node,Edwin,,,,,,,,,,,,
    82 ,CbcNodeInfo.cpp,Node,Edwin,,,,,,,,,,,,
    83 ,CbcPartialNodeInfo.cpp,Node,Edwin,,,,,,,,,,,,
    84 CbcParam.cpp,,Solver,Bjarni,,24,502,237,739,x,,,,CbcParam,,
    85 CbcSolver.cpp,,Solver,Bjarni,,0,11365,,11365,,x,,,CbcSolver,CbcMain,
    86 CbcStatistics.cpp,,,,,21,136,98,234,x,,,,CbcStatistics,,
    87 CbcStrategy.cpp,,,,,8,940,255,1195,x,,,,CbcStrategy,CbcStrategyDefault*,
    88 CbcTree.cpp,,,,,8,1178,419,1597,x,,,,CbcTree,CbcTreeArray,
    89 CbcTreeLocal.cpp,,,,,10,1747,369,2116,x,,,,CbcTreeLocal,,
     82CbcLinked.cpp,,Osi,,,10,8302,1403,9705,x,,,,OsiSolverLink,"OsiLinkedBound, OsiHeuristicDynamic3, OsiOldLink, OsiBiLinear*, OsiSimpleFixedInteger, Multiple",
     83CbcMain.cpp,,API,,,14,1651,,1651,,,,x,main,"CbcCompareUser, namespace",
     84CbcMessage.cpp,,API,,,13,104,87,191,x,,,,CbcMessage,,
     85CbcModel.cpp,,Core,,,0,16557,2622,19179,x,,,,CbcModel,,
     86CbcNode.cpp,,Core,Edwin,,0,5135,806,5941,x,,,,CbcNode,"CbcNodeInfo, CbcFullNodeInfo, CbcPartialNodeInfo, ",
     87,CbcFullNodeInfo.cpp,Core,Edwin,,,,,,,,,,,,
     88,CbcNodeInfo.cpp,Core,Edwin,,,,,,,,,,,,
     89,CbcPartialNodeInfo.cpp,Core,Edwin,,,,,,,,,,,,
     90CbcParam.cpp,,API,Bjarni,,24,502,237,739,x,,,,CbcParam,,
     91CbcSolver.cpp,,API,Bjarni,,0,11365,,11365,,x,,,CbcSolver,CbcMain,
     92CbcStatistics.cpp,,API,,,21,136,98,234,x,,,,CbcStatistics,,
     93CbcStrategy.cpp,,Core,,,8,940,255,1195,x,,,,CbcStrategy,CbcStrategyDefault*,
     94CbcTree.cpp,,Core,,,8,1178,419,1597,x,,,,CbcTree,CbcTreeArray,
     95CbcTreeLocal.cpp,,Heuristic,,,10,1747,369,2116,x,,,,CbcTreeLocal,,
    9096Cbc_ampl.cpp,,Ampl,,,4,1504,65,1569,,,,x,global,,
    9197Cbc_C_Interface.cpp,,Interface,Bjarni,,4,2554,658,3212,,,,x,global,,
  • branches/sandbox/Cbc/MSVisualStudio/v9/libCbc/libCbc.vcproj

    r1313 r1314  
    295295                        </File>
    296296                        <File
    297                                 RelativePath="..\..\..\..\Cbc\src\CbcCompareActual.cpp"
    298                                 >
    299                                 <FileConfiguration
    300                                         Name="Debug|Win32"
    301                                         >
    302                                         <Tool
    303                                                 Name="VCCLCompilerTool"
    304                                                 Optimization="0"
    305                                                 AdditionalIncludeDirectories=""
    306                                                 PreprocessorDefinitions=""
    307                                                 BasicRuntimeChecks="3"
    308                                         />
    309                                 </FileConfiguration>
    310                                 <FileConfiguration
    311                                         Name="Release|Win32"
    312                                         >
    313                                         <Tool
    314                                                 Name="VCCLCompilerTool"
    315                                                 Optimization="2"
    316                                                 AdditionalIncludeDirectories=""
    317                                                 PreprocessorDefinitions=""
    318                                         />
    319                                 </FileConfiguration>
     297                                RelativePath="..\..\..\src\CbcCompareDefault.cpp"
     298                                >
     299                        </File>
     300                        <File
     301                                RelativePath="..\..\..\src\CbcCompareDepth.cpp"
     302                                >
     303                        </File>
     304                        <File
     305                                RelativePath="..\..\..\src\CbcCompareEstimate.cpp"
     306                                >
     307                        </File>
     308                        <File
     309                                RelativePath="..\..\..\src\CbcCompareObjective.cpp"
     310                                >
    320311                        </File>
    321312                        <File
     
    376367                                        />
    377368                                </FileConfiguration>
     369                        </File>
     370                        <File
     371                                RelativePath="..\..\..\src\CbcCutModifier.cpp"
     372                                >
     373                        </File>
     374                        <File
     375                                RelativePath="..\..\..\src\CbcCutSubsetModifier.cpp"
     376                                >
    378377                        </File>
    379378                        <File
     
    11791178                        </File>
    11801179                        <File
     1180                                RelativePath="..\..\..\src\CbcCompareDefault.hpp"
     1181                                >
     1182                        </File>
     1183                        <File
     1184                                RelativePath="..\..\..\src\CbcCompareDepth.hpp"
     1185                                >
     1186                        </File>
     1187                        <File
     1188                                RelativePath="..\..\..\src\CbcCompareEstimate.hpp"
     1189                                >
     1190                        </File>
     1191                        <File
     1192                                RelativePath="..\..\..\src\CbcCompareObjective.hpp"
     1193                                >
     1194                        </File>
     1195                        <File
    11811196                                RelativePath="..\..\..\..\Cbc\src\CbcConfig.h"
    11821197                                >
     
    11961211                        <File
    11971212                                RelativePath="..\..\..\..\Cbc\src\CbcCutGenerator.hpp"
     1213                                >
     1214                        </File>
     1215                        <File
     1216                                RelativePath="..\..\..\src\CbcCutModifier.hpp"
     1217                                >
     1218                        </File>
     1219                        <File
     1220                                RelativePath="..\..\..\src\CbcCutSubsetModifier.hpp"
    11981221                                >
    11991222                        </File>
  • branches/sandbox/Cbc/src/CbcCompareActual.cpp

    r1286 r1314  
    1 /* $Id$ */
    2 // Copyright (C) 2004, International Business Machines
    3 // Corporation and others.  All Rights Reserved.
    4 #if defined(_MSC_VER)
    5 // Turn off compiler warning about long names
    6 #  pragma warning(disable:4786)
    7 #endif
    8 #include <cassert>
    9 #include <cstdlib>
    10 #include <cmath>
    11 #include <cfloat>
    12 //#define CBC_DEBUG
    13 
    14 #include "CbcMessage.hpp"
    15 #include "CbcModel.hpp"
    16 #include "CbcTree.hpp"
    17 #include "CbcCompareActual.hpp"
    18 #include "CoinError.hpp"
    191
    202
    21 /** Default Constructor
    22 
    23 */
    24 CbcCompareDepth::CbcCompareDepth ()
    25         : CbcCompareBase()
    26 {
    27     test_ = this;
    28 }
    29 
    30 // Copy constructor
    31 CbcCompareDepth::CbcCompareDepth ( const CbcCompareDepth & rhs)
    32         : CbcCompareBase(rhs)
    33 
    34 {
    35 }
    36 
    37 // Clone
    38 CbcCompareBase *
    39 CbcCompareDepth::clone() const
    40 {
    41     return new CbcCompareDepth(*this);
    42 }
    43 
    44 // Assignment operator
    45 CbcCompareDepth &
    46 CbcCompareDepth::operator=( const CbcCompareDepth & rhs)
    47 {
    48     if (this != &rhs) {
    49         CbcCompareBase::operator=(rhs);
    50     }
    51     return *this;
    52 }
    53 
    54 // Destructor
    55 CbcCompareDepth::~CbcCompareDepth ()
    56 {
    57 }
    58 
    59 // Returns true if y better than x
    60 bool
    61 CbcCompareDepth::test (CbcNode * x, CbcNode * y)
    62 {
    63     int testX = x->depth();
    64     int testY = y->depth();
    65     if (testX != testY)
    66         return testX < testY;
    67     else
    68         return equalityTest(x, y); // so ties will be broken in consistent manner
    69 }
    70 // Create C++ lines to get to current state
    71 void
    72 CbcCompareDepth::generateCpp( FILE * fp)
    73 {
    74     fprintf(fp, "0#include \"CbcCompareActual.hpp\"\n");
    75     fprintf(fp, "3  CbcCompareDepth compare;\n");
    76     fprintf(fp, "3  cbcModel->setNodeComparison(compare);\n");
    77 }
    78 
    79 /** Default Constructor
    80 
    81 */
    82 CbcCompareObjective::CbcCompareObjective ()
    83         : CbcCompareBase()
    84 {
    85     test_ = this;
    86 }
    87 
    88 // Copy constructor
    89 CbcCompareObjective::CbcCompareObjective ( const CbcCompareObjective & rhs)
    90         : CbcCompareBase(rhs)
    91 
    92 {
    93 }
    94 
    95 // Clone
    96 CbcCompareBase *
    97 CbcCompareObjective::clone() const
    98 {
    99     return new CbcCompareObjective(*this);
    100 }
    101 
    102 // Assignment operator
    103 CbcCompareObjective &
    104 CbcCompareObjective::operator=( const CbcCompareObjective & rhs)
    105 {
    106     if (this != &rhs) {
    107         CbcCompareBase::operator=(rhs);
    108     }
    109     return *this;
    110 }
    111 
    112 // Destructor
    113 CbcCompareObjective::~CbcCompareObjective ()
    114 {
    115 }
    116 
    117 // Returns true if y better than x
    118 bool
    119 CbcCompareObjective::test (CbcNode * x, CbcNode * y)
    120 {
    121     double testX = x->objectiveValue();
    122     double testY = y->objectiveValue();
    123     if (testX != testY)
    124         return testX > testY;
    125     else
    126         return equalityTest(x, y); // so ties will be broken in consistent manner
    127 }
    128 // Create C++ lines to get to current state
    129 void
    130 CbcCompareObjective::generateCpp( FILE * fp)
    131 {
    132     fprintf(fp, "0#include \"CbcCompareActual.hpp\"\n");
    133     fprintf(fp, "3  CbcCompareObjective compare;\n");
    134     fprintf(fp, "3  cbcModel->setNodeComparison(compare);\n");
    135 }
    136 
    137 
    138 /** Default Constructor
    139 
    140 */
    141 CbcCompareDefault::CbcCompareDefault ()
    142         : CbcCompareBase(),
    143         weight_(-1.0),
    144         saveWeight_(0.0),
    145         cutoff_(COIN_DBL_MAX),
    146         bestPossible_(-COIN_DBL_MAX),
    147         numberSolutions_(0),
    148         treeSize_(0),
    149         breadthDepth_(5)
    150 {
    151     test_ = this;
    152 }
    153 
    154 // Constructor with weight
    155 CbcCompareDefault::CbcCompareDefault (double weight)
    156         : CbcCompareBase(),
    157         weight_(weight) ,
    158         saveWeight_(0.0),
    159         cutoff_(COIN_DBL_MAX),
    160         bestPossible_(-COIN_DBL_MAX),
    161         numberSolutions_(0),
    162         treeSize_(0),
    163         breadthDepth_(5)
    164 {
    165     test_ = this;
    166 }
    167 
    168 
    169 // Copy constructor
    170 CbcCompareDefault::CbcCompareDefault ( const CbcCompareDefault & rhs)
    171         : CbcCompareBase(rhs)
    172 
    173 {
    174     weight_ = rhs.weight_;
    175     saveWeight_ = rhs.saveWeight_;
    176     cutoff_ = rhs.cutoff_;
    177     bestPossible_ = rhs.bestPossible_;
    178     numberSolutions_ = rhs.numberSolutions_;
    179     treeSize_ = rhs.treeSize_;
    180     breadthDepth_ = rhs.breadthDepth_;
    181 }
    182 
    183 // Clone
    184 CbcCompareBase *
    185 CbcCompareDefault::clone() const
    186 {
    187     return new CbcCompareDefault(*this);
    188 }
    189 
    190 // Assignment operator
    191 CbcCompareDefault &
    192 CbcCompareDefault::operator=( const CbcCompareDefault & rhs)
    193 {
    194     if (this != &rhs) {
    195         CbcCompareBase::operator=(rhs);
    196         weight_ = rhs.weight_;
    197         saveWeight_ = rhs.saveWeight_;
    198         cutoff_ = rhs.cutoff_;
    199         bestPossible_ = rhs.bestPossible_;
    200         numberSolutions_ = rhs.numberSolutions_;
    201         treeSize_ = rhs.treeSize_;
    202         breadthDepth_ = rhs.breadthDepth_;
    203     }
    204     return *this;
    205 }
    206 
    207 // Destructor
    208 CbcCompareDefault::~CbcCompareDefault ()
    209 {
    210 }
    211 
    212 // Returns true if y better than x
    213 bool
    214 CbcCompareDefault::test (CbcNode * x, CbcNode * y)
    215 {
    216 #if 0
    217     // always choose *smallest* depth if one or both <= breadthDepth_
    218     int depthX = x->depth();
    219     int depthY = y->depth();
    220     if (depthX <= breadthDepth_ || depthY <= breadthDepth_) {
    221         if (depthX != depthY)
    222             return depthX > depthY;
    223         else
    224             return equalityTest(x, y); // so ties will be broken in consistent manner
    225     }
    226     if (weight_ == -1.0 || weight_ == -3.0) {
    227         int adjust =  (weight_ == -3.0) ? 10000 : 0;
    228         // before solution
    229         /*printf("x %d %d %g, y %d %d %g\n",
    230            x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
    231            y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
    232         if (x->numberUnsatisfied() > y->numberUnsatisfied() + adjust) {
    233             return true;
    234         } else if (x->numberUnsatisfied() < y->numberUnsatisfied() - adjust) {
    235             return false;
    236         } else {
    237             int depthX = x->depth();
    238             int depthY = y->depth();
    239             if (depthX != depthY)
    240                 return depthX < depthY;
    241             else
    242                 return equalityTest(x, y); // so ties will be broken in consistent manner
    243         }
    244     } else {
    245         // after solution
    246         double weight = CoinMax(weight_, 0.0);
    247         double testX =  x->objectiveValue() + weight * x->numberUnsatisfied();
    248         double testY = y->objectiveValue() + weight * y->numberUnsatisfied();
    249         if (testX != testY)
    250             return testX > testY;
    251         else
    252             return equalityTest(x, y); // so ties will be broken in consistent manner
    253     }
    254 #else
    255     //weight_=0.0;
    256     if ((weight_ == -1.0 && (y->depth() > breadthDepth_ && x->depth() > breadthDepth_)) || weight_ == -3.0 || weight_ == -2.0) {
    257         int adjust =  (weight_ == -3.0) ? 10000 : 0;
    258         // before solution
    259         /*printf("x %d %d %g, y %d %d %g\n",
    260            x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
    261            y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
    262         if (x->numberUnsatisfied() > y->numberUnsatisfied() + adjust) {
    263             return true;
    264         } else if (x->numberUnsatisfied() < y->numberUnsatisfied() - adjust) {
    265             return false;
    266         } else {
    267             int depthX = x->depth();
    268             int depthY = y->depth();
    269             if (depthX != depthY)
    270                 return depthX < depthY;
    271             else
    272                 return equalityTest(x, y); // so ties will be broken in consistent manner
    273         }
    274     } else {
    275         // always choose *greatest* depth if both <= breadthDepth_ otherwise <= breadthDepth_ if just one
    276         int depthX = x->depth();
    277         int depthY = y->depth();
    278         /*if ((depthX==4&&depthY==5)||(depthX==5&&depthY==4))
    279           printf("X %x depth %d, Y %x depth %d, breadth %d\n",
    280           x,depthX,y,depthY,breadthDepth_);*/
    281         if (depthX <= breadthDepth_ || depthY <= breadthDepth_) {
    282             if (depthX <= breadthDepth_ && depthY <= breadthDepth_) {
    283                 if (depthX != depthY) {
    284                     return depthX < depthY;
    285                 }
    286             } else {
    287                 assert (depthX != depthY) ;
    288                 return depthX > depthY;
    289             }
    290         }
    291         // after solution ?
    292 #define THRESH2 0.999
    293 #define TRY_THIS 0
    294 #if TRY_THIS==0
    295         double weight = CoinMax(weight_, 1.0e-9);
    296         double testX =  x->objectiveValue() + weight * x->numberUnsatisfied();
    297         double testY = y->objectiveValue() + weight * y->numberUnsatisfied();
    298 #elif TRY_THIS==1
    299     /* compute what weight would have to be to hit target
    300        then reverse sign as large weight good */
    301     double target = (1.0 - THRESH2) * bestPossible_ + THRESH2 * cutoff_;
    302     double weight;
    303     weight = (target - x->objectiveValue()) /
    304              static_cast<double>(x->numberUnsatisfied());
    305     double testX = - weight;
    306     weight = (target - y->objectiveValue()) /
    307              static_cast<double>(y->numberUnsatisfied());
    308     double testY = - weight;
    309 #elif TRY_THIS==2
    310     // Use estimates
    311     double testX = x->guessedObjectiveValue();
    312     double testY = y->guessedObjectiveValue();
    313 #elif TRY_THIS==3
    314 #define THRESH 0.95
    315     // Use estimates
    316     double testX = x->guessedObjectiveValue();
    317     double testY = y->guessedObjectiveValue();
    318     if (x->objectiveValue() - bestPossible_ > THRESH*(cutoff_ - bestPossible_))
    319         testX *= 2.0; // make worse
    320     if (y->objectiveValue() - bestPossible_ > THRESH*(cutoff_ - bestPossible_))
    321         testY *= 2.0; // make worse
    322 #endif
    323         if (testX != testY)
    324             return testX > testY;
    325         else
    326             return equalityTest(x, y); // so ties will be broken in consistent manner
    327     }
    328 #endif
    329 }
    330 // This allows method to change behavior as it is called
    331 // after each solution
    332 void
    333 CbcCompareDefault::newSolution(CbcModel * model,
    334                                double objectiveAtContinuous,
    335                                int numberInfeasibilitiesAtContinuous)
    336 {
    337     cutoff_ = model->getCutoff();
    338     if (model->getSolutionCount() == model->getNumberHeuristicSolutions() &&
    339             model->getSolutionCount() < 5 && model->getNodeCount() < 500)
    340         return; // solution was got by rounding
    341     // set to get close to this solution
    342     double costPerInteger =
    343         (model->getObjValue() - objectiveAtContinuous) /
    344         static_cast<double> (numberInfeasibilitiesAtContinuous);
    345     weight_ = 0.95 * costPerInteger;
    346     saveWeight_ = 0.95 * weight_;
    347     numberSolutions_++;
    348     //if (numberSolutions_>5)
    349     //weight_ =0.0; // this searches on objective
    350 }
    351 // This allows method to change behavior
    352 bool
    353 CbcCompareDefault::every1000Nodes(CbcModel * model, int numberNodes)
    354 {
    355 #if 0
    356     // was
    357     if (numberNodes > 10000)
    358         weight_ = 0.0; // this searches on objective
    359     // get size of tree
    360     treeSize_ = model->tree()->size();
    361 #else
    362     double saveWeight = weight_;
    363     int numberNodes1000 = numberNodes / 1000;
    364     if (numberNodes > 10000) {
    365         weight_ = 0.0; // this searches on objective
    366         // but try a bit of other stuff
    367         if ((numberNodes1000 % 4) == 1)
    368             weight_ = saveWeight_;
    369     } else if (numberNodes == 1000 && weight_ == -2.0) {
    370         weight_ = -1.0; // Go to depth first
    371     }
    372     // get size of tree
    373     treeSize_ = model->tree()->size();
    374     if (treeSize_ > 10000) {
    375         int n1 = model->solver()->getNumRows() + model->solver()->getNumCols();
    376         int n2 = model->numberObjects();
    377         double size = n1 * 0.1 + n2 * 2.0;
    378         // set weight to reduce size most of time
    379         if (treeSize_*(size + 100.0) > 5.0e7)
    380             weight_ = -3.0;
    381         else if ((numberNodes1000 % 4) == 0 && treeSize_*size > 1.0e6)
    382             weight_ = -1.0;
    383         else if ((numberNodes1000 % 4) == 1)
    384             weight_ = 0.0;
    385         else
    386             weight_ = saveWeight_;
    387     }
    388 #endif
    389     //return numberNodes==11000; // resort if first time
    390     return (weight_ != saveWeight);
    391 }
    392 
    393 // Create C++ lines to get to current state
    394 void
    395 CbcCompareDefault::generateCpp( FILE * fp)
    396 {
    397     CbcCompareDefault other;
    398     fprintf(fp, "0#include \"CbcCompareActual.hpp\"\n");
    399     fprintf(fp, "3  CbcCompareDefault compare;\n");
    400     if (weight_ != other.weight_)
    401         fprintf(fp, "3  compare.setWeight(%g);\n", weight_);
    402     fprintf(fp, "3  cbcModel->setNodeComparison(compare);\n");
    403 }
    404 
    405 /** Default Constructor
    406 
    407 */
    408 CbcCompareEstimate::CbcCompareEstimate ()
    409         : CbcCompareBase()
    410 {
    411     test_ = this;
    412 }
    413 
    414 // Copy constructor
    415 CbcCompareEstimate::CbcCompareEstimate ( const CbcCompareEstimate & rhs)
    416         : CbcCompareBase(rhs)
    417 
    418 {
    419 }
    420 
    421 // Clone
    422 CbcCompareBase *
    423 CbcCompareEstimate::clone() const
    424 {
    425     return new CbcCompareEstimate(*this);
    426 }
    427 
    428 // Assignment operator
    429 CbcCompareEstimate &
    430 CbcCompareEstimate::operator=( const CbcCompareEstimate & rhs)
    431 {
    432     if (this != &rhs) {
    433         CbcCompareBase::operator=(rhs);
    434     }
    435     return *this;
    436 }
    437 
    438 // Destructor
    439 CbcCompareEstimate::~CbcCompareEstimate ()
    440 {
    441 }
    442 
    443 // Returns true if y better than x
    444 bool
    445 CbcCompareEstimate::test (CbcNode * x, CbcNode * y)
    446 {
    447     double testX = x->guessedObjectiveValue();
    448     double testY = y->guessedObjectiveValue();
    449     if (testX != testY)
    450         return testX > testY;
    451     else
    452         return equalityTest(x, y); // so ties will be broken in consistent manner
    453 }
    454 
    455 // Create C++ lines to get to current state
    456 void
    457 CbcCompareEstimate::generateCpp( FILE * fp)
    458 {
    459     fprintf(fp, "0#include \"CbcCompareActual.hpp\"\n");
    460     fprintf(fp, "3  CbcCompareEstimate compare;\n");
    461     fprintf(fp, "3  cbcModel->setNodeComparison(compare);\n");
    462 }
  • branches/sandbox/Cbc/src/CbcCompareActual.hpp

    r1290 r1314  
    44#ifndef CbcCompareActual_H
    55#define CbcCompareActual_H
    6 
    7 
    8 //#############################################################################
    9 /*  These are alternative strategies for node traversal.
    10     They can take data etc for fine tuning
    11 
    12     At present the node list is stored as a heap and the "test"
    13     comparison function returns true if node y is better than node x.
    14 
    15 */
    166#include "CbcNode.hpp"
    177#include "CbcCompareBase.hpp"
    188#include "CbcCompare.hpp"
    19 
    20 class CbcModel;
    21 // This is default before first solution
    22 class CbcCompareDepth : public CbcCompareBase {
    23 public:
    24     // Default Constructor
    25     CbcCompareDepth () ;
    26 
    27     ~CbcCompareDepth();
    28     // Copy constructor
    29     CbcCompareDepth ( const CbcCompareDepth &rhs);
    30 
    31     // Assignment operator
    32     CbcCompareDepth & operator=( const CbcCompareDepth& rhs);
    33 
    34     /// Clone
    35     virtual CbcCompareBase * clone() const;
    36     /// Create C++ lines to get to current state
    37     virtual void generateCpp( FILE * fp);
    38 
    39     // This returns true if the depth of node y is greater than depth of node x
    40     virtual bool test (CbcNode * x, CbcNode * y);
    41 };
    42 class CbcCompareObjective  : public CbcCompareBase {
    43 public:
    44     // Default Constructor
    45     CbcCompareObjective ();
    46 
    47     virtual ~CbcCompareObjective();
    48     // Copy constructor
    49     CbcCompareObjective ( const CbcCompareObjective &rhs);
    50 
    51     // Assignment operator
    52     CbcCompareObjective & operator=( const CbcCompareObjective& rhs);
    53 
    54     /// Clone
    55     virtual CbcCompareBase * clone() const;
    56     /// Create C++ lines to get to current state
    57     virtual void generateCpp( FILE * fp);
    58 
    59     /* This returns true if objective value of node y is less than
    60        objective value of node x */
    61     virtual bool test (CbcNode * x, CbcNode * y);
    62 };
    63 /* This is an example of a more complex rule with data
    64    It is default after first solution
    65    If weight is 0.0 then it is computed to hit first solution
    66    less 5%
    67 */
    68 class CbcCompareDefault  : public CbcCompareBase {
    69 public:
    70     // Default Constructor
    71     CbcCompareDefault () ;
    72     // Constructor with weight
    73     CbcCompareDefault (double weight);
    74 
    75     // Copy constructor
    76     CbcCompareDefault ( const CbcCompareDefault &rhs);
    77 
    78     // Assignment operator
    79     CbcCompareDefault & operator=( const CbcCompareDefault& rhs);
    80 
    81     /// Clone
    82     virtual CbcCompareBase * clone() const;
    83     /// Create C++ lines to get to current state
    84     virtual void generateCpp( FILE * fp);
    85 
    86     ~CbcCompareDefault() ;
    87     /* This returns true if weighted value of node y is less than
    88        weighted value of node x */
    89     virtual bool test (CbcNode * x, CbcNode * y) ;
    90 
    91     using CbcCompareBase::newSolution ;
    92     // This allows method to change behavior as it is called
    93     // after each solution
    94     virtual void newSolution(CbcModel * model,
    95                              double objectiveAtContinuous,
    96                              int numberInfeasibilitiesAtContinuous) ;
    97     // This allows method to change behavior
    98     // Return true if want tree re-sorted
    99     virtual bool every1000Nodes(CbcModel * model, int numberNodes);
    100 
    101     /* if weight == -1.0 then fewest infeasibilities (before solution)
    102        if -2.0 then do breadth first just for first 1000 nodes
    103        if -3.0 then depth first before solution
    104     */
    105     inline double getWeight() const {
    106         return weight_;
    107     }
    108     inline void setWeight(double weight) {
    109         weight_ = weight;
    110     }
    111     /// Cutoff
    112     inline double getCutoff() const {
    113         return cutoff_;
    114     }
    115     inline void setCutoff(double cutoff) {
    116         cutoff_ = cutoff;
    117     }
    118     /// Best possible solution
    119     inline double getBestPossible() const {
    120         return bestPossible_;
    121     }
    122     inline void setBestPossible(double bestPossible) {
    123         bestPossible_ = bestPossible;
    124     }
    125     // Depth above which want to explore first
    126     inline void setBreadthDepth(int value) {
    127         breadthDepth_ = value;
    128     }
    129 protected:
    130     // Weight for each infeasibility
    131     double weight_;
    132     // Weight for each infeasibility - computed from solution
    133     double saveWeight_;
    134     /// Cutoff
    135     double cutoff_;
    136     /// Best possible solution
    137     double bestPossible_;
    138     // Number of solutions
    139     int numberSolutions_;
    140     // Tree size (at last check)
    141     int treeSize_;
    142     // Depth above which want to explore first
    143     int breadthDepth_;
    144 };
    145 
    146 /* This is when rounding is being done
    147 */
    148 class CbcCompareEstimate  : public CbcCompareBase {
    149 public:
    150     // Default Constructor
    151     CbcCompareEstimate () ;
    152     ~CbcCompareEstimate() ;
    153     // Copy constructor
    154     CbcCompareEstimate ( const CbcCompareEstimate &rhs);
    155 
    156     // Assignment operator
    157     CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs);
    158 
    159     /// Clone
    160     virtual CbcCompareBase * clone() const;
    161     /// Create C++ lines to get to current state
    162     virtual void generateCpp( FILE * fp);
    163 
    164     virtual bool test (CbcNode * x, CbcNode * y) ;
    165 };
    166 
     9#include "CbcCompareDepth.hpp"
     10#include "CbcCompareDefault.hpp"
    16711#endif
  • branches/sandbox/Cbc/src/CbcCutGenerator.cpp

    r1286 r1314  
    11211121
    11221122
    1123 // Default Constructor
    1124 CbcCutModifier::CbcCutModifier()
    1125 {
    1126 }
    11271123
    1128 
    1129 // Destructor
    1130 CbcCutModifier::~CbcCutModifier ()
    1131 {
    1132 }
    1133 
    1134 // Copy constructor
    1135 CbcCutModifier::CbcCutModifier ( const CbcCutModifier & /*rhs*/)
    1136 {
    1137 }
    1138 
    1139 // Assignment operator
    1140 CbcCutModifier &
    1141 CbcCutModifier::operator=( const CbcCutModifier & rhs)
    1142 {
    1143     if (this != &rhs) {
    1144     }
    1145     return *this;
    1146 }
    1147 
    1148 // Default Constructor
    1149 CbcCutSubsetModifier::CbcCutSubsetModifier ()
    1150         : CbcCutModifier(),
    1151         firstOdd_(COIN_INT_MAX)
    1152 {
    1153 }
    1154 
    1155 // Useful constructor
    1156 CbcCutSubsetModifier::CbcCutSubsetModifier (int firstOdd)
    1157         : CbcCutModifier()
    1158 {
    1159     firstOdd_ = firstOdd;
    1160 }
    1161 
    1162 // Copy constructor
    1163 CbcCutSubsetModifier::CbcCutSubsetModifier ( const CbcCutSubsetModifier & rhs)
    1164         : CbcCutModifier(rhs)
    1165 {
    1166     firstOdd_ = rhs.firstOdd_;
    1167 }
    1168 
    1169 // Clone
    1170 CbcCutModifier *
    1171 CbcCutSubsetModifier::clone() const
    1172 {
    1173     return new CbcCutSubsetModifier(*this);
    1174 }
    1175 
    1176 // Assignment operator
    1177 CbcCutSubsetModifier &
    1178 CbcCutSubsetModifier::operator=( const CbcCutSubsetModifier & rhs)
    1179 {
    1180     if (this != &rhs) {
    1181         CbcCutModifier::operator=(rhs);
    1182         firstOdd_ = rhs.firstOdd_;
    1183     }
    1184     return *this;
    1185 }
    1186 
    1187 // Destructor
    1188 CbcCutSubsetModifier::~CbcCutSubsetModifier ()
    1189 {
    1190 }
    1191 /* Returns
    1192    0 unchanged
    1193    1 strengthened
    1194    2 weakened
    1195    3 deleted
    1196 */
    1197 int
    1198 CbcCutSubsetModifier::modify(const OsiSolverInterface * /*solver*/,
    1199                              OsiRowCut & cut)
    1200 {
    1201     int n = cut.row().getNumElements();
    1202     if (!n)
    1203         return 0;
    1204     const int * column = cut.row().getIndices();
    1205     //const double * element = cut.row().getElements();
    1206     int returnCode = 0;
    1207     for (int i = 0; i < n; i++) {
    1208         if (column[i] >= firstOdd_) {
    1209             returnCode = 3;
    1210             break;
    1211         }
    1212     }
    1213     if (!returnCode) {
    1214         const double * element = cut.row().getElements();
    1215         printf("%g <= ", cut.lb());
    1216         for (int i = 0; i < n; i++) {
    1217             printf("%g*x%d ", element[i], column[i]);
    1218         }
    1219         printf("<= %g\n", cut.ub());
    1220     }
    1221     //return 3;
    1222     return returnCode;
    1223 }
    1224 
  • branches/sandbox/Cbc/src/CbcCutGenerator.hpp

    r1286 r1314  
    88#include "OsiCuts.hpp"
    99#include "CglCutGenerator.hpp"
     10#include "CbcCutModifier.hpp"
    1011
    1112class CbcModel;
     
    420421    int switches_;
    421422};
    422 /** Abstract cut modifier base class
    423 
    424     In exotic circumstances - cuts may need to be modified
    425     a) strengthened - changed
    426     b) weakened - changed
    427     c) deleted - set to NULL
    428     d) unchanged
    429 */
    430 
    431 class CbcCutModifier {
    432 public:
    433     /// Default Constructor
    434     CbcCutModifier ();
    435 
    436     // Copy constructor
    437     CbcCutModifier ( const CbcCutModifier &);
    438 
    439     /// Destructor
    440     virtual ~CbcCutModifier();
    441 
    442     /// Assignment
    443     CbcCutModifier & operator=(const CbcCutModifier& rhs);
    444 /// Clone
    445     virtual CbcCutModifier * clone() const = 0;
    446 
    447     /** Returns
    448         0 unchanged
    449         1 strengthened
    450         2 weakened
    451         3 deleted
    452     */
    453     virtual int modify(const OsiSolverInterface * solver, OsiRowCut & cut) = 0;
    454     /// Create C++ lines to get to current state
    455     virtual void generateCpp( FILE * ) {}
    456 protected:
    457 
    458 };
    459 
    460 /** Simple cut modifier base class
    461 
    462     In exotic circumstances - cuts may need to be modified
    463     a) strengthened - changed
    464     b) weakened - changed
    465     c) deleted - set to NULL
    466     d) unchanged
    467 
    468     initially get rid of cuts with variables >= k
    469     could weaken
    470 */
    471 
    472 class CbcCutSubsetModifier  : public CbcCutModifier {
    473 public:
    474     /// Default Constructor
    475     CbcCutSubsetModifier ();
    476 
    477     /// Useful Constructor
    478     CbcCutSubsetModifier (int firstOdd);
    479 
    480     // Copy constructor
    481     CbcCutSubsetModifier ( const CbcCutSubsetModifier &);
    482 
    483     /// Destructor
    484     virtual ~CbcCutSubsetModifier();
    485 
    486     /// Assignment
    487     CbcCutSubsetModifier & operator=(const CbcCutSubsetModifier& rhs);
    488 /// Clone
    489     virtual CbcCutModifier * clone() const ;
    490 
    491     /** Returns
    492         0 unchanged
    493         1 strengthened
    494         2 weakened
    495         3 deleted
    496     */
    497     virtual int modify(const OsiSolverInterface * solver, OsiRowCut & cut) ;
    498     /// Create C++ lines to get to current state
    499     virtual void generateCpp( FILE * ) {}
    500 protected:
    501     /// data
    502     /// First odd variable
    503     int firstOdd_;
    504 };
     423
    505424// How often to do if mostly switched off (A)
    506425# define SCANCUTS 1000
  • branches/sandbox/Cbc/src/Makefile.am

    r1313 r1314  
    3131        CbcBranchLotsize.cpp CbcBranchLotsize.hpp \
    3232        CbcBranchToFixLots.cpp CbcBranchToFixLots.hpp \
    33         CbcCompareActual.cpp CbcCompareActual.hpp \
     33        CbcCompareActual.hpp \
    3434        CbcCompareBase.hpp \
     35        CbcCompareDefault.cpp CbcCompareDefault.hpp \
     36        CbcCompareDepth.cpp CbcCompareDepth.hpp \
     37        CbcCompareEstimate.cpp CbcCompareEstimate.hpp \
     38        CbcCompareObjective.cpp CbcCompareObjective.hpp \
    3539        CbcConsequence.cpp CbcConsequence.hpp \
    3640        CbcChooseVariable.hpp \
     
    4246        CbcCutBranchingObject.cpp CbcCutBranchingObject.hpp \
    4347        CbcCutGenerator.cpp CbcCutGenerator.hpp \
     48        CbcCutModifier.cpp CbcCutModifier.hpp \
     49        CbcCutSubsetModifier.cpp CbcCutSubsetModifier.hpp \
    4450        CbcDummyBranchingObject.cpp CbcDummyBranchingObject.hpp \
    4551        CbcDynamicPseudoCostBranchingObject.cpp CbcDynamicPseudoCostBranchingObject.hpp \
     
    356362        CbcBranchToFixLots.hpp \
    357363        CbcCompareActual.hpp \
     364        CbcCompareDefault.hpp \
     365        CbcCompareDepth.hpp \
     366        CbcCompareEstimate.hpp \
     367        CbcCompareObjective.hpp \
    358368        CbcConsequence.hpp \
    359369        CbcChooseVariable.hpp \
     
    363373        CbcCutBranchingObject.hpp \
    364374        CbcCutGenerator.hpp \
     375        CbcCutModifier.hpp \
     376        CbcCutSubsetModifier.hpp \
    365377        CbcDummyBranchingObject.hpp \
    366378        CbcDynamicPseudoCostBranchingObject.hpp \
  • branches/sandbox/Cbc/src/Makefile.in

    r1313 r1314  
    165165        CbcBranchDefaultDecision.lo CbcBranchDynamic.lo \
    166166        CbcBranchingObject.lo CbcBranchLotsize.lo \
    167         CbcBranchToFixLots.lo CbcCompareActual.lo CbcConsequence.lo \
     167        CbcBranchToFixLots.lo CbcCompareDefault.lo CbcCompareDepth.lo \
     168        CbcCompareEstimate.lo CbcCompareObjective.lo CbcConsequence.lo \
    168169        CbcClique.lo CbcCliqueBranchingObject.lo \
    169170        CbcLongCliqueBranchingObject.lo CbcCountRowCut.lo \
    170         CbcCutBranchingObject.lo CbcCutGenerator.lo \
    171         CbcDummyBranchingObject.lo \
     171        CbcCutBranchingObject.lo CbcCutGenerator.lo CbcCutModifier.lo \
     172        CbcCutSubsetModifier.lo CbcDummyBranchingObject.lo \
    172173        CbcDynamicPseudoCostBranchingObject.lo CbcEventHandler.lo \
    173174        CbcFathom.lo CbcFathomDynamicProgramming.lo \
     
    534535        CbcBranchLotsize.cpp CbcBranchLotsize.hpp \
    535536        CbcBranchToFixLots.cpp CbcBranchToFixLots.hpp \
    536         CbcCompareActual.cpp CbcCompareActual.hpp \
     537        CbcCompareActual.hpp \
    537538        CbcCompareBase.hpp \
     539        CbcCompareDefault.cpp CbcCompareDefault.hpp \
     540        CbcCompareDepth.cpp CbcCompareDepth.hpp \
     541        CbcCompareEstimate.cpp CbcCompareEstimate.hpp \
     542        CbcCompareObjective.cpp CbcCompareObjective.hpp \
    538543        CbcConsequence.cpp CbcConsequence.hpp \
    539544        CbcChooseVariable.hpp \
     
    545550        CbcCutBranchingObject.cpp CbcCutBranchingObject.hpp \
    546551        CbcCutGenerator.cpp CbcCutGenerator.hpp \
     552        CbcCutModifier.cpp CbcCutModifier.hpp \
     553        CbcCutSubsetModifier.cpp CbcCutSubsetModifier.hpp \
    547554        CbcDummyBranchingObject.cpp CbcDummyBranchingObject.hpp \
    548555        CbcDynamicPseudoCostBranchingObject.cpp CbcDynamicPseudoCostBranchingObject.hpp \
     
    722729        CbcBranchToFixLots.hpp \
    723730        CbcCompareActual.hpp \
     731        CbcCompareDefault.hpp \
     732        CbcCompareDepth.hpp \
     733        CbcCompareEstimate.hpp \
     734        CbcCompareObjective.hpp \
    724735        CbcConsequence.hpp \
    725736        CbcChooseVariable.hpp \
     
    729740        CbcCutBranchingObject.hpp \
    730741        CbcCutGenerator.hpp \
     742        CbcCutModifier.hpp \
     743        CbcCutSubsetModifier.hpp \
    731744        CbcDummyBranchingObject.hpp \
    732745        CbcDynamicPseudoCostBranchingObject.hpp \
     
    906919@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcClique.Plo@am__quote@
    907920@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCliqueBranchingObject.Plo@am__quote@
    908 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCompareActual.Plo@am__quote@
     921@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCompareDefault.Plo@am__quote@
     922@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCompareDepth.Plo@am__quote@
     923@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCompareEstimate.Plo@am__quote@
     924@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCompareObjective.Plo@am__quote@
    909925@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcConsequence.Plo@am__quote@
    910926@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCountRowCut.Plo@am__quote@
    911927@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCutBranchingObject.Plo@am__quote@
    912928@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCutGenerator.Plo@am__quote@
     929@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCutModifier.Plo@am__quote@
     930@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcCutSubsetModifier.Plo@am__quote@
    913931@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcDummyBranchingObject.Plo@am__quote@
    914932@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcDynamicPseudoCostBranchingObject.Plo@am__quote@
Note: See TracChangeset for help on using the changeset viewer.