CbcFollowOn.hpp 6.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
// $Id$
// Copyright (C) 2002, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

// Edwin 11/10/2009-- carved out of CbcBranchActual

#ifndef CbcFollowOn_H
#define CbcFollowOn_H

#include "CbcBranchBase.hpp"
#include "OsiRowCut.hpp"
#include "CoinHelperFunctions.hpp"
#include "CoinPackedMatrix.hpp"

/** Define a follow on class.
    The idea of this is that in air-crew scheduling problems crew may fly in on flight A
    and out on flight B or on some other flight.  A useful branch is one which on one side
    fixes all which go out on flight B to 0, while the other branch fixes all those that do NOT
    go out on flight B to 0.

    This branching rule should be in addition to normal rules and have a high priority.
*/

class CbcFollowOn : public CbcObject {

public:
  // Default Constructor
  CbcFollowOn();

  /** Useful constructor
    */
  CbcFollowOn(CbcModel *model);

  // Copy constructor
  CbcFollowOn(const CbcFollowOn &);

  /// Clone
  virtual CbcObject *clone() const;

  // Assignment operator
  CbcFollowOn &operator=(const CbcFollowOn &rhs);

  // Destructor
  ~CbcFollowOn();

  /// Infeasibility - large is 0.5
  virtual double infeasibility(const OsiBranchingInformation *info,
    int &preferredWay) const;

  using CbcObject::feasibleRegion;
  /// This looks at solution and sets bounds to contain solution
  virtual void feasibleRegion();

  /// Creates a branching object
  virtual CbcBranchingObject *createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way);
  /// As some computation is needed in more than one place - returns row
  virtual int gutsOfFollowOn(int &otherRow, int &preferredWay) const;

protected:
  /// data
  /// Matrix
  CoinPackedMatrix matrix_;
  /// Matrix by row
  CoinPackedMatrix matrixByRow_;
  /// Possible rhs (if 0 then not possible)
  int *rhs_;
};

/** General Branching Object class.
    Each way fixes some variables to lower bound
 */
class CbcFixingBranchingObject : public CbcBranchingObject {

public:
  // Default Constructor
  CbcFixingBranchingObject();

  // Useful constructor
  CbcFixingBranchingObject(CbcModel *model,
    int way,
    int numberOnDownSide, const int *down,
    int numberOnUpSide, const int *up);

  // Copy constructor
  CbcFixingBranchingObject(const CbcFixingBranchingObject &);

  // Assignment operator
  CbcFixingBranchingObject &operator=(const CbcFixingBranchingObject &rhs);

  /// Clone
  virtual CbcBranchingObject *clone() const;

  // Destructor
  virtual ~CbcFixingBranchingObject();

  using CbcBranchingObject::branch;
  /// Does next branch and updates state
  virtual double branch();

#ifdef JJF_ZERO
  // No need to override. Default works fine.
  /** Reset every information so that the branching object appears to point to
        the previous child. This method does not need to modify anything in any
        solver. */
  virtual void previousBranch();
#endif

  using CbcBranchingObject::print;
  /** \brief Print something about branch - only if log level high
    */
  virtual void print();

  /** Return the type (an integer identifier) of \c this */
  virtual CbcBranchObjType type() const
  {
    return FollowOnBranchObj;
  }

  /** Compare the original object of \c this with the original object of \c
        brObj. Assumes that there is an ordering of the original objects.
        This method should be invoked only if \c this and brObj are of the same
        type.
        Return negative/0/positive depending on whether \c this is
        smaller/same/larger than the argument.
    */
  virtual int compareOriginalObject(const CbcBranchingObject *brObj) const;

  /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
        same type and must have the same original object, but they may have
        different feasible regions.
        Return the appropriate CbcRangeCompare value (first argument being the
        sub/superset if that's the case). In case of overlap (and if \c
        replaceIfOverlap is true) replace the current branching object with one
        whose feasible region is the overlap.
     */
  virtual CbcRangeCompare compareBranchingObject(const CbcBranchingObject *brObj, const bool replaceIfOverlap = false);

private:
  /// data
  /// Number on down list
  int numberDown_;
  /// Number on up list
  int numberUp_;
  /// downList - variables to fix to lb on down branch
  int *downList_;
  /// upList - variables to fix to lb on up branch
  int *upList_;
};

/** Define an idiotic idea class.
    The idea of this is that we take some integer variables away from integer and
    sum them with some randomness to get signed sum close to 0.5.  We then can
    branch to exclude that gap.

    This branching rule should be in addition to normal rules and have a high priority.
*/

class CbcIdiotBranch : public CbcObject {

public:
  // Default Constructor
  CbcIdiotBranch();

  /** Useful constructor
    */
  CbcIdiotBranch(CbcModel *model);

  // Copy constructor
  CbcIdiotBranch(const CbcIdiotBranch &);

  /// Clone
  virtual CbcObject *clone() const;

  // Assignment operator
  CbcIdiotBranch &operator=(const CbcIdiotBranch &rhs);

  // Destructor
  ~CbcIdiotBranch();

  /// Infeasibility - large is 0.5
  virtual double infeasibility(const OsiBranchingInformation *info,
    int &preferredWay) const;

  using CbcObject::feasibleRegion;
  /// This looks at solution and sets bounds to contain solution
  virtual void feasibleRegion();

  /// Creates a branching object
  virtual CbcBranchingObject *createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way);
  /// Initialize for branching
  virtual void initializeForBranching(CbcModel *);

protected:
  /// Build "cut"
  OsiRowCut buildCut(const OsiBranchingInformation *info, int type, int &preferredWay) const;
  /// data
  /// Thread specific random number generator
  mutable CoinThreadRandom randomNumberGenerator_;
  /// Saved version of thread specific random number generator
  mutable CoinThreadRandom savedRandomNumberGenerator_;
};

#endif

/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
*/