source: branches/devel-1/ClpFactorization.cpp @ 3

Last change on this file since 3 was 2, checked in by forrest, 18 years ago

Adding Clp to development branch

  • 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  : OsiFactorization()
23{
24}
25
26//-------------------------------------------------------------------
27// Copy constructor
28//-------------------------------------------------------------------
29ClpFactorization::ClpFactorization (const ClpFactorization & rhs) 
30: OsiFactorization(rhs)
31{ 
32 
33}
34
35ClpFactorization::ClpFactorization (const OsiFactorization & rhs) 
36: OsiFactorization(rhs)
37{ 
38 
39}
40
41//-------------------------------------------------------------------
42// Destructor
43//-------------------------------------------------------------------
44ClpFactorization::~ClpFactorization ()
45{
46}
47
48//----------------------------------------------------------------
49// Assignment operator
50//-------------------------------------------------------------------
51ClpFactorization &
52ClpFactorization::operator=(const ClpFactorization& rhs)
53{
54  if (this != &rhs) {
55    OsiFactorization::operator=(rhs);
56  }
57  return *this;
58}
59int 
60ClpFactorization::factorize ( const ClpSimplex * model,
61                              const ClpMatrixBase * matrix, 
62                              int numberRows, int numberColumns,
63                              int rowIsBasic[], int columnIsBasic[] , 
64                              double areaFactor )
65{
66  // maybe for speed will be better to leave as many regions as possible
67  gutsOfDestructor();
68  gutsOfInitialize(2);
69  if (areaFactor)
70    areaFactor_ = areaFactor;
71  int numberBasic = 0;
72  OsiBigIndex numberElements=0;
73  int numberRowBasic=0;
74
75  // compute how much in basis
76
77  int i;
78
79  for (i=0;i<numberRows;i++) {
80    if (rowIsBasic[i]>=0)
81      numberRowBasic++;
82  }
83
84  numberBasic = numberRowBasic;
85  for (i=0;i<numberColumns;i++) {
86    if (columnIsBasic[i]>=0) {
87      numberBasic++;
88    }
89  }
90  numberElements += matrix->numberInBasis(columnIsBasic);
91  if ( numberBasic > numberRows ) {
92    return -2; // say too many in basis
93  }                             
94  numberElements = 3 * numberBasic + 3 * numberElements + 10000;
95  getAreas ( numberRows, numberBasic, numberElements,
96             2 * numberElements );
97  //fill
98  //copy
99  numberBasic=0;
100  numberElements=0;
101  for (i=0;i<numberRows;i++) {
102    if (rowIsBasic[i]>=0) {
103      indexRowU_[numberElements]=i;
104      indexColumnU_[numberElements]=numberBasic;
105      elementU_[numberElements++]=slackValue_;
106      numberBasic++;
107    }
108  }
109  numberElements +=matrix->fillBasis(model, columnIsBasic, numberBasic, 
110                                     indexRowU_+numberElements, 
111                                     indexColumnU_+numberElements,
112                                     elementU_+numberElements);
113  lengthU_ = numberElements;
114
115  preProcess ( 0 );
116  factor (  );
117  numberBasic=0;
118  if (status_ == 0) {
119    int * permuteBack = permuteBack_;
120    int * back = pivotColumnBack_;
121    for (i=0;i<numberRows;i++) {
122      if (rowIsBasic[i]>=0) {
123        rowIsBasic[i]=permuteBack[back[numberBasic++]];
124      }
125    }
126    for (i=0;i<numberColumns;i++) {
127      if (columnIsBasic[i]>=0) {
128        columnIsBasic[i]=permuteBack[back[numberBasic++]];
129      }
130    }
131    if (increasingRows_>1) {
132      // Set up permutation vector
133      if (increasingRows_<3) {
134        // these arrays start off as copies of permute
135        // (and we could use permute_ instead of pivotColumn (not back though))
136        CoinDisjointCopyN ( permute_, numberRows_ , pivotColumn_  );
137        CoinDisjointCopyN ( permuteBack_, numberRows_ , pivotColumnBack_  );
138      }
139    } else {
140      // Set up permutation vector
141      // (we could use permute_ instead of pivotColumn (not back though))
142      for (i=0;i<numberRows_;i++) {
143        int k=pivotColumn_[i];
144        pivotColumn_[i]=pivotColumnBack_[i];
145        pivotColumnBack_[i]=k;
146      }
147    }
148  } else if (status_ == -1) {
149    // mark as basic or non basic
150    for (i=0;i<numberRows_;i++) {
151      if (rowIsBasic[i]>=0) {
152        if (pivotColumn_[numberBasic]>=0) 
153          rowIsBasic[i]=pivotColumn_[numberBasic];
154        else
155          rowIsBasic[i]=-1;
156        numberBasic++;
157      }
158    }
159    for (i=0;i<numberColumns;i++) {
160      if (columnIsBasic[i]>=0) {
161        if (pivotColumn_[numberBasic]>=0) 
162          columnIsBasic[i]=pivotColumn_[numberBasic];
163        else
164          columnIsBasic[i]=-1;
165        numberBasic++;
166      }
167    }
168  }
169
170  return status_;
171}
Note: See TracBrowser for help on using the repository browser.