File: CbcNWay.hpp

package info (click to toggle)
coinor-cbc 2.9.9+repack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,848 kB
  • ctags: 5,787
  • sloc: cpp: 104,337; sh: 8,921; xml: 2,950; makefile: 520; ansic: 491; awk: 197
file content (166 lines) | stat: -rw-r--r-- 5,271 bytes parent folder | download | duplicates (3)
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
// $Id: CbcNWay.hpp 1899 2013-04-09 18:12:08Z stefan $
// 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/9/2009-- carved out of CbcBranchActual

/** Define an n-way class for variables.
    Only valid value is one at UB others at LB
    Normally 0-1
*/
#ifndef CbcNWay_H
#define CbcNWay_H

class CbcNWay : public CbcObject {

public:

    // Default Constructor
    CbcNWay ();

    /** Useful constructor (which are matrix indices)
    */
    CbcNWay (CbcModel * model, int numberMembers,
             const int * which, int identifier);

    // Copy constructor
    CbcNWay ( const CbcNWay &);

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

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

    /// Destructor
    virtual ~CbcNWay ();

    /// Set up a consequence for a single member
    void setConsequence(int iColumn, const CbcConsequence & consequence);

    /// Applies a consequence for a single member
    void applyConsequence(int iSequence, int state) const;

    /// Infeasibility - large is 0.5 (and 0.5 will give this)
    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) ;

    /// Number of members
    inline int numberMembers() const {
        return numberMembers_;
    }

    /// Members (indices in range 0 ... numberColumns-1)
    inline const int * members() const {
        return members_;
    }
    /// Redoes data when sequence numbers change
    virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns);

protected:
    /// data
    /// Number of members
    int numberMembers_;

    /// Members (indices in range 0 ... numberColumns-1)
    int * members_;
    /// Consequences (normally NULL)
    CbcConsequence ** consequence_;
};
/** N way branching Object class.
    Variable is number of set.
 */
class CbcNWayBranchingObject : public CbcBranchingObject {

public:

    // Default Constructor
    CbcNWayBranchingObject ();

    /** Useful constructor - order had matrix indices
        way_ -1 corresponds to setting first, +1 to second, +3 etc.
        this is so -1 and +1 have similarity to normal
    */
    CbcNWayBranchingObject (CbcModel * model,  const CbcNWay * nway,
                            int numberBranches, const int * order);

    // Copy constructor
    CbcNWayBranchingObject ( const CbcNWayBranchingObject &);

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

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

    // Destructor
    virtual ~CbcNWayBranchingObject ();

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

#ifdef JJF_ZERO
    // FIXME: what do we need to do here?
    /** 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();
    /** The number of branch arms created for this branching object
    */
    virtual int numberBranches() const {
        return numberInSet_;
    }
    /// Is this a two way object (-1 down, +1 up)
    virtual bool twoWay() const {
        return false;
    }

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

    /** 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:
    /// order of branching - points back to CbcNWay
    int * order_;
    /// Points back to object
    const CbcNWay * object_;
    /// Number in set
    int numberInSet_;
};
#endif