source: trunk/Clp/src/ClpSimplexOther.hpp @ 1860

Last change on this file since 1860 was 1860, checked in by forrest, 8 years ago

make test on maximum theta in parametrics more robust

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.4 KB
Line 
1/* $Id: ClpSimplexOther.hpp 1860 2012-05-31 13:40:26Z forrest $ */
2// Copyright (C) 2004, 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   Authors
7
8   John Forrest
9
10 */
11#ifndef ClpSimplexOther_H
12#define ClpSimplexOther_H
13
14#include "ClpSimplex.hpp"
15
16/** This is for Simplex stuff which is neither dual nor primal
17
18    It inherits from ClpSimplex.  It has no data of its own and
19    is never created - only cast from a ClpSimplex object at algorithm time.
20
21*/
22
23class ClpSimplexOther : public ClpSimplex {
24
25public:
26
27     /**@name Methods */
28     //@{
29     /** Dual ranging.
30         This computes increase/decrease in cost for each given variable and corresponding
31         sequence numbers which would change basis.  Sequence numbers are 0..numberColumns
32         and numberColumns.. for artificials/slacks.
33         For non-basic variables the information is trivial to compute and the change in cost is just minus the
34         reduced cost and the sequence number will be that of the non-basic variables.
35         For basic variables a ratio test is between the reduced costs for non-basic variables
36         and the row of the tableau corresponding to the basic variable.
37         The increase/decrease value is always >= 0.0
38
39         Up to user to provide correct length arrays where each array is of length numberCheck.
40         which contains list of variables for which information is desired.  All other
41         arrays will be filled in by function.  If fifth entry in which is variable 7 then fifth entry in output arrays
42         will be information for variable 7.
43
44         If valueIncrease/Decrease not NULL (both must be NULL or both non NULL) then these are filled with
45         the value of variable if such a change in cost were made (the existing bounds are ignored)
46
47         When here - guaranteed optimal
48     */
49     void dualRanging(int numberCheck, const int * which,
50                      double * costIncrease, int * sequenceIncrease,
51                      double * costDecrease, int * sequenceDecrease,
52                      double * valueIncrease = NULL, double * valueDecrease = NULL);
53     /** Primal ranging.
54         This computes increase/decrease in value for each given variable and corresponding
55         sequence numbers which would change basis.  Sequence numbers are 0..numberColumns
56         and numberColumns.. for artificials/slacks.
57         This should only be used for non-basic variabls as otherwise information is pretty useless
58         For basic variables the sequence number will be that of the basic variables.
59
60         Up to user to provide correct length arrays where each array is of length numberCheck.
61         which contains list of variables for which information is desired.  All other
62         arrays will be filled in by function.  If fifth entry in which is variable 7 then fifth entry in output arrays
63         will be information for variable 7.
64
65         When here - guaranteed optimal
66     */
67     void primalRanging(int numberCheck, const int * which,
68                        double * valueIncrease, int * sequenceIncrease,
69                        double * valueDecrease, int * sequenceDecrease);
70     /** Parametrics
71         This is an initial slow version.
72         The code uses current bounds + theta * change (if change array not NULL)
73         and similarly for objective.
74         It starts at startingTheta and returns ending theta in endingTheta.
75         If reportIncrement 0.0 it will report on any movement
76         If reportIncrement >0.0 it will report at startingTheta+k*reportIncrement.
77         If it can not reach input endingTheta return code will be 1 for infeasible,
78         2 for unbounded, if error on ranges -1,  otherwise 0.
79         Normal report is just theta and objective but
80         if event handler exists it may do more
81         On exit endingTheta is maximum reached (can be used for next startingTheta)
82     */
83     int parametrics(double startingTheta, double & endingTheta, double reportIncrement,
84                     const double * changeLowerBound, const double * changeUpperBound,
85                     const double * changeLowerRhs, const double * changeUpperRhs,
86                     const double * changeObjective);
87     /** Version of parametrics which reads from file
88         See CbcClpParam.cpp for details of format
89         Returns -2 if unable to open file */
90     int parametrics(const char * dataFile);
91     /** Parametrics
92         This is an initial slow version.
93         The code uses current bounds + theta * change (if change array not NULL)
94         It starts at startingTheta and returns ending theta in endingTheta.
95         If it can not reach input endingTheta return code will be 1 for infeasible,
96         2 for unbounded, if error on ranges -1,  otherwise 0.
97         Event handler may do more
98         On exit endingTheta is maximum reached (can be used for next startingTheta)
99     */
100     int parametrics(double startingTheta, double & endingTheta, 
101                     const double * changeLowerBound, const double * changeUpperBound,
102                     const double * changeLowerRhs, const double * changeUpperRhs);
103     int parametricsObj(double startingTheta, double & endingTheta, 
104                        const double * changeObjective);
105    /// Finds best possible pivot
106    double bestPivot(bool justColumns=false);
107  typedef struct {
108    double startingTheta;
109    double endingTheta;
110    double maxTheta;
111    double acceptableMaxTheta; // if this far then within tolerances
112    double * lowerChange; // full array of lower bound changes
113    int * lowerList; // list of lower bound changes
114    double * upperChange; // full array of upper bound changes
115    int * upperList; // list of upper bound changes
116    char * markDone; // mark which ones looked at
117    int * backwardBasic; // from sequence to pivot row
118    int * lowerActive;
119    double * lowerGap;
120    double * lowerCoefficient;
121    int * upperActive;
122    double * upperGap;
123    double * upperCoefficient;
124  } parametricsData;
125
126private:
127     /** Parametrics - inner loop
128         This first attempt is when reportIncrement non zero and may
129         not report endingTheta correctly
130         If it can not reach input endingTheta return code will be 1 for infeasible,
131         2 for unbounded,  otherwise 0.
132         Normal report is just theta and objective but
133         if event handler exists it may do more
134     */
135     int parametricsLoop(parametricsData & paramData, double reportIncrement,
136                         const double * changeLower, const double * changeUpper,
137                         const double * changeObjective, ClpDataSave & data,
138                         bool canTryQuick);
139     int parametricsLoop(parametricsData & paramData,
140                         ClpDataSave & data,bool canSkipFactorization=false);
141     int parametricsObjLoop(parametricsData & paramData,
142                         ClpDataSave & data,bool canSkipFactorization=false);
143     /**  Refactorizes if necessary
144          Checks if finished.  Updates status.
145
146          type - 0 initial so set up save arrays etc
147               - 1 normal -if good update save
148           - 2 restoring from saved
149     */
150     void statusOfProblemInParametrics(int type, ClpDataSave & saveData);
151     void statusOfProblemInParametricsObj(int type, ClpDataSave & saveData);
152     /** This has the flow between re-factorizations
153
154         Reasons to come out:
155         -1 iterations etc
156         -2 inaccuracy
157         -3 slight inaccuracy (and done iterations)
158         +0 looks optimal (might be unbounded - but we will investigate)
159         +1 looks infeasible
160         +3 max iterations
161      */
162     int whileIterating(parametricsData & paramData, double reportIncrement,
163                        const double * changeObjective);
164     /** Computes next theta and says if objective or bounds (0= bounds, 1 objective, -1 none).
165         theta is in theta_.
166         type 1 bounds, 2 objective, 3 both.
167     */
168     int nextTheta(int type, double maxTheta, parametricsData & paramData,
169                   const double * changeObjective);
170     int whileIteratingObj(parametricsData & paramData);
171     int nextThetaObj(double maxTheta, parametricsData & paramData);
172     /// Restores bound to original bound
173     void originalBound(int iSequence, double theta, const double * changeLower,
174                     const double * changeUpper);
175     /**
176         Row array has row part of pivot row
177         Column array has column part.
178         This is used in dual ranging
179     */
180     void checkDualRatios(CoinIndexedVector * rowArray,
181                          CoinIndexedVector * columnArray,
182                          double & costIncrease, int & sequenceIncrease, double & alphaIncrease,
183                          double & costDecrease, int & sequenceDecrease, double & alphaDecrease);
184     /**
185         Row array has pivot column
186         This is used in primal ranging
187     */
188     void checkPrimalRatios(CoinIndexedVector * rowArray,
189                            int direction);
190     /// Returns new value of whichOther when whichIn enters basis
191     double primalRanging1(int whichIn, int whichOther);
192
193public:
194     /** Write the basis in MPS format to the specified file.
195     If writeValues true writes values of structurals
196     (and adds VALUES to end of NAME card)
197
198     Row and column names may be null.
199     formatType is
200     <ul>
201       <li> 0 - normal
202       <li> 1 - extra accuracy
203       <li> 2 - IEEE hex (later)
204     </ul>
205
206     Returns non-zero on I/O error
207     */
208     int writeBasis(const char *filename,
209                    bool writeValues = false,
210                    int formatType = 0) const;
211     /// Read a basis from the given filename
212     int readBasis(const char *filename);
213     /** Creates dual of a problem if looks plausible
214         (defaults will always create model)
215         fractionRowRanges is fraction of rows allowed to have ranges
216         fractionColumnRanges is fraction of columns allowed to have ranges
217     */
218     ClpSimplex * dualOfModel(double fractionRowRanges = 1.0, double fractionColumnRanges = 1.0) const;
219     /** Restores solution from dualized problem
220         non-zero return code indicates minor problems
221     */
222  int restoreFromDual(const ClpSimplex * dualProblem,
223                      bool checkAccuracy=false);
224     /** Does very cursory presolve.
225         rhs is numberRows, whichRows is 3*numberRows and whichColumns is 2*numberColumns.
226     */
227     ClpSimplex * crunch(double * rhs, int * whichRows, int * whichColumns,
228                         int & nBound, bool moreBounds = false, bool tightenBounds = false);
229     /** After very cursory presolve.
230         rhs is numberRows, whichRows is 3*numberRows and whichColumns is 2*numberColumns.
231     */
232     void afterCrunch(const ClpSimplex & small,
233                      const int * whichRows, const int * whichColumns,
234                      int nBound);
235     /** Returns gub version of model or NULL
236         whichRows has to be numberRows
237         whichColumns has to be numberRows+numberColumns */
238     ClpSimplex * gubVersion(int * whichRows, int * whichColumns,
239                             int neededGub,
240                             int factorizationFrequency=50);
241     /// Sets basis from original
242     void setGubBasis(ClpSimplex &original,const int * whichRows,
243                      const int * whichColumns);
244     /// Restores basis to original
245     void getGubBasis(ClpSimplex &original,const int * whichRows,
246                      const int * whichColumns) const;
247     /// Quick try at cleaning up duals if postsolve gets wrong
248     void cleanupAfterPostsolve();
249     /** Tightens integer bounds - returns number tightened or -1 if infeasible
250     */
251     int tightenIntegerBounds(double * rhsSpace);
252     /** Expands out all possible combinations for a knapsack
253         If buildObj NULL then just computes space needed - returns number elements
254         On entry numberOutput is maximum allowed, on exit it is number needed or
255         -1 (as will be number elements) if maximum exceeded.  numberOutput will have at
256         least space to return values which reconstruct input.
257         Rows returned will be original rows but no entries will be returned for
258         any rows all of whose entries are in knapsack.  So up to user to allow for this.
259         If reConstruct >=0 then returns number of entrie which make up item "reConstruct"
260         in expanded knapsack.  Values in buildRow and buildElement;
261     */
262     int expandKnapsack(int knapsackRow, int & numberOutput,
263                        double * buildObj, CoinBigIndex * buildStart,
264                        int * buildRow, double * buildElement, int reConstruct = -1) const;
265     //@}
266};
267#endif
Note: See TracBrowser for help on using the repository browser.