source: trunk/ClpFactorization.cpp @ 63

Last change on this file since 63 was 63, checked in by jpfasano, 17 years ago

-modified to use CoinPragma?.h
-modified to compile w/MS Visual C++ and gcc (on cygwin) without errors or warnings.

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