source: trunk/Clp/src/ClpDynamicExampleMatrix.hpp @ 1502

Last change on this file since 1502 was 1502, checked in by forrest, 10 years ago

moving sandbox stuff to trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.5 KB
Line 
1/* $Id: ClpDynamicExampleMatrix.hpp 1502 2010-01-29 14:25:07Z forrest $ */
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef ClpDynamicExampleMatrix_H
5#define ClpDynamicExampleMatrix_H
6
7
8#include "CoinPragma.hpp"
9
10#include "ClpDynamicMatrix.hpp"
11class ClpSimplex;
12/** This implements a dynamic matrix when we have a limit on the number of
13    "interesting rows". This version inherits from ClpDynamicMatrix and knows that
14    the real matrix is gub.  This acts just like ClpDynamicMatrix but generates columns.
15    This "generates" columns by choosing from stored set.  It is maent as a starting point
16    as to how you could use shortest path to generate columns.
17
18    So it has its own copy of all data needed.  It populates ClpDynamicWatrix with enough
19    to allow for gub keys and active variables.  In turn ClpDynamicMatrix populates
20    a CoinPackedMatrix with active columns and rows.
21
22    As there is one copy here and one in ClpDynamicmatrix these names end in Gen_
23
24    It is obviously more efficient to just use ClpDynamicMatrix but the ideas is to
25    show how much code a user would have to write.
26
27    This does not work very well with bounds
28
29*/
30
31class ClpDynamicExampleMatrix : public ClpDynamicMatrix {
32
33public:
34    /**@name Main functions provided */
35    //@{
36    /// Partial pricing
37    virtual void partialPricing(ClpSimplex * model, double start, double end,
38                                int & bestSequence, int & numberWanted);
39
40    /** Creates a variable.  This is called after partial pricing and will modify matrix.
41        Will update bestSequence.
42    */
43    virtual void createVariable(ClpSimplex * model, int & bestSequence);
44    /** If addColumn forces compression then this allows descendant to know what to do.
45        If >= then entry stayed in, if -1 then entry went out to lower bound.of zero.
46        Entries at upper bound (really nonzero) never go out (at present).
47    */
48    virtual void packDown(const int * in, int numberToPack);
49    //@}
50
51
52
53    /**@name Constructors, destructor */
54    //@{
55    /** Default constructor. */
56    ClpDynamicExampleMatrix();
57    /** This is the real constructor.
58        It assumes factorization frequency will not be changed.
59        This resizes model !!!!
60        The contents of original matrix in model will be taken over and original matrix
61        will be sanitized so can be deleted (to avoid a very small memory leak)
62     */
63    ClpDynamicExampleMatrix(ClpSimplex * model, int numberSets,
64                            int numberColumns, const int * starts,
65                            const double * lower, const double * upper,
66                            const int * startColumn, const int * row,
67                            const double * element, const double * cost,
68                            const double * columnLower = NULL, const double * columnUpper = NULL,
69                            const unsigned char * status = NULL,
70                            const unsigned char * dynamicStatus = NULL,
71                            int numberIds = 0, const int *ids = NULL);
72    /// This constructor just takes over ownership (except for lower, upper)
73    ClpDynamicExampleMatrix(ClpSimplex * model, int numberSets,
74                            int numberColumns, int * starts,
75                            const double * lower, const double * upper,
76                            int * startColumn, int * row,
77                            double * element, double * cost,
78                            double * columnLower = NULL, double * columnUpper = NULL,
79                            const unsigned char * status = NULL,
80                            const unsigned char * dynamicStatus = NULL,
81                            int numberIds = 0, const int *ids = NULL);
82
83    /** Destructor */
84    virtual ~ClpDynamicExampleMatrix();
85    //@}
86
87    /**@name Copy method */
88    //@{
89    /** The copy constructor. */
90    ClpDynamicExampleMatrix(const ClpDynamicExampleMatrix&);
91    ClpDynamicExampleMatrix& operator=(const ClpDynamicExampleMatrix&);
92    /// Clone
93    virtual ClpMatrixBase * clone() const ;
94    //@}
95    /**@name gets and sets */
96    //@{
97    /// Starts of each column
98    inline CoinBigIndex * startColumnGen() const {
99        return startColumnGen_;
100    }
101    /// rows
102    inline int * rowGen() const {
103        return rowGen_;
104    }
105    /// elements
106    inline double * elementGen() const {
107        return elementGen_;
108    }
109    /// costs
110    inline double * costGen() const {
111        return costGen_;
112    }
113    /// full starts
114    inline int * fullStartGen() const {
115        return fullStartGen_;
116    }
117    /// ids in next level matrix
118    inline int * idGen() const {
119        return idGen_;
120    }
121    /// Optional lower bounds on columns
122    inline double * columnLowerGen() const {
123        return columnLowerGen_;
124    }
125    /// Optional upper bounds on columns
126    inline double * columnUpperGen() const {
127        return columnUpperGen_;
128    }
129    /// size
130    inline int numberColumns() const {
131        return numberColumns_;
132    }
133    inline void setDynamicStatusGen(int sequence, DynamicStatus status) {
134        unsigned char & st_byte = dynamicStatusGen_[sequence];
135        st_byte = static_cast<unsigned char>(st_byte & ~7);
136        st_byte = static_cast<unsigned char>(st_byte | status);
137    }
138    inline DynamicStatus getDynamicStatusGen(int sequence) const {
139        return static_cast<DynamicStatus> (dynamicStatusGen_[sequence]&7);
140    }
141    /// Whether flagged
142    inline bool flaggedGen(int i) const {
143        return (dynamicStatusGen_[i]&8) != 0;
144    }
145    inline void setFlaggedGen(int i) {
146        dynamicStatusGen_[i] = static_cast<unsigned char>(dynamicStatusGen_[i] | 8);
147    }
148    inline void unsetFlagged(int i) {
149        dynamicStatusGen_[i] = static_cast<unsigned char>(dynamicStatusGen_[i] & ~8);
150    }
151    //@}
152
153
154protected:
155    /**@name Data members
156       The data members are protected to allow access for derived classes. */
157    //@{
158    /// size
159    int numberColumns_;
160    /// Starts of each column
161    CoinBigIndex * startColumnGen_;
162    /// rows
163    int * rowGen_;
164    /// elements
165    double * elementGen_;
166    /// costs
167    double * costGen_;
168    /// start of each set
169    int * fullStartGen_;
170    /// for status and which bound
171    unsigned char * dynamicStatusGen_;
172    /** identifier for each variable up one level (startColumn_, etc).  This is
173        of length maximumGubColumns_.  For this version it is just sequence number
174        at this level */
175    int * idGen_;
176    /// Optional lower bounds on columns
177    double * columnLowerGen_;
178    /// Optional upper bounds on columns
179    double * columnUpperGen_;
180    //@}
181};
182
183#endif
Note: See TracBrowser for help on using the repository browser.