source: trunk/PresolveUseless.cpp @ 56

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

Idiot and modifications 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#include "PresolveMatrix.hpp"
4#include "PresolveUseless.hpp"
5
6
7// WHAT HAPPENS IF COLS ARE DROPPED AS A RESULT??
8// should be like do_tighten.
9// not really - one could fix costed variables to appropriate bound.
10// ok, don't bother about it.  If it is costed, it will be checked
11// when it is eliminated as an empty col; if it is costed in the
12// wrong direction, the problem is unbounded, otherwise it is pegged
13// at its bound.  no special action need be taken here.
14const PresolveAction *useless_constraint_action::presolve(PresolveMatrix * prob,
15                                                                  const int *useless_rows,
16                                                                  int nuseless_rows,
17                                       const PresolveAction *next)
18{
19  // may be modified by useless constraint
20  double *colels        = prob->colels_;
21
22  // may be modified by useless constraint
23        int *hrow       = prob->hrow_;
24
25  const CoinBigIndex *mcstrt    = prob->mcstrt_;
26
27  // may be modified by useless constraint
28        int *hincol     = prob->hincol_;
29
30        //  double *clo = prob->clo_;
31        //  double *cup = prob->cup_;
32
33  const double *rowels  = prob->rowels_;
34  const int *hcol       = prob->hcol_;
35  const CoinBigIndex *mrstrt    = prob->mrstrt_;
36
37  // may be written by useless constraint
38        int *hinrow     = prob->hinrow_;
39        //  const int nrows     = prob->nrows_;
40
41  double *rlo   = prob->rlo_;
42  double *rup   = prob->rup_;
43
44  action *actions       = new action [nuseless_rows];
45
46#if     PRESOLVE_SUMMARY
47    printf("NUSELESS ROWS:  %d\n", nuseless_rows);
48#endif
49
50  for (int i=0; i<nuseless_rows; ++i) {
51    int irow = useless_rows[i];
52    CoinBigIndex krs = mrstrt[irow];
53    CoinBigIndex kre = krs + hinrow[irow];
54
55    action *f = &actions[i];
56
57    f->row = irow;
58    f->ninrow = hinrow[irow];
59    f->rlo = rlo[irow];
60    f->rup = rup[irow];
61    f->rowcols = copyOfArray(&hcol[krs], hinrow[irow]);
62    f->rowels  = copyOfArray(&rowels[krs], hinrow[irow]);
63
64    for (CoinBigIndex k=krs; k<kre; k++)
65      presolve_delete_from_row(hcol[k], irow, mcstrt, hincol, hrow, colels);
66    hinrow[irow] = 0;
67
68    // just to make things squeeky
69    rlo[irow] = 0.0;
70    rup[irow] = 0.0;
71  }
72
73
74  next = new useless_constraint_action(nuseless_rows, actions, next);
75
76  return (next);
77}
78
79const char *useless_constraint_action::name() const
80{
81  return ("useless_constraint_action");
82}
83
84void useless_constraint_action::postsolve(PostsolveMatrix *prob) const
85{
86  const action *const actions = actions_;
87  const int nactions = nactions_;
88
89  double *colels        = prob->colels_;
90  int *hrow             = prob->hrow_;
91  CoinBigIndex *mcstrt          = prob->mcstrt_;
92  int *link             = prob->link_;
93  int *hincol           = prob->hincol_;
94 
95  //  double *rowduals  = prob->rowduals_;
96  double *rowacts       = prob->acts_;
97  const double *sol     = prob->sol_;
98
99
100  CoinBigIndex free_list                = prob->free_list_;
101
102  double *rlo   = prob->rlo_;
103  double *rup   = prob->rup_;
104
105  for (const action *f = &actions[nactions-1]; actions<=f; f--) {
106
107    int irow    = f->row;
108    int ninrow  = f->ninrow;
109    const int *rowcols  = f->rowcols;
110    const double *rowels = f->rowels;
111    double rowact = 0.0;
112
113    rup[irow] = f->rup;
114    rlo[irow] = f->rlo;
115
116    for (CoinBigIndex k=0; k<ninrow; k++) {
117      int jcol = rowcols[k];
118      //      CoinBigIndex kk = mcstrt[jcol];
119
120      // append deleted row element to each col
121      {
122        CoinBigIndex kk = free_list;
123        free_list = link[free_list];
124
125        check_free_list(free_list);
126
127        hrow[kk] = irow;
128        colels[kk] = rowels[k];
129        link[kk] = mcstrt[jcol];
130        mcstrt[jcol] = kk;
131      }
132     
133      rowact += rowels[k] * sol[jcol];
134      hincol[jcol]++;
135    }
136   
137    // I don't know if this is always true
138    PRESOLVEASSERT(prob->getRowStatus(irow)==PrePostsolveMatrix::basic);
139    // rcosts are unaffected since rowdual is 0
140
141    rowacts[irow] = rowact;
142  }
143  prob->free_list_ = free_list;
144}
145
146
Note: See TracBrowser for help on using the repository browser.