source: stable/2.6/Cbc/src/CbcBranchDecision.cpp @ 2122

Last change on this file since 2122 was 1432, checked in by bjarni, 10 years ago

Added extra return at end of each source file where needed, to remove possible linefeed conflicts (NightlyBuild? errors)

File size: 2.5 KB
Line 
1// Edwin 11/12/2009 carved from CbcBranchBase
2#if defined(_MSC_VER)
3// Turn off compiler warning about long names
4#  pragma warning(disable:4786)
5#endif
6#include <cassert>
7#include <cstdlib>
8#include <cmath>
9#include <cfloat>
10
11#include "OsiSolverInterface.hpp"
12#include "OsiSolverBranch.hpp"
13#include "OsiChooseVariable.hpp"
14#include "CbcModel.hpp"
15#include "CbcMessage.hpp"
16#include "CbcBranchBase.hpp"
17#include "CbcBranchDecision.hpp"
18
19// Default Constructor
20CbcBranchDecision::CbcBranchDecision ()
21        : object_(NULL), model_(NULL), chooseMethod_(NULL)
22{
23}
24
25// Copy Constructor
26CbcBranchDecision::CbcBranchDecision (const CbcBranchDecision &rhs)
27        : object_(NULL), model_(rhs.model_), chooseMethod_(NULL)
28{
29    if (rhs.chooseMethod_)
30        chooseMethod_ = rhs.chooseMethod_->clone();
31}
32
33CbcBranchDecision::~CbcBranchDecision()
34{
35    delete object_;
36    delete chooseMethod_;
37}
38/* Compare N branching objects. Return index of best
39   and sets way of branching in chosen object.
40
41   This routine is used only after strong branching.
42   This is reccommended version as it can be more sophisticated
43*/
44
45int
46CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects,
47                               int /*numberUnsatisfied*/,
48                               double * changeUp, int * numberInfeasibilitiesUp,
49                               double * changeDown, int * numberInfeasibilitiesDown,
50                               double /*objectiveValue*/)
51{
52    int bestWay = 0;
53    int whichObject = -1;
54    if (numberObjects) {
55        initialize(objects[0]->model());
56        CbcBranchingObject * bestObject = NULL;
57        for (int i = 0 ; i < numberObjects ; i++) {
58            int betterWay = betterBranch(objects[i],
59                                         bestObject,
60                                         changeUp[i],
61                                         numberInfeasibilitiesUp [i],
62                                         changeDown[i],
63                                         numberInfeasibilitiesDown[i] );
64            if (betterWay) {
65                bestObject = objects[i];
66                bestWay = betterWay;
67                whichObject = i;
68            }
69        }
70        // set way in best
71        if (whichObject >= 0)
72            objects[whichObject]->way(bestWay);
73    }
74    return whichObject;
75}
76// Set (clone) chooseMethod
77void
78CbcBranchDecision::setChooseMethod(const OsiChooseVariable & method)
79{
80    delete chooseMethod_;
81    chooseMethod_ = method.clone();
82}
83
Note: See TracBrowser for help on using the repository browser.