source: branches/devel-1/ClpFactorization.cpp

Last change on this file was 45, checked in by forrest, 18 years ago

First try at over 2 giga-elements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7
8#include "ClpFactorization.hpp"
9#include "CoinHelperFunctions.hpp"
10#include "ClpSimplex.hpp"
11#include "ClpMatrixBase.hpp"
12
13
14//#############################################################################
15// Constructors / Destructor / Assignment
16//#############################################################################
17
18//-------------------------------------------------------------------
19// Default Constructor
20//-------------------------------------------------------------------
21ClpFactorization::ClpFactorization () :
22   CoinFactorization() {}
23
24//-------------------------------------------------------------------
25// Copy constructor
26//-------------------------------------------------------------------
27ClpFactorization::ClpFactorization (const ClpFactorization & rhs) :
28   CoinFactorization(rhs) {}
29
30ClpFactorization::ClpFactorization (const CoinFactorization & rhs) :
31   CoinFactorization(rhs) {}
32
33//-------------------------------------------------------------------
34// Destructor
35//-------------------------------------------------------------------
36ClpFactorization::~ClpFactorization () {}
37
38//----------------------------------------------------------------
39// Assignment operator
40//-------------------------------------------------------------------
41ClpFactorization &
42ClpFactorization::operator=(const ClpFactorization& rhs)
43{
44  if (this != &rhs) {
45    CoinFactorization::operator=(rhs);
46  }
47  return *this;
48}
49int 
50ClpFactorization::factorize ( const ClpSimplex * model,
51                              const ClpMatrixBase * matrix, 
52                              int numberRows, int numberColumns,
53                              int rowIsBasic[], int columnIsBasic[] , 
54                              double areaFactor )
55{
56  // maybe for speed will be better to leave as many regions as possible
57  gutsOfDestructor();
58  gutsOfInitialize(2);
59  if (areaFactor)
60    areaFactor_ = areaFactor;
61  int numberBasic = 0;
62  CoinBigIndex numberElements=0;
63  int numberRowBasic=0;
64
65  // compute how much in basis
66
67  int i;
68
69  for (i=0;i<numberRows;i++) {
70    if (rowIsBasic[i]>=0)
71      numberRowBasic++;
72  }
73
74  numberBasic = numberRowBasic;
75  for (i=0;i<numberColumns;i++) {
76    if (columnIsBasic[i]>=0) {
77      numberBasic++;
78    }
79  }
80  numberElements += matrix->numberInBasis(columnIsBasic);
81  if ( numberBasic > numberRows ) {
82    return -2; // say too many in basis
83  }
84  numberElements = 3 * numberBasic + 3 * numberElements + 10000;
85  getAreas ( numberRows, numberBasic, numberElements,
86             2 * numberElements );
87  //fill
88  //copy
89  numberBasic=0;
90  numberElements=0;
91  for (i=0;i<numberRows;i++) {
92    if (rowIsBasic[i]>=0) {
93      indexRowU_[numberElements]=i;
94      indexColumnU_[numberElements]=numberBasic;
95      elementU_[numberElements++]=slackValue_;
96      numberBasic++;
97    }
98  }
99  numberElements +=matrix->fillBasis(model, columnIsBasic, numberBasic, 
100                                     indexRowU_+numberElements, 
101                                     indexColumnU_+numberElements,
102                                     elementU_+numberElements);
103  lengthU_ = numberElements;
104
105  preProcess ( 0 );
106  factor (  );
107  numberBasic=0;
108  if (status_ == 0) {
109    int * permuteBack = permuteBack_;
110    int * back = pivotColumnBack_;
111    for (i=0;i<numberRows;i++) {
112      if (rowIsBasic[i]>=0) {
113        rowIsBasic[i]=permuteBack[back[numberBasic++]];
114      }
115    }
116    for (i=0;i<numberColumns;i++) {
117      if (columnIsBasic[i]>=0) {
118        columnIsBasic[i]=permuteBack[back[numberBasic++]];
119      }
120    }
121    if (increasingRows_>1) {
122      // Set up permutation vector
123      if (increasingRows_<3) {
124        // these arrays start off as copies of permute
125        // (and we could use permute_ instead of pivotColumn (not back though))
126        ClpDisjointCopyN ( permute_, numberRows_ , pivotColumn_  );
127        ClpDisjointCopyN ( permuteBack_, numberRows_ , pivotColumnBack_  );
128      }
129    } else {
130      // Set up permutation vector
131      // (we could use permute_ instead of pivotColumn (not back though))
132      for (i=0;i<numberRows_;i++) {
133        int k=pivotColumn_[i];
134        pivotColumn_[i]=pivotColumnBack_[i];
135        pivotColumnBack_[i]=k;
136      }
137    }
138  } else if (status_ == -1) {
139    // mark as basic or non basic
140    for (i=0;i<numberRows_;i++) {
141      if (rowIsBasic[i]>=0) {
142        if (pivotColumn_[numberBasic]>=0) 
143          rowIsBasic[i]=pivotColumn_[numberBasic];
144        else
145          rowIsBasic[i]=-1;
146        numberBasic++;
147      }
148    }
149    for (i=0;i<numberColumns;i++) {
150      if (columnIsBasic[i]>=0) {
151        if (pivotColumn_[numberBasic]>=0) 
152          columnIsBasic[i]=pivotColumn_[numberBasic];
153        else
154          columnIsBasic[i]=-1;
155        numberBasic++;
156      }
157    }
158  }
159
160  return status_;
161}
Note: See TracBrowser for help on using the repository browser.