source: stable/2.8/Cbc/src/CbcBranchDecision.cpp @ 2011

Last change on this file since 2011 was 1902, checked in by stefan, 6 years ago

sync with trunk rev 1901

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1// $Id: CbcBranchDecision.cpp 1902 2013-04-10 16:58:16Z forrest $
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), model_(NULL), chooseMethod_(NULL)
28{
29}
30
31// Copy Constructor
32CbcBranchDecision::CbcBranchDecision (const CbcBranchDecision &rhs)
33        : object_(NULL), model_(rhs.model_), chooseMethod_(NULL)
34{
35    if (rhs.chooseMethod_)
36        chooseMethod_ = rhs.chooseMethod_->clone();
37}
38
39CbcBranchDecision::~CbcBranchDecision()
40{
41    delete object_;
42    delete chooseMethod_;
43}
44/* Compare N branching objects. Return index of best
45   and sets way of branching in chosen object.
46
47   This routine is used only after strong branching.
48   This is reccommended version as it can be more sophisticated
49*/
50
51int
52CbcBranchDecision::bestBranch (CbcBranchingObject ** objects, int numberObjects,
53                               int /*numberUnsatisfied*/,
54                               double * changeUp, int * numberInfeasibilitiesUp,
55                               double * changeDown, int * numberInfeasibilitiesDown,
56                               double /*objectiveValue*/)
57{
58    int bestWay = 0;
59    int whichObject = -1;
60    if (numberObjects) {
61        initialize(objects[0]->model());
62        CbcBranchingObject * bestObject = NULL;
63        for (int i = 0 ; i < numberObjects ; i++) {
64            int betterWay = betterBranch(objects[i],
65                                         bestObject,
66                                         changeUp[i],
67                                         numberInfeasibilitiesUp [i],
68                                         changeDown[i],
69                                         numberInfeasibilitiesDown[i] );
70            if (betterWay) {
71                bestObject = objects[i];
72                bestWay = betterWay;
73                whichObject = i;
74            }
75        }
76        // set way in best
77        if (whichObject >= 0)
78            objects[whichObject]->way(bestWay);
79    }
80    return whichObject;
81}
82// Set (clone) chooseMethod
83void
84CbcBranchDecision::setChooseMethod(const OsiChooseVariable & method)
85{
86    delete chooseMethod_;
87    chooseMethod_ = method.clone();
88}
89
Note: See TracBrowser for help on using the repository browser.