source: trunk/Cbc/src/CbcBranchDecision.cpp @ 2464

Last change on this file since 2464 was 2464, checked in by unxusr, 10 months ago

.clang-format with proposal for formatting code

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