1 | /* $Id: AbcDualRowSteepest.hpp 1910 2013-01-27 02:00:13Z stefan $ */ |
---|
2 | // Copyright (C) 2002, International Business Machines |
---|
3 | // Corporation and others, Copyright (C) 2012, FasterCoin. All Rights Reserved. |
---|
4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
---|
5 | |
---|
6 | #ifndef AbcDualRowSteepest_H |
---|
7 | #define AbcDualRowSteepest_H |
---|
8 | |
---|
9 | #include "AbcDualRowPivot.hpp" |
---|
10 | class CoinIndexedVector; |
---|
11 | |
---|
12 | |
---|
13 | //############################################################################# |
---|
14 | |
---|
15 | /** Dual Row Pivot Steepest Edge Algorithm Class |
---|
16 | |
---|
17 | See Forrest-Goldfarb paper for algorithm |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | class AbcDualRowSteepest : public AbcDualRowPivot { |
---|
22 | |
---|
23 | public: |
---|
24 | |
---|
25 | ///@name Algorithmic methods |
---|
26 | //@{ |
---|
27 | |
---|
28 | /// Returns pivot row, -1 if none |
---|
29 | virtual int pivotRow(); |
---|
30 | |
---|
31 | /** Updates weights and returns pivot alpha. |
---|
32 | Also does FT update */ |
---|
33 | virtual double updateWeights(CoinIndexedVector & input,CoinIndexedVector & updatedColumn); |
---|
34 | virtual double updateWeights1(CoinIndexedVector & input,CoinIndexedVector & updateColumn); |
---|
35 | virtual void updateWeightsOnly(CoinIndexedVector & input); |
---|
36 | /// Actually updates weights |
---|
37 | virtual void updateWeights2(CoinIndexedVector & input,CoinIndexedVector & updateColumn); |
---|
38 | |
---|
39 | /** Updates primal solution (and maybe list of candidates) |
---|
40 | Uses input vector which it deletes |
---|
41 | */ |
---|
42 | virtual void updatePrimalSolution(CoinIndexedVector & input, |
---|
43 | double theta); |
---|
44 | |
---|
45 | virtual void updatePrimalSolutionAndWeights(CoinIndexedVector & weightsVector, |
---|
46 | CoinIndexedVector & updateColumn, |
---|
47 | double theta); |
---|
48 | /** Saves any weights round factorization as pivot rows may change |
---|
49 | Save model |
---|
50 | May also recompute infeasibility stuff |
---|
51 | 1) before factorization |
---|
52 | 2) after good factorization (if weights empty may initialize) |
---|
53 | 3) after something happened but no factorization |
---|
54 | (e.g. check for infeasible) |
---|
55 | 4) as 2 but restore weights from previous snapshot |
---|
56 | 5) for strong branching - initialize (uninitialized) , infeasibilities |
---|
57 | */ |
---|
58 | virtual void saveWeights(AbcSimplex * model, int mode); |
---|
59 | /// Recompute infeasibilities |
---|
60 | virtual void recomputeInfeasibilities(); |
---|
61 | /// Gets rid of all arrays |
---|
62 | virtual void clearArrays(); |
---|
63 | /// Returns true if would not find any row |
---|
64 | virtual bool looksOptimal() const; |
---|
65 | //@} |
---|
66 | |
---|
67 | /** enums for persistence |
---|
68 | */ |
---|
69 | enum Persistence { |
---|
70 | normal = 0x00, // create (if necessary) and destroy |
---|
71 | keep = 0x01 // create (if necessary) and leave |
---|
72 | }; |
---|
73 | |
---|
74 | ///@name Constructors and destructors |
---|
75 | //@{ |
---|
76 | /** Default Constructor |
---|
77 | 0 is uninitialized, 1 full, 2 is partial uninitialized, |
---|
78 | 3 starts as 2 but may switch to 1. |
---|
79 | By partial is meant that the weights are updated as normal |
---|
80 | but only part of the infeasible basic variables are scanned. |
---|
81 | This can be faster on very easy problems. |
---|
82 | */ |
---|
83 | AbcDualRowSteepest(int mode = 3); |
---|
84 | |
---|
85 | /// Copy constructor |
---|
86 | AbcDualRowSteepest(const AbcDualRowSteepest &); |
---|
87 | |
---|
88 | /// Assignment operator |
---|
89 | AbcDualRowSteepest & operator=(const AbcDualRowSteepest& rhs); |
---|
90 | |
---|
91 | /// Fill most values |
---|
92 | void fill(const AbcDualRowSteepest& rhs); |
---|
93 | |
---|
94 | /// Destructor |
---|
95 | virtual ~AbcDualRowSteepest (); |
---|
96 | |
---|
97 | /// Clone |
---|
98 | virtual AbcDualRowPivot * clone(bool copyData = true) const; |
---|
99 | |
---|
100 | //@} |
---|
101 | /**@name gets and sets */ |
---|
102 | //@{ |
---|
103 | /// Mode |
---|
104 | inline int mode() const { |
---|
105 | return mode_; |
---|
106 | } |
---|
107 | /// Set/ get persistence |
---|
108 | inline void setPersistence(Persistence life) { |
---|
109 | persistence_ = life; |
---|
110 | } |
---|
111 | inline Persistence persistence() const { |
---|
112 | return persistence_ ; |
---|
113 | } |
---|
114 | /// Infeasible vector |
---|
115 | inline CoinIndexedVector * infeasible() const |
---|
116 | { return infeasible_;} |
---|
117 | /// Weights vector |
---|
118 | inline CoinIndexedVector * weights() const |
---|
119 | { return weights_;} |
---|
120 | /// Model |
---|
121 | inline AbcSimplex * model() const |
---|
122 | { return model_;} |
---|
123 | //@} |
---|
124 | |
---|
125 | //--------------------------------------------------------------------------- |
---|
126 | |
---|
127 | private: |
---|
128 | ///@name Private member data |
---|
129 | /// norm saved before going into update |
---|
130 | double norm_; |
---|
131 | /// Ratio of size of factorization to number of rows |
---|
132 | double factorizationRatio_; |
---|
133 | /** Status |
---|
134 | 0) Normal |
---|
135 | -1) Needs initialization |
---|
136 | 1) Weights are stored by sequence number |
---|
137 | */ |
---|
138 | int state_; |
---|
139 | /** If 0 then we are using uninitialized weights, 1 then full, |
---|
140 | if 2 then uninitialized partial, 3 switchable */ |
---|
141 | int mode_; |
---|
142 | /// Life of weights |
---|
143 | Persistence persistence_; |
---|
144 | /// weight array |
---|
145 | CoinIndexedVector * weights_; |
---|
146 | /// square of infeasibility array (just for infeasible rows) |
---|
147 | CoinIndexedVector * infeasible_; |
---|
148 | /// save weight array (so we can use checkpoint) |
---|
149 | CoinIndexedVector * savedWeights_; |
---|
150 | //@} |
---|
151 | }; |
---|
152 | |
---|
153 | // For Devex stuff |
---|
154 | #undef DEVEX_TRY_NORM |
---|
155 | #define DEVEX_TRY_NORM 1.0e-8 |
---|
156 | #define DEVEX_ADD_ONE 1.0 |
---|
157 | #endif |
---|