source: branches/devel-1/PresolveIsolated.cpp @ 2351

Last change on this file since 2351 was 45, checked in by forrest, 17 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: 3.8 KB
Line 
1#include <stdio.h>
2#include <math.h>
3#include <strings.h>
4
5#include "PresolveMatrix.hpp"
6#include "PresolveIsolated.hpp"
7
8
9// Rarely, there may a constraint whose variables only
10// occur in that constraint.
11// In this case it is a completely independent problem.
12// We should be able to solve it right now.
13// Since that is actually not trivial, I'm just going to ignore
14// them and stick them back in at postsolve.
15const PresolveAction *isolated_constraint_action::presolve(PresolveMatrix *prob,
16                                                            int irow,
17                                                            const PresolveAction *next)
18{
19  int *hincol   = prob->hincol_;
20  const CoinBigIndex *mcstrt    = prob->mcstrt_;
21  int *hrow     = prob->hrow_;
22  double *colels        = prob->colels_;
23
24  double *clo   = prob->clo_;
25  double *cup   = prob->cup_;
26
27  const double *rowels  = prob->rowels_;
28  const int *hcol       = prob->hcol_;
29  const CoinBigIndex *mrstrt    = prob->mrstrt_;
30
31  // may be written by useless constraint
32  int *hinrow   = prob->hinrow_;
33
34  double *rlo   = prob->rlo_;
35  double *rup   = prob->rup_;
36
37  CoinBigIndex krs = mrstrt[irow];
38  CoinBigIndex kre = krs + hinrow[irow];
39 
40  double *dcost = prob->cost_;
41
42#if     DEBUG_PRESOLVE
43  printf("ISOLATED:  %d - ", irow);
44  for (CoinBigIndex k = krs; k<kre; ++k)
45    printf("%d ", hcol[k]);
46  printf("\n");
47#endif
48
49  if (rlo[irow] != 0.0 || rup[irow] != 0.0) {
50#if     DEBUG_PRESOLVE
51    printf("can't handle non-trivial isolated constraints for now\n");
52#endif
53    return NULL;
54  }
55  for (CoinBigIndex k = krs; k<kre; ++k) {
56    int jcol = hcol[k];
57    if (clo[jcol] != 0.0 && cup[jcol] != 0.0) {
58#if     DEBUG_PRESOLVE
59      printf("can't handle non-trivial isolated constraints for now\n");
60#endif
61    return NULL;
62    }
63  }
64
65  int nc = hinrow[irow];
66
67#if 0
68  double tableau = new double[nc];
69  double sol = new double[nc];
70  double clo = new double[nc];
71  double cup = new double[nc];
72
73
74  for (int i=0; i<nc; ++i) {
75    int col = hcol[krs+1];
76    tableau[i] = rowels[krs+i];
77    clo[i] = prob->clo[krs+i];
78    cup[i] = prob->cup[krs+i];
79
80    sol[i] = clo[i];
81  }
82#endif
83
84  // HACK - set costs to 0.0 so empty.cpp doesn't complain
85  double *costs = new double[nc];
86  for (CoinBigIndex k = krs; k<kre; ++k) {
87    costs[k-krs] = dcost[hcol[k]];
88    dcost[hcol[k]] = 0.0;
89  }
90 
91  next = new isolated_constraint_action(rlo[irow], rup[irow],
92                                        irow, nc,
93                                        copyOfArray(&hcol[krs], nc*sizeof(int)),
94                                        copyOfArray(&rowels[krs], nc*sizeof(double)),
95                                        costs,
96                                        next);
97
98  for (CoinBigIndex k=krs; k<kre; k++)
99    presolve_delete_from_row(hcol[k], irow, mcstrt, hincol, hrow, colels);
100  hinrow[irow] = 0;
101
102  // just to make things squeeky
103  rlo[irow] = 0.0;
104  rup[irow] = 0.0;
105
106  return (next);
107}
108
109const char *isolated_constraint_action::name() const
110{
111  return ("isolated_constraint_action");
112}
113
114void isolated_constraint_action::postsolve(PostsolveMatrix *prob) const
115{
116  double *colels        = prob->colels_;
117  int *hrow             = prob->hrow_;
118  CoinBigIndex *mcstrt          = prob->mcstrt_;
119  int *link             = prob->link_;
120  int *hincol           = prob->hincol_;
121 
122  double *rowduals      = prob->rowduals_;
123  double *rowacts       = prob->acts_;
124  double *sol           = prob->sol_;
125
126  CoinBigIndex free_list                = prob->free_list_;
127
128
129  // hides fields
130  double *rlo   = prob->rlo_;
131  double *rup   = prob->rup_;
132
133  double rowact = 0.0;
134
135  int irow  = this->row_;
136
137  rup[irow] = this->rup_;
138  rlo[irow] = this->rlo_;
139
140  for (int k=0; k<this->ninrow_; k++) {
141    int jcol = this->rowcols_[k];
142
143    sol[jcol] = 0.0;    // ONLY ACCEPTED SUCH CONSTRAINTS
144
145    CoinBigIndex kk = free_list;
146    free_list = link[free_list];
147
148    check_free_list(free_list);
149
150    mcstrt[jcol] = kk;
151
152    //rowact += rowels[k] * sol[jcol];
153
154    colels[kk] = this->rowels_[k];
155    hrow[kk]   = irow;
156
157    hincol[jcol] = 1;
158  }
159
160  // ???
161  prob->setRowStatus(irow,PrePostsolveMatrix::basic);
162    rowduals[irow] = 0.0;
163
164  rowacts[irow] = rowact;
165
166  prob->free_list_ = free_list;
167}
168
Note: See TracBrowser for help on using the repository browser.