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

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

Presolve (no changes to Makefile)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 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 int *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 int *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  int krs = mrstrt[irow];
38  int kre = krs + hinrow[irow];
39 
40  double *dcost = prob->cost_;
41
42#if     DEBUG_PRESOLVE
43  printf("ISOLATED:  %d - ", irow);
44  for (int 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    DIE("can't handle non-trivial isolated constraints for now\n");
51
52  for (int k = krs; k<kre; ++k) {
53    int jcol = hcol[k];
54    if (clo[jcol] != 0.0 && cup[jcol] != 0.0)
55      DIE("can't handle non-trivial isolated constraints for now\n");
56  }
57
58  int nc = hinrow[irow];
59
60#if 0
61  double tableau = new double[nc];
62  double sol = new double[nc];
63  double clo = new double[nc];
64  double cup = new double[nc];
65
66
67  for (int i=0; i<nc; ++i) {
68    int col = hcol[krs+1];
69    tableau[i] = rowels[krs+i];
70    clo[i] = prob->clo[krs+i];
71    cup[i] = prob->cup[krs+i];
72
73    sol[i] = clo[i];
74  }
75#endif
76
77  // HACK - set costs to 0.0 so empty.cpp doesn't complain
78  double *costs = new double[nc];
79  for (int k = krs; k<kre; ++k) {
80    costs[k-krs] = dcost[hcol[k]];
81    dcost[hcol[k]] = 0.0;
82  }
83 
84  next = new isolated_constraint_action(rlo[irow], rup[irow],
85                                        irow, nc,
86                                        copyOfArray(&hcol[krs], nc*sizeof(int)),
87                                        copyOfArray(&rowels[krs], nc*sizeof(double)),
88                                        costs,
89                                        next);
90
91  for (int k=krs; k<kre; k++)
92    presolve_delete_from_row(hcol[k], irow, mcstrt, hincol, hrow, colels);
93  hinrow[irow] = 0;
94
95  // just to make things squeeky
96  rlo[irow] = 0.0;
97  rup[irow] = 0.0;
98
99  return (next);
100}
101
102const char *isolated_constraint_action::name() const
103{
104  return ("isolated_constraint_action");
105}
106
107void isolated_constraint_action::postsolve(PostsolveMatrix *prob) const
108{
109  double *colels        = prob->colels_;
110  int *hrow             = prob->hrow_;
111  int *mcstrt           = prob->mcstrt_;
112  int *link             = prob->link_;
113  int *hincol           = prob->hincol_;
114 
115  double *rowduals      = prob->rowduals_;
116  double *rowacts       = prob->acts_;
117  double *sol           = prob->sol_;
118
119  int free_list         = prob->free_list_;
120
121
122  // hides fields
123  double *rlo   = prob->rlo_;
124  double *rup   = prob->rup_;
125
126  double rowact = 0.0;
127
128  int irow  = this->row_;
129
130  rup[irow] = this->rup_;
131  rlo[irow] = this->rlo_;
132
133  for (int k=0; k<this->ninrow_; k++) {
134    int jcol = this->rowcols_[k];
135
136    sol[jcol] = 0.0;    // ONLY ACCEPTED SUCH CONSTRAINTS
137
138    int kk = free_list;
139    free_list = link[free_list];
140
141    check_free_list(free_list);
142
143    mcstrt[jcol] = kk;
144
145    //rowact += rowels[k] * sol[jcol];
146
147    colels[kk] = this->rowels_[k];
148    hrow[kk]   = irow;
149
150    hincol[jcol] = 1;
151  }
152
153  // ???
154  prob->setRowStatus(irow,PrePostsolveMatrix::basic);
155    rowduals[irow] = 0.0;
156
157  rowacts[irow] = rowact;
158
159  prob->free_list_ = free_list;
160}
161
Note: See TracBrowser for help on using the repository browser.