1/* $Id: CoinPresolveFixed.hpp 1372 2011-01-03 23:31:00Z lou $ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others. All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef CoinPresolveFixed_H
7#define CoinPresolveFixed_H
8#define FIXED_VARIABLE 1
9
10/*! \class remove_fixed_action
11 \brief Excise fixed variables from the model.
12
13 Implements the action of removing one or more fixed variables x_j from the
14 model by substituting the value sol_j in each constraint. Specifically,
15 for each constraint i where a_ij != 0, rlo_i and rup_i are adjusted by
16 -a_ij*sol_j and a_ij is set to 0.
17
18 There is an implicit assumption that the variable already has the correct
19 value. If this isn't true, corrections to row activity may be incorrect.
20 If you want to guard against this possibility, consider make_fixed_action.
21
22 Actual removal of the column from the matrix is handled by
23 drop_empty_cols_action. Correction of the objective function is done there.
24*/
25class remove_fixed_action : public CoinPresolveAction {
26 public:
27 /*! \brief Structure to hold information necessary to reintroduce a
28 column into the problem representation.
29 */
30 struct action {
31 int col; ///< column index of variable
32 int start; ///< start of coefficients in #colels_ and #colrows_
33 double sol; ///< value of variable
34 };
35 /// Array of row indices for coefficients of excised columns
36 int *colrows_;
37 /// Array of coefficients of excised columns
38 double *colels_;
39 /// Number of entries in #actions_
40 int nactions_;
41 /// Vector specifying variable(s) affected by this object
42 action *actions_;
43
44 private:
45 /*! \brief Constructor */
46 remove_fixed_action(int nactions,
47 action *actions,
48 double * colels,
49 int * colrows,
50 const CoinPresolveAction *next);
51
52 public:
53 /// Returns string "remove_fixed_action".
54 const char *name() const;
55
56 /*! \brief Excise the specified columns.
57
58 Remove the specified columns (\p nfcols, \p fcols) from the problem
59 representation (\p prob), leaving the appropriate postsolve object
60 linked as the head of the list of postsolve objects (currently headed
61 by \p next).
62 */
63 static const remove_fixed_action *presolve(CoinPresolveMatrix *prob,
64 int *fcols,
65 int nfcols,
66 const CoinPresolveAction *next);
67
68 void postsolve(CoinPostsolveMatrix *prob) const;
69
70 /// Destructor
71 ~remove_fixed_action();
72};
73
74
75/*! \relates remove_fixed_action
76 \brief Scan the problem for fixed columns and remove them.
77
78 A front end to collect a list of columns with equal bounds and hand them to
79 remove_fixed_action::presolve() for processing.
80*/
81
82const CoinPresolveAction *remove_fixed(CoinPresolveMatrix *prob,
83 const CoinPresolveAction *next);
84
85
86/*! \class make_fixed_action
87 \brief Fix a variable at a specified bound.
88
89 Implements the action of fixing a variable by forcing both bounds to the same
90 value and forcing the value of the variable to match.
91
92 If the bounds are already equal, and the value of the variable is already
93 correct, consider remove_fixed_action.
94*/
95class make_fixed_action : public CoinPresolveAction {
96
97 /// Structure to preserve the bound overwritten when fixing a variable
98 struct action {
99 double bound; ///< Value of bound overwritten to fix variable.
100 int col ; ///< column index of variable
101 };
102
103 /// Number of preserved bounds
104 int nactions_;
105 /// Vector of preserved bounds, one for each variable fixed in this object
106 const action *actions_;
107
108 /*! \brief True to fix at lower bound, false to fix at upper bound.
109
110 Note that this applies to all variables fixed in this object.
111 */
112 const bool fix_to_lower_;
113
114 /// The postsolve object with information to undo the fix(es).
115 const remove_fixed_action *faction_;
116
117 /*! \brief Constructor */
118 make_fixed_action(int nactions,
119 const action *actions,
120 bool fix_to_lower,
121 const remove_fixed_action *faction,
122 const CoinPresolveAction *next) :
123 CoinPresolveAction(next),
124 nactions_(nactions), actions_(actions),
125 fix_to_lower_(fix_to_lower),
126 faction_(faction)
127 {}
128
129 public:
130 /// Returns string "make_fixed_action".
131 const char *name() const;
132
133 /*! \brief Perform actions to fix variables and return postsolve object
134
135 For each specified variable (\p nfcols, \p fcols), fix the variable to
136 the specified bound (\p fix_to_lower) by setting the variable's bounds
137 to be equal in \p prob. Create a postsolve object, link it at the head of
138 the list of postsolve objects (\p next), and return the object.
139 */
140 static const CoinPresolveAction *presolve(CoinPresolveMatrix *prob,
141 int *fcols,
142 int nfcols,
143 bool fix_to_lower,
144 const CoinPresolveAction *next);
145
146 /*! \brief Postsolve (unfix variables)
147
148 Back out the variables fixed by the presolve side of this object.
149 */
150 void postsolve(CoinPostsolveMatrix *prob) const;
151
152 /// Destructor
153 ~make_fixed_action() {
154 deleteAction(actions_,action*);
155 delete faction_;
156 }
157};
158
159/*! \relates make_fixed_action
160 \brief Scan variables and fix any with equal bounds
161
162 A front end to collect a list of columns with equal bounds and hand them to
163 make_fixed_action::presolve() for processing.
164*/
165
166const CoinPresolveAction *make_fixed(CoinPresolveMatrix *prob,
167 const CoinPresolveAction *next);
168/// Transfers costs
169void transferCosts(CoinPresolveMatrix * prob);
170#endif
171