source: trunk/PresolveIsolated.cpp @ 57

Last change on this file since 57 was 57, checked in by forrest, 17 years ago

Yet more changes for Visual C++

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1#include <stdio.h>
2#include <math.h>
3
4#include "PresolveMatrix.hpp"
5#include "PresolveIsolated.hpp"
6
7
8// Rarely, there may a constraint whose variables only
9// occur in that constraint.
10// In this case it is a completely independent problem.
11// We should be able to solve it right now.
12// Since that is actually not trivial, I'm just going to ignore
13// them and stick them back in at postsolve.
14const PresolveAction *isolated_constraint_action::presolve(PresolveMatrix *prob,
15                                                            int irow,
16                                                            const PresolveAction *next)
17{
18  int *hincol   = prob->hincol_;
19  const CoinBigIndex *mcstrt    = prob->mcstrt_;
20  int *hrow     = prob->hrow_;
21  double *colels        = prob->colels_;
22
23  double *clo   = prob->clo_;
24  double *cup   = prob->cup_;
25
26  const double *rowels  = prob->rowels_;
27  const int *hcol       = prob->hcol_;
28  const CoinBigIndex *mrstrt    = prob->mrstrt_;
29
30  // may be written by useless constraint
31  int *hinrow   = prob->hinrow_;
32
33  double *rlo   = prob->rlo_;
34  double *rup   = prob->rup_;
35
36  CoinBigIndex krs = mrstrt[irow];
37  CoinBigIndex kre = krs + hinrow[irow];
38 
39  double *dcost = prob->cost_;
40
41#if     DEBUG_PRESOLVE
42  printf("ISOLATED:  %d - ", irow);
43  for (CoinBigIndex k = krs; k<kre; ++k)
44    printf("%d ", hcol[k]);
45  printf("\n");
46#endif
47
48  if (rlo[irow] != 0.0 || rup[irow] != 0.0) {
49#if     DEBUG_PRESOLVE
50    printf("can't handle non-trivial isolated constraints for now\n");
51#endif
52    return NULL;
53  }
54  CoinBigIndex k;
55  for ( 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 (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 ( 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  int k;
140
141  for (k=0; k<this->ninrow_; k++) {
142    int jcol = this->rowcols_[k];
143
144    sol[jcol] = 0.0;    // ONLY ACCEPTED SUCH CONSTRAINTS
145
146    CoinBigIndex kk = free_list;
147    free_list = link[free_list];
148
149    check_free_list(free_list);
150
151    mcstrt[jcol] = kk;
152
153    //rowact += rowels[k] * sol[jcol];
154
155    colels[kk] = this->rowels_[k];
156    hrow[kk]   = irow;
157
158    hincol[jcol] = 1;
159  }
160
161  // ???
162  prob->setRowStatus(irow,PrePostsolveMatrix::basic);
163    rowduals[irow] = 0.0;
164
165  rowacts[irow] = rowact;
166
167  prob->free_list_ = free_list;
168}
169
Note: See TracBrowser for help on using the repository browser.