1 | // Copyright (C) 2002, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | |
---|
4 | /* |
---|
5 | Authors |
---|
6 | |
---|
7 | John Forrest |
---|
8 | |
---|
9 | */ |
---|
10 | #ifndef ClpSimplex_H |
---|
11 | #define ClpSimplex_H |
---|
12 | |
---|
13 | #include <iostream> |
---|
14 | #include <cfloat> |
---|
15 | #include "ClpModel.hpp" |
---|
16 | #include "ClpMatrixBase.hpp" |
---|
17 | #include "ClpSolve.hpp" |
---|
18 | class ClpDualRowPivot; |
---|
19 | class ClpPrimalColumnPivot; |
---|
20 | class ClpFactorization; |
---|
21 | class CoinIndexedVector; |
---|
22 | class ClpNonLinearCost; |
---|
23 | class CoinModel; |
---|
24 | class OsiClpSolverInterface; |
---|
25 | class CoinWarmStartBasis; |
---|
26 | class ClpDisasterHandler; |
---|
27 | class ClpConstraint; |
---|
28 | class ClpNodeStuff; |
---|
29 | |
---|
30 | /** This solves LPs using the simplex method |
---|
31 | |
---|
32 | It inherits from ClpModel and all its arrays are created at |
---|
33 | algorithm time. Originally I tried to work with model arrays |
---|
34 | but for simplicity of coding I changed to single arrays with |
---|
35 | structural variables then row variables. Some coding is still |
---|
36 | based on old style and needs cleaning up. |
---|
37 | |
---|
38 | For a description of algorithms: |
---|
39 | |
---|
40 | for dual see ClpSimplexDual.hpp and at top of ClpSimplexDual.cpp |
---|
41 | for primal see ClpSimplexPrimal.hpp and at top of ClpSimplexPrimal.cpp |
---|
42 | |
---|
43 | There is an algorithm data member. + for primal variations |
---|
44 | and - for dual variations |
---|
45 | |
---|
46 | */ |
---|
47 | |
---|
48 | class ClpSimplex : public ClpModel { |
---|
49 | friend void ClpSimplexUnitTest(const std::string & mpsDir); |
---|
50 | |
---|
51 | public: |
---|
52 | /** enums for status of various sorts. |
---|
53 | First 4 match CoinWarmStartBasis, |
---|
54 | isFixed means fixed at lower bound and out of basis |
---|
55 | */ |
---|
56 | enum Status { |
---|
57 | isFree = 0x00, |
---|
58 | basic = 0x01, |
---|
59 | atUpperBound = 0x02, |
---|
60 | atLowerBound = 0x03, |
---|
61 | superBasic = 0x04, |
---|
62 | isFixed = 0x05 |
---|
63 | }; |
---|
64 | // For Dual |
---|
65 | enum FakeBound { |
---|
66 | noFake = 0x00, |
---|
67 | bothFake = 0x01, |
---|
68 | upperFake = 0x02, |
---|
69 | lowerFake = 0x03 |
---|
70 | }; |
---|
71 | |
---|
72 | /**@name Constructors and destructor and copy */ |
---|
73 | //@{ |
---|
74 | /// Default constructor |
---|
75 | ClpSimplex (bool emptyMessages = false ); |
---|
76 | |
---|
77 | /** Copy constructor. May scale depending on mode |
---|
78 | -1 leave mode as is |
---|
79 | 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) |
---|
80 | */ |
---|
81 | ClpSimplex(const ClpSimplex & rhs, int scalingMode =-1); |
---|
82 | /** Copy constructor from model. May scale depending on mode |
---|
83 | -1 leave mode as is |
---|
84 | 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) |
---|
85 | */ |
---|
86 | ClpSimplex(const ClpModel & rhs, int scalingMode=-1); |
---|
87 | /** Subproblem constructor. A subset of whole model is created from the |
---|
88 | row and column lists given. The new order is given by list order and |
---|
89 | duplicates are allowed. Name and integer information can be dropped |
---|
90 | Can optionally modify rhs to take into account variables NOT in list |
---|
91 | in this case duplicates are not allowed (also see getbackSolution) |
---|
92 | */ |
---|
93 | ClpSimplex (const ClpModel * wholeModel, |
---|
94 | int numberRows, const int * whichRows, |
---|
95 | int numberColumns, const int * whichColumns, |
---|
96 | bool dropNames=true, bool dropIntegers=true, |
---|
97 | bool fixOthers=false); |
---|
98 | /** Subproblem constructor. A subset of whole model is created from the |
---|
99 | row and column lists given. The new order is given by list order and |
---|
100 | duplicates are allowed. Name and integer information can be dropped |
---|
101 | Can optionally modify rhs to take into account variables NOT in list |
---|
102 | in this case duplicates are not allowed (also see getbackSolution) |
---|
103 | */ |
---|
104 | ClpSimplex (const ClpSimplex * wholeModel, |
---|
105 | int numberRows, const int * whichRows, |
---|
106 | int numberColumns, const int * whichColumns, |
---|
107 | bool dropNames=true, bool dropIntegers=true, |
---|
108 | bool fixOthers=false); |
---|
109 | /** This constructor modifies original ClpSimplex and stores |
---|
110 | original stuff in created ClpSimplex. It is only to be used in |
---|
111 | conjunction with originalModel */ |
---|
112 | ClpSimplex (ClpSimplex * wholeModel, |
---|
113 | int numberColumns, const int * whichColumns); |
---|
114 | /** This copies back stuff from miniModel and then deletes miniModel. |
---|
115 | Only to be used with mini constructor */ |
---|
116 | void originalModel(ClpSimplex * miniModel); |
---|
117 | /** Array persistence flag |
---|
118 | If 0 then as now (delete/new) |
---|
119 | 1 then only do arrays if bigger needed |
---|
120 | 2 as 1 but give a bit extra if bigger needed |
---|
121 | */ |
---|
122 | void setPersistenceFlag(int value); |
---|
123 | /** |
---|
124 | If you are re-using the same matrix again and again then the setup time |
---|
125 | to do scaling may be significant. Also you may not want to initialize all values |
---|
126 | or return all values (especially if infeasible). While an auxiliary model exists |
---|
127 | it will be faster. If options -1 then model is switched off. Otherwise switched on |
---|
128 | with following options. |
---|
129 | 1 - rhs is constant |
---|
130 | 2 - bounds are constant |
---|
131 | 4 - objective is constant |
---|
132 | 8 - solution in by basis and no djs etc in |
---|
133 | 16 - no duals out (but reduced costs) |
---|
134 | 32 - no output if infeasible |
---|
135 | */ |
---|
136 | void auxiliaryModel(int options); |
---|
137 | /// Switch off e.g. if people using presolve |
---|
138 | void deleteAuxiliaryModel(); |
---|
139 | /// See if we have auxiliary model |
---|
140 | inline bool usingAuxiliaryModel() const |
---|
141 | { return auxiliaryModel_!=NULL;} |
---|
142 | /// Save a copy of model with certain state - normally without cuts |
---|
143 | void makeBaseModel(); |
---|
144 | /// Switch off base model |
---|
145 | void deleteBaseModel(); |
---|
146 | /// See if we have base model |
---|
147 | inline ClpSimplex * baseModel() const |
---|
148 | { return baseModel_;} |
---|
149 | /** Reset to base model (just size and arrays needed) |
---|
150 | If model NULL use internal copy |
---|
151 | */ |
---|
152 | void setToBaseModel(ClpSimplex * model=NULL); |
---|
153 | /// Assignment operator. This copies the data |
---|
154 | ClpSimplex & operator=(const ClpSimplex & rhs); |
---|
155 | /// Destructor |
---|
156 | ~ClpSimplex ( ); |
---|
157 | // Ones below are just ClpModel with some changes |
---|
158 | /** Loads a problem (the constraints on the |
---|
159 | rows are given by lower and upper bounds). If a pointer is 0 then the |
---|
160 | following values are the default: |
---|
161 | <ul> |
---|
162 | <li> <code>colub</code>: all columns have upper bound infinity |
---|
163 | <li> <code>collb</code>: all columns have lower bound 0 |
---|
164 | <li> <code>rowub</code>: all rows have upper bound infinity |
---|
165 | <li> <code>rowlb</code>: all rows have lower bound -infinity |
---|
166 | <li> <code>obj</code>: all variables have 0 objective coefficient |
---|
167 | </ul> |
---|
168 | */ |
---|
169 | void loadProblem ( const ClpMatrixBase& matrix, |
---|
170 | const double* collb, const double* colub, |
---|
171 | const double* obj, |
---|
172 | const double* rowlb, const double* rowub, |
---|
173 | const double * rowObjective=NULL); |
---|
174 | void loadProblem ( const CoinPackedMatrix& matrix, |
---|
175 | const double* collb, const double* colub, |
---|
176 | const double* obj, |
---|
177 | const double* rowlb, const double* rowub, |
---|
178 | const double * rowObjective=NULL); |
---|
179 | |
---|
180 | /** Just like the other loadProblem() method except that the matrix is |
---|
181 | given in a standard column major ordered format (without gaps). */ |
---|
182 | void loadProblem ( const int numcols, const int numrows, |
---|
183 | const CoinBigIndex* start, const int* index, |
---|
184 | const double* value, |
---|
185 | const double* collb, const double* colub, |
---|
186 | const double* obj, |
---|
187 | const double* rowlb, const double* rowub, |
---|
188 | const double * rowObjective=NULL); |
---|
189 | /// This one is for after presolve to save memory |
---|
190 | void loadProblem ( const int numcols, const int numrows, |
---|
191 | const CoinBigIndex* start, const int* index, |
---|
192 | const double* value,const int * length, |
---|
193 | const double* collb, const double* colub, |
---|
194 | const double* obj, |
---|
195 | const double* rowlb, const double* rowub, |
---|
196 | const double * rowObjective=NULL); |
---|
197 | /** This loads a model from a coinModel object - returns number of errors. |
---|
198 | If keepSolution true and size is same as current then |
---|
199 | keeps current status and solution |
---|
200 | */ |
---|
201 | int loadProblem ( CoinModel & modelObject,bool keepSolution=false); |
---|
202 | /// Read an mps file from the given filename |
---|
203 | int readMps(const char *filename, |
---|
204 | bool keepNames=false, |
---|
205 | bool ignoreErrors = false); |
---|
206 | /// Read GMPL files from the given filenames |
---|
207 | int readGMPL(const char *filename,const char * dataName, |
---|
208 | bool keepNames=false); |
---|
209 | /// Read file in LP format from file with name filename. |
---|
210 | /// See class CoinLpIO for description of this format. |
---|
211 | int readLp(const char *filename, const double epsilon = 1e-5); |
---|
212 | /** Borrow model. This is so we dont have to copy large amounts |
---|
213 | of data around. It assumes a derived class wants to overwrite |
---|
214 | an empty model with a real one - while it does an algorithm. |
---|
215 | This is same as ClpModel one, but sets scaling on etc. */ |
---|
216 | void borrowModel(ClpModel & otherModel); |
---|
217 | void borrowModel(ClpSimplex & otherModel); |
---|
218 | /// Pass in Event handler (cloned and deleted at end) |
---|
219 | void passInEventHandler(const ClpEventHandler * eventHandler); |
---|
220 | /// Puts solution back into small model |
---|
221 | void getbackSolution(const ClpSimplex & smallModel,const int * whichRow, const int * whichColumn); |
---|
222 | /** Load nonlinear part of problem from AMPL info |
---|
223 | Returns 0 if linear |
---|
224 | 1 if quadratic objective |
---|
225 | 2 if quadratic constraints |
---|
226 | 3 if nonlinear objective |
---|
227 | 4 if nonlinear constraints |
---|
228 | -1 on failure |
---|
229 | */ |
---|
230 | int loadNonLinear(void * info, int & numberConstraints, |
---|
231 | ClpConstraint ** & constraints); |
---|
232 | //@} |
---|
233 | |
---|
234 | /**@name Functions most useful to user */ |
---|
235 | //@{ |
---|
236 | /** General solve algorithm which can do presolve. |
---|
237 | See ClpSolve.hpp for options |
---|
238 | */ |
---|
239 | int initialSolve(ClpSolve & options); |
---|
240 | /// Default initial solve |
---|
241 | int initialSolve(); |
---|
242 | /// Dual initial solve |
---|
243 | int initialDualSolve(); |
---|
244 | /// Primal initial solve |
---|
245 | int initialPrimalSolve(); |
---|
246 | /// Barrier initial solve |
---|
247 | int initialBarrierSolve(); |
---|
248 | /// Barrier initial solve, not to be followed by crossover |
---|
249 | int initialBarrierNoCrossSolve(); |
---|
250 | /** Dual algorithm - see ClpSimplexDual.hpp for method. |
---|
251 | ifValuesPass==2 just does values pass and then stops. |
---|
252 | |
---|
253 | startFinishOptions - bits |
---|
254 | 1 - do not delete work areas and factorization at end |
---|
255 | 2 - use old factorization if same number of rows |
---|
256 | 4 - skip as much initialization of work areas as possible |
---|
257 | (based on whatsChanged in clpmodel.hpp) ** work in progress |
---|
258 | maybe other bits later |
---|
259 | */ |
---|
260 | int dual(int ifValuesPass=0, int startFinishOptions=0); |
---|
261 | // If using Debug |
---|
262 | int dualDebug(int ifValuesPass=0, int startFinishOptions=0); |
---|
263 | /** Primal algorithm - see ClpSimplexPrimal.hpp for method. |
---|
264 | ifValuesPass==2 just does values pass and then stops. |
---|
265 | |
---|
266 | startFinishOptions - bits |
---|
267 | 1 - do not delete work areas and factorization at end |
---|
268 | 2 - use old factorization if same number of rows |
---|
269 | 4 - skip as much initialization of work areas as possible |
---|
270 | (based on whatsChanged in clpmodel.hpp) ** work in progress |
---|
271 | maybe other bits later |
---|
272 | */ |
---|
273 | int primal(int ifValuesPass=0, int startFinishOptions=0); |
---|
274 | /** Solves nonlinear problem using SLP - may be used as crash |
---|
275 | for other algorithms when number of iterations small. |
---|
276 | Also exits if all problematical variables are changing |
---|
277 | less than deltaTolerance |
---|
278 | */ |
---|
279 | int nonlinearSLP(int numberPasses,double deltaTolerance); |
---|
280 | /** Solves problem with nonlinear constraints using SLP - may be used as crash |
---|
281 | for other algorithms when number of iterations small. |
---|
282 | Also exits if all problematical variables are changing |
---|
283 | less than deltaTolerance |
---|
284 | */ |
---|
285 | int nonlinearSLP(int numberConstraints, ClpConstraint ** constraints, |
---|
286 | int numberPasses,double deltaTolerance); |
---|
287 | /** Solves using barrier (assumes you have good cholesky factor code). |
---|
288 | Does crossover to simplex if asked*/ |
---|
289 | int barrier(bool crossover=true); |
---|
290 | /** Solves non-linear using reduced gradient. Phase = 0 get feasible, |
---|
291 | =1 use solution */ |
---|
292 | int reducedGradient(int phase=0); |
---|
293 | /** |
---|
294 | When scaling is on it is possible that the scaled problem |
---|
295 | is feasible but the unscaled is not. Clp returns a secondary |
---|
296 | status code to that effect. This option allows for a cleanup. |
---|
297 | If you use it I would suggest 1. |
---|
298 | This only affects actions when scaled optimal |
---|
299 | 0 - no action |
---|
300 | 1 - clean up using dual if primal infeasibility |
---|
301 | 2 - clean up using dual if dual infeasibility |
---|
302 | 3 - clean up using dual if primal or dual infeasibility |
---|
303 | 11,12,13 - as 1,2,3 but use primal |
---|
304 | |
---|
305 | return code as dual/primal |
---|
306 | */ |
---|
307 | int cleanup(int cleanupScaling); |
---|
308 | /** Dual ranging. |
---|
309 | This computes increase/decrease in cost for each given variable and corresponding |
---|
310 | sequence numbers which would change basis. Sequence numbers are 0..numberColumns |
---|
311 | and numberColumns.. for artificials/slacks. |
---|
312 | For non-basic variables the information is trivial to compute and the change in cost is just minus the |
---|
313 | reduced cost and the sequence number will be that of the non-basic variables. |
---|
314 | For basic variables a ratio test is between the reduced costs for non-basic variables |
---|
315 | and the row of the tableau corresponding to the basic variable. |
---|
316 | The increase/decrease value is always >= 0.0 |
---|
317 | |
---|
318 | Up to user to provide correct length arrays where each array is of length numberCheck. |
---|
319 | which contains list of variables for which information is desired. All other |
---|
320 | arrays will be filled in by function. If fifth entry in which is variable 7 then fifth entry in output arrays |
---|
321 | will be information for variable 7. |
---|
322 | |
---|
323 | If valueIncrease/Decrease not NULL (both must be NULL or both non NULL) then these are filled with |
---|
324 | the value of variable if such a change in cost were made (the existing bounds are ignored) |
---|
325 | |
---|
326 | Returns non-zero if infeasible unbounded etc |
---|
327 | */ |
---|
328 | int dualRanging(int numberCheck,const int * which, |
---|
329 | double * costIncrease, int * sequenceIncrease, |
---|
330 | double * costDecrease, int * sequenceDecrease, |
---|
331 | double * valueIncrease=NULL, double * valueDecrease=NULL); |
---|
332 | /** Primal ranging. |
---|
333 | This computes increase/decrease in value for each given variable and corresponding |
---|
334 | sequence numbers which would change basis. Sequence numbers are 0..numberColumns |
---|
335 | and numberColumns.. for artificials/slacks. |
---|
336 | This should only be used for non-basic variabls as otherwise information is pretty useless |
---|
337 | For basic variables the sequence number will be that of the basic variables. |
---|
338 | |
---|
339 | Up to user to provide correct length arrays where each array is of length numberCheck. |
---|
340 | which contains list of variables for which information is desired. All other |
---|
341 | arrays will be filled in by function. If fifth entry in which is variable 7 then fifth entry in output arrays |
---|
342 | will be information for variable 7. |
---|
343 | |
---|
344 | Returns non-zero if infeasible unbounded etc |
---|
345 | */ |
---|
346 | int primalRanging(int numberCheck,const int * which, |
---|
347 | double * valueIncrease, int * sequenceIncrease, |
---|
348 | double * valueDecrease, int * sequenceDecrease); |
---|
349 | /** Write the basis in MPS format to the specified file. |
---|
350 | If writeValues true writes values of structurals |
---|
351 | (and adds VALUES to end of NAME card) |
---|
352 | |
---|
353 | Row and column names may be null. |
---|
354 | formatType is |
---|
355 | <ul> |
---|
356 | <li> 0 - normal |
---|
357 | <li> 1 - extra accuracy |
---|
358 | <li> 2 - IEEE hex (later) |
---|
359 | </ul> |
---|
360 | |
---|
361 | Returns non-zero on I/O error |
---|
362 | */ |
---|
363 | int writeBasis(const char *filename, |
---|
364 | bool writeValues=false, |
---|
365 | int formatType=0) const; |
---|
366 | /** Read a basis from the given filename, |
---|
367 | returns -1 on file error, 0 if no values, 1 if values */ |
---|
368 | int readBasis(const char *filename); |
---|
369 | /// Returns a basis (to be deleted by user) |
---|
370 | CoinWarmStartBasis * getBasis() const; |
---|
371 | /// Passes in factorization |
---|
372 | void setFactorization( ClpFactorization & factorization); |
---|
373 | /** Tightens primal bounds to make dual faster. Unless |
---|
374 | fixed or doTight>10, bounds are slightly looser than they could be. |
---|
375 | This is to make dual go faster and is probably not needed |
---|
376 | with a presolve. Returns non-zero if problem infeasible. |
---|
377 | |
---|
378 | Fudge for branch and bound - put bounds on columns of factor * |
---|
379 | largest value (at continuous) - should improve stability |
---|
380 | in branch and bound on infeasible branches (0.0 is off) |
---|
381 | */ |
---|
382 | int tightenPrimalBounds(double factor=0.0,int doTight=0,bool tightIntegers=false); |
---|
383 | /** Crash - at present just aimed at dual, returns |
---|
384 | -2 if dual preferred and crash basis created |
---|
385 | -1 if dual preferred and all slack basis preferred |
---|
386 | 0 if basis going in was not all slack |
---|
387 | 1 if primal preferred and all slack basis preferred |
---|
388 | 2 if primal preferred and crash basis created. |
---|
389 | |
---|
390 | if gap between bounds <="gap" variables can be flipped |
---|
391 | ( If pivot -1 then can be made super basic!) |
---|
392 | |
---|
393 | If "pivot" is |
---|
394 | -1 No pivoting - always primal |
---|
395 | 0 No pivoting (so will just be choice of algorithm) |
---|
396 | 1 Simple pivoting e.g. gub |
---|
397 | 2 Mini iterations |
---|
398 | */ |
---|
399 | int crash(double gap,int pivot); |
---|
400 | /// Sets row pivot choice algorithm in dual |
---|
401 | void setDualRowPivotAlgorithm(ClpDualRowPivot & choice); |
---|
402 | /// Sets column pivot choice algorithm in primal |
---|
403 | void setPrimalColumnPivotAlgorithm(ClpPrimalColumnPivot & choice); |
---|
404 | /** For strong branching. On input lower and upper are new bounds |
---|
405 | while on output they are change in objective function values |
---|
406 | (>1.0e50 infeasible). |
---|
407 | Return code is 0 if nothing interesting, -1 if infeasible both |
---|
408 | ways and +1 if infeasible one way (check values to see which one(s)) |
---|
409 | Solutions are filled in as well - even down, odd up - also |
---|
410 | status and number of iterations |
---|
411 | */ |
---|
412 | int strongBranching(int numberVariables,const int * variables, |
---|
413 | double * newLower, double * newUpper, |
---|
414 | double ** outputSolution, |
---|
415 | int * outputStatus, int * outputIterations, |
---|
416 | bool stopOnFirstInfeasible=true, |
---|
417 | bool alwaysFinish=false, |
---|
418 | int startFinishOptions=0); |
---|
419 | /// Starts Fast dual2 |
---|
420 | int startFastDual2(ClpNodeStuff * stuff); |
---|
421 | /// Like Fast dual |
---|
422 | int fastDual2(ClpNodeStuff * stuff); |
---|
423 | /// Stops Fast dual2 |
---|
424 | void stopFastDual2(ClpNodeStuff * stuff); |
---|
425 | //@} |
---|
426 | |
---|
427 | /**@name Needed for functionality of OsiSimplexInterface */ |
---|
428 | //@{ |
---|
429 | /** Pivot in a variable and out a variable. Returns 0 if okay, |
---|
430 | 1 if inaccuracy forced re-factorization, -1 if would be singular. |
---|
431 | Also updates primal/dual infeasibilities. |
---|
432 | Assumes sequenceIn_ and pivotRow_ set and also directionIn and Out. |
---|
433 | */ |
---|
434 | int pivot(); |
---|
435 | |
---|
436 | /** Pivot in a variable and choose an outgoing one. Assumes primal |
---|
437 | feasible - will not go through a bound. Returns step length in theta |
---|
438 | Returns ray in ray_ (or NULL if no pivot) |
---|
439 | Return codes as before but -1 means no acceptable pivot |
---|
440 | */ |
---|
441 | int primalPivotResult(); |
---|
442 | |
---|
443 | /** Pivot out a variable and choose an incoing one. Assumes dual |
---|
444 | feasible - will not go through a reduced cost. |
---|
445 | Returns step length in theta |
---|
446 | Returns ray in ray_ (or NULL if no pivot) |
---|
447 | Return codes as before but -1 means no acceptable pivot |
---|
448 | */ |
---|
449 | int dualPivotResult(); |
---|
450 | |
---|
451 | /** Common bits of coding for dual and primal. Return 0 if okay, |
---|
452 | 1 if bad matrix, 2 if very bad factorization |
---|
453 | |
---|
454 | startFinishOptions - bits |
---|
455 | 1 - do not delete work areas and factorization at end |
---|
456 | 2 - use old factorization if same number of rows |
---|
457 | 4 - skip as much initialization of work areas as possible |
---|
458 | (based on whatsChanged in clpmodel.hpp) ** work in progress |
---|
459 | maybe other bits later |
---|
460 | |
---|
461 | */ |
---|
462 | int startup(int ifValuesPass,int startFinishOptions=0); |
---|
463 | void finish(int startFinishOptions=0); |
---|
464 | |
---|
465 | /** Factorizes and returns true if optimal. Used by user */ |
---|
466 | bool statusOfProblem(bool initial=false); |
---|
467 | /// If user left factorization frequency then compute |
---|
468 | void defaultFactorizationFrequency(); |
---|
469 | //@} |
---|
470 | |
---|
471 | /**@name most useful gets and sets */ |
---|
472 | //@{ |
---|
473 | /// If problem is primal feasible |
---|
474 | inline bool primalFeasible() const |
---|
475 | { return (numberPrimalInfeasibilities_==0);} |
---|
476 | /// If problem is dual feasible |
---|
477 | inline bool dualFeasible() const |
---|
478 | { return (numberDualInfeasibilities_==0);} |
---|
479 | /// factorization |
---|
480 | inline ClpFactorization * factorization() const |
---|
481 | { return factorization_;} |
---|
482 | /// Sparsity on or off |
---|
483 | bool sparseFactorization() const; |
---|
484 | void setSparseFactorization(bool value); |
---|
485 | /// Factorization frequency |
---|
486 | int factorizationFrequency() const; |
---|
487 | void setFactorizationFrequency(int value); |
---|
488 | /// Dual bound |
---|
489 | inline double dualBound() const |
---|
490 | { return dualBound_;} |
---|
491 | void setDualBound(double value); |
---|
492 | /// Infeasibility cost |
---|
493 | inline double infeasibilityCost() const |
---|
494 | { return infeasibilityCost_;} |
---|
495 | void setInfeasibilityCost(double value); |
---|
496 | /** Amount of print out: |
---|
497 | 0 - none |
---|
498 | 1 - just final |
---|
499 | 2 - just factorizations |
---|
500 | 3 - as 2 plus a bit more |
---|
501 | 4 - verbose |
---|
502 | above that 8,16,32 etc just for selective debug |
---|
503 | */ |
---|
504 | /** Perturbation: |
---|
505 | 50 - switch on perturbation |
---|
506 | 100 - auto perturb if takes too long (1.0e-6 largest nonzero) |
---|
507 | 101 - we are perturbed |
---|
508 | 102 - don't try perturbing again |
---|
509 | default is 100 |
---|
510 | others are for playing |
---|
511 | */ |
---|
512 | inline int perturbation() const |
---|
513 | { return perturbation_;} |
---|
514 | void setPerturbation(int value); |
---|
515 | /// Current (or last) algorithm |
---|
516 | inline int algorithm() const |
---|
517 | {return algorithm_; } |
---|
518 | /// Set algorithm |
---|
519 | inline void setAlgorithm(int value) |
---|
520 | {algorithm_=value; } |
---|
521 | /// Sum of dual infeasibilities |
---|
522 | inline double sumDualInfeasibilities() const |
---|
523 | { return sumDualInfeasibilities_;} |
---|
524 | inline void setSumDualInfeasibilities(double value) |
---|
525 | { sumDualInfeasibilities_=value;} |
---|
526 | /// Sum of relaxed dual infeasibilities |
---|
527 | inline double sumOfRelaxedDualInfeasibilities() const |
---|
528 | { return sumOfRelaxedDualInfeasibilities_;} |
---|
529 | inline void setSumOfRelaxedDualInfeasibilities(double value) |
---|
530 | { sumOfRelaxedDualInfeasibilities_=value;} |
---|
531 | /// Number of dual infeasibilities |
---|
532 | inline int numberDualInfeasibilities() const |
---|
533 | { return numberDualInfeasibilities_;} |
---|
534 | inline void setNumberDualInfeasibilities(int value) |
---|
535 | { numberDualInfeasibilities_=value;} |
---|
536 | /// Number of dual infeasibilities (without free) |
---|
537 | inline int numberDualInfeasibilitiesWithoutFree() const |
---|
538 | { return numberDualInfeasibilitiesWithoutFree_;} |
---|
539 | /// Sum of primal infeasibilities |
---|
540 | inline double sumPrimalInfeasibilities() const |
---|
541 | { return sumPrimalInfeasibilities_;} |
---|
542 | inline void setSumPrimalInfeasibilities(double value) |
---|
543 | { sumPrimalInfeasibilities_=value;} |
---|
544 | /// Sum of relaxed primal infeasibilities |
---|
545 | inline double sumOfRelaxedPrimalInfeasibilities() const |
---|
546 | { return sumOfRelaxedPrimalInfeasibilities_;} |
---|
547 | inline void setSumOfRelaxedPrimalInfeasibilities(double value) |
---|
548 | { sumOfRelaxedPrimalInfeasibilities_=value;} |
---|
549 | /// Number of primal infeasibilities |
---|
550 | inline int numberPrimalInfeasibilities() const |
---|
551 | { return numberPrimalInfeasibilities_;} |
---|
552 | inline void setNumberPrimalInfeasibilities(int value) |
---|
553 | { numberPrimalInfeasibilities_=value;} |
---|
554 | /** Save model to file, returns 0 if success. This is designed for |
---|
555 | use outside algorithms so does not save iterating arrays etc. |
---|
556 | It does not save any messaging information. |
---|
557 | Does not save scaling values. |
---|
558 | It does not know about all types of virtual functions. |
---|
559 | */ |
---|
560 | int saveModel(const char * fileName); |
---|
561 | /** Restore model from file, returns 0 if success, |
---|
562 | deletes current model */ |
---|
563 | int restoreModel(const char * fileName); |
---|
564 | |
---|
565 | /** Just check solution (for external use) - sets sum of |
---|
566 | infeasibilities etc. |
---|
567 | If setToBounds 0 then primal column values not changed |
---|
568 | and used to compute primal row activity values. If 1 or 2 |
---|
569 | then status used - so all nonbasic variables set to |
---|
570 | indicated bound and if any values changed (or ==2) basic values re-computed. |
---|
571 | */ |
---|
572 | void checkSolution(int setToBounds=false); |
---|
573 | /** Just check solution (for internal use) - sets sum of |
---|
574 | infeasibilities etc. */ |
---|
575 | void checkSolutionInternal(); |
---|
576 | /// Useful row length arrays (0,1,2,3,4,5) |
---|
577 | inline CoinIndexedVector * rowArray(int index) const |
---|
578 | { return rowArray_[index];} |
---|
579 | /// Useful column length arrays (0,1,2,3,4,5) |
---|
580 | inline CoinIndexedVector * columnArray(int index) const |
---|
581 | { return columnArray_[index];} |
---|
582 | //@} |
---|
583 | |
---|
584 | /******************** End of most useful part **************/ |
---|
585 | /**@name Functions less likely to be useful to casual user */ |
---|
586 | //@{ |
---|
587 | /** Given an existing factorization computes and checks |
---|
588 | primal and dual solutions. Uses input arrays for variables at |
---|
589 | bounds. Returns feasibility states */ |
---|
590 | int getSolution ( const double * rowActivities, |
---|
591 | const double * columnActivities); |
---|
592 | /** Given an existing factorization computes and checks |
---|
593 | primal and dual solutions. Uses current problem arrays for |
---|
594 | bounds. Returns feasibility states */ |
---|
595 | int getSolution (); |
---|
596 | /** Constructs a non linear cost from list of non-linearities (columns only) |
---|
597 | First lower of each column is taken as real lower |
---|
598 | Last lower is taken as real upper and cost ignored |
---|
599 | |
---|
600 | Returns nonzero if bad data e.g. lowers not monotonic |
---|
601 | */ |
---|
602 | int createPiecewiseLinearCosts(const int * starts, |
---|
603 | const double * lower, const double * gradient); |
---|
604 | /// dual row pivot choice |
---|
605 | ClpDualRowPivot * dualRowPivot() const |
---|
606 | { return dualRowPivot_;} |
---|
607 | /** Return model - updates any scalars */ |
---|
608 | void returnModel(ClpSimplex & otherModel); |
---|
609 | /** Factorizes using current basis. |
---|
610 | solveType - 1 iterating, 0 initial, -1 external |
---|
611 | If 10 added then in primal values pass |
---|
612 | Return codes are as from ClpFactorization unless initial factorization |
---|
613 | when total number of singularities is returned. |
---|
614 | Special case is numberRows_+1 -> all slack basis. |
---|
615 | */ |
---|
616 | int internalFactorize(int solveType); |
---|
617 | /// Save data |
---|
618 | ClpDataSave saveData() ; |
---|
619 | /// Restore data |
---|
620 | void restoreData(ClpDataSave saved); |
---|
621 | /// Clean up status |
---|
622 | void cleanStatus(); |
---|
623 | /// Factorizes using current basis. For external use |
---|
624 | int factorize(); |
---|
625 | /** Computes duals from scratch. If givenDjs then |
---|
626 | allows for nonzero basic djs */ |
---|
627 | void computeDuals(double * givenDjs); |
---|
628 | /// Computes primals from scratch |
---|
629 | void computePrimals ( const double * rowActivities, |
---|
630 | const double * columnActivities); |
---|
631 | /** Adds multiple of a column into an array */ |
---|
632 | void add(double * array, |
---|
633 | int column, double multiplier) const; |
---|
634 | /** |
---|
635 | Unpacks one column of the matrix into indexed array |
---|
636 | Uses sequenceIn_ |
---|
637 | Also applies scaling if needed |
---|
638 | */ |
---|
639 | void unpack(CoinIndexedVector * rowArray) const ; |
---|
640 | /** |
---|
641 | Unpacks one column of the matrix into indexed array |
---|
642 | Slack if sequence>= numberColumns |
---|
643 | Also applies scaling if needed |
---|
644 | */ |
---|
645 | void unpack(CoinIndexedVector * rowArray,int sequence) const; |
---|
646 | /** |
---|
647 | Unpacks one column of the matrix into indexed array |
---|
648 | ** as packed vector |
---|
649 | Uses sequenceIn_ |
---|
650 | Also applies scaling if needed |
---|
651 | */ |
---|
652 | void unpackPacked(CoinIndexedVector * rowArray) ; |
---|
653 | /** |
---|
654 | Unpacks one column of the matrix into indexed array |
---|
655 | ** as packed vector |
---|
656 | Slack if sequence>= numberColumns |
---|
657 | Also applies scaling if needed |
---|
658 | */ |
---|
659 | void unpackPacked(CoinIndexedVector * rowArray,int sequence); |
---|
660 | protected: |
---|
661 | /** |
---|
662 | This does basis housekeeping and does values for in/out variables. |
---|
663 | Can also decide to re-factorize |
---|
664 | */ |
---|
665 | int housekeeping(double objectiveChange); |
---|
666 | /** This sets largest infeasibility and most infeasible and sum |
---|
667 | and number of infeasibilities (Primal) */ |
---|
668 | void checkPrimalSolution(const double * rowActivities=NULL, |
---|
669 | const double * columnActivies=NULL); |
---|
670 | /** This sets largest infeasibility and most infeasible and sum |
---|
671 | and number of infeasibilities (Dual) */ |
---|
672 | void checkDualSolution(); |
---|
673 | /** This sets sum and number of infeasibilities (Dual and Primal) */ |
---|
674 | void checkBothSolutions(); |
---|
675 | public: |
---|
676 | /** For advanced use. When doing iterative solves things can get |
---|
677 | nasty so on values pass if incoming solution has largest |
---|
678 | infeasibility < incomingInfeasibility throw out variables |
---|
679 | from basis until largest infeasibility < allowedInfeasibility |
---|
680 | or incoming largest infeasibility. |
---|
681 | If allowedInfeasibility>= incomingInfeasibility this is |
---|
682 | always possible altough you may end up with an all slack basis. |
---|
683 | |
---|
684 | Defaults are 1.0,10.0 |
---|
685 | */ |
---|
686 | void setValuesPassAction(double incomingInfeasibility, |
---|
687 | double allowedInfeasibility); |
---|
688 | //@} |
---|
689 | /**@name most useful gets and sets */ |
---|
690 | //@{ |
---|
691 | public: |
---|
692 | /// Initial value for alpha accuracy calculation (-1.0 off) |
---|
693 | inline double alphaAccuracy() const |
---|
694 | { return alphaAccuracy_;} |
---|
695 | inline void setAlphaAccuracy(double value) |
---|
696 | { alphaAccuracy_ = value;} |
---|
697 | public: |
---|
698 | /// Disaster handler |
---|
699 | inline void setDisasterHandler(ClpDisasterHandler * handler) |
---|
700 | { disasterArea_= handler;} |
---|
701 | /// Large bound value (for complementarity etc) |
---|
702 | inline double largeValue() const |
---|
703 | { return largeValue_;} |
---|
704 | void setLargeValue( double value) ; |
---|
705 | /// Largest error on Ax-b |
---|
706 | inline double largestPrimalError() const |
---|
707 | { return largestPrimalError_;} |
---|
708 | /// Largest error on basic duals |
---|
709 | inline double largestDualError() const |
---|
710 | { return largestDualError_;} |
---|
711 | /// Largest error on Ax-b |
---|
712 | inline void setLargestPrimalError(double value) |
---|
713 | { largestPrimalError_=value;} |
---|
714 | /// Largest error on basic duals |
---|
715 | inline void setLargestDualError(double value) |
---|
716 | { largestDualError_=value;} |
---|
717 | /// Basic variables pivoting on which rows |
---|
718 | inline int * pivotVariable() const |
---|
719 | { return pivotVariable_;} |
---|
720 | /// If automatic scaling on |
---|
721 | inline bool automaticScaling() const |
---|
722 | { return automaticScale_!=0;} |
---|
723 | inline void setAutomaticScaling(bool onOff) |
---|
724 | { automaticScale_ = onOff ? 1: 0;} |
---|
725 | /// Current dual tolerance |
---|
726 | inline double currentDualTolerance() const |
---|
727 | { return dualTolerance_;} |
---|
728 | inline void setCurrentDualTolerance(double value) |
---|
729 | { dualTolerance_ = value;} |
---|
730 | /// Current primal tolerance |
---|
731 | inline double currentPrimalTolerance() const |
---|
732 | { return primalTolerance_;} |
---|
733 | inline void setCurrentPrimalTolerance(double value) |
---|
734 | { primalTolerance_ = value;} |
---|
735 | /// How many iterative refinements to do |
---|
736 | inline int numberRefinements() const |
---|
737 | { return numberRefinements_;} |
---|
738 | void setNumberRefinements( int value) ; |
---|
739 | /// Alpha (pivot element) for use by classes e.g. steepestedge |
---|
740 | inline double alpha() const { return alpha_;} |
---|
741 | inline void setAlpha(double value) { alpha_ = value;} |
---|
742 | /// Reduced cost of last incoming for use by classes e.g. steepestedge |
---|
743 | inline double dualIn() const { return dualIn_;} |
---|
744 | /// Pivot Row for use by classes e.g. steepestedge |
---|
745 | inline int pivotRow() const{ return pivotRow_;} |
---|
746 | inline void setPivotRow(int value) { pivotRow_=value;} |
---|
747 | /// value of incoming variable (in Dual) |
---|
748 | double valueIncomingDual() const; |
---|
749 | //@} |
---|
750 | |
---|
751 | protected: |
---|
752 | /**@name protected methods */ |
---|
753 | //@{ |
---|
754 | /** May change basis and then returns number changed. |
---|
755 | Computation of solutions may be overriden by given pi and solution |
---|
756 | */ |
---|
757 | int gutsOfSolution ( double * givenDuals, |
---|
758 | const double * givenPrimals, |
---|
759 | bool valuesPass=false); |
---|
760 | /// Does most of deletion (0 = all, 1 = most, 2 most + factorization) |
---|
761 | void gutsOfDelete(int type); |
---|
762 | /// Does most of copying |
---|
763 | void gutsOfCopy(const ClpSimplex & rhs); |
---|
764 | /** puts in format I like (rowLower,rowUpper) also see StandardMatrix |
---|
765 | 1 bit does rows (now and columns), (2 bit does column bounds), 4 bit does objective(s). |
---|
766 | 8 bit does solution scaling in |
---|
767 | 16 bit does rowArray and columnArray indexed vectors |
---|
768 | and makes row copy if wanted, also sets columnStart_ etc |
---|
769 | Also creates scaling arrays if needed. It does scaling if needed. |
---|
770 | 16 also moves solutions etc in to work arrays |
---|
771 | On 16 returns false if problem "bad" i.e. matrix or bounds bad |
---|
772 | If startFinishOptions is -1 then called by user in getSolution |
---|
773 | so do arrays but keep pivotVariable_ |
---|
774 | */ |
---|
775 | bool createRim(int what,bool makeRowCopy=false,int startFinishOptions=0); |
---|
776 | /// Does rows and columns |
---|
777 | void createRim1(bool initial); |
---|
778 | /// Does objective |
---|
779 | void createRim4(bool initial); |
---|
780 | /// Does rows and columns and objective |
---|
781 | void createRim5(bool initial); |
---|
782 | /** releases above arrays and does solution scaling out. May also |
---|
783 | get rid of factorization data - |
---|
784 | 0 get rid of nothing, 1 get rid of arrays, 2 also factorization |
---|
785 | */ |
---|
786 | void deleteRim(int getRidOfFactorizationData=2); |
---|
787 | /// Sanity check on input rim data (after scaling) - returns true if okay |
---|
788 | bool sanityCheck(); |
---|
789 | //@} |
---|
790 | public: |
---|
791 | /**@name public methods */ |
---|
792 | //@{ |
---|
793 | /** Return row or column sections - not as much needed as it |
---|
794 | once was. These just map into single arrays */ |
---|
795 | inline double * solutionRegion(int section) const |
---|
796 | { if (!section) return rowActivityWork_; else return columnActivityWork_;} |
---|
797 | inline double * djRegion(int section) const |
---|
798 | { if (!section) return rowReducedCost_; else return reducedCostWork_;} |
---|
799 | inline double * lowerRegion(int section) const |
---|
800 | { if (!section) return rowLowerWork_; else return columnLowerWork_;} |
---|
801 | inline double * upperRegion(int section) const |
---|
802 | { if (!section) return rowUpperWork_; else return columnUpperWork_;} |
---|
803 | inline double * costRegion(int section) const |
---|
804 | { if (!section) return rowObjectiveWork_; else return objectiveWork_;} |
---|
805 | /// Return region as single array |
---|
806 | inline double * solutionRegion() const |
---|
807 | { return solution_;} |
---|
808 | inline double * djRegion() const |
---|
809 | { return dj_;} |
---|
810 | inline double * lowerRegion() const |
---|
811 | { return lower_;} |
---|
812 | inline double * upperRegion() const |
---|
813 | { return upper_;} |
---|
814 | inline double * costRegion() const |
---|
815 | { return cost_;} |
---|
816 | inline Status getStatus(int sequence) const |
---|
817 | {return static_cast<Status> (status_[sequence]&7);} |
---|
818 | inline void setStatus(int sequence, Status status) |
---|
819 | { |
---|
820 | unsigned char & st_byte = status_[sequence]; |
---|
821 | st_byte &= ~7; |
---|
822 | st_byte |= status; |
---|
823 | } |
---|
824 | /// Start or reset using maximumRows_ and Columns_ - true if change |
---|
825 | bool startPermanentArrays(); |
---|
826 | /** Normally the first factorization does sparse coding because |
---|
827 | the factorization could be singular. This allows initial dense |
---|
828 | factorization when it is known to be safe |
---|
829 | */ |
---|
830 | void setInitialDenseFactorization(bool onOff); |
---|
831 | bool initialDenseFactorization() const; |
---|
832 | /** Return sequence In or Out */ |
---|
833 | inline int sequenceIn() const |
---|
834 | {return sequenceIn_;} |
---|
835 | inline int sequenceOut() const |
---|
836 | {return sequenceOut_;} |
---|
837 | /** Set sequenceIn or Out */ |
---|
838 | inline void setSequenceIn(int sequence) |
---|
839 | { sequenceIn_=sequence;} |
---|
840 | inline void setSequenceOut(int sequence) |
---|
841 | { sequenceOut_=sequence;} |
---|
842 | /** Return direction In or Out */ |
---|
843 | inline int directionIn() const |
---|
844 | {return directionIn_;} |
---|
845 | inline int directionOut() const |
---|
846 | {return directionOut_;} |
---|
847 | /** Set directionIn or Out */ |
---|
848 | inline void setDirectionIn(int direction) |
---|
849 | { directionIn_=direction;} |
---|
850 | inline void setDirectionOut(int direction) |
---|
851 | { directionOut_=direction;} |
---|
852 | /// Value of Out variable |
---|
853 | inline double valueOut() const |
---|
854 | { return valueOut_;} |
---|
855 | /// Returns 1 if sequence indicates column |
---|
856 | inline int isColumn(int sequence) const |
---|
857 | { return sequence<numberColumns_ ? 1 : 0;} |
---|
858 | /// Returns sequence number within section |
---|
859 | inline int sequenceWithin(int sequence) const |
---|
860 | { return sequence<numberColumns_ ? sequence : sequence-numberColumns_;} |
---|
861 | /// Return row or column values |
---|
862 | inline double solution(int sequence) |
---|
863 | { return solution_[sequence];} |
---|
864 | /// Return address of row or column values |
---|
865 | inline double & solutionAddress(int sequence) |
---|
866 | { return solution_[sequence];} |
---|
867 | inline double reducedCost(int sequence) |
---|
868 | { return dj_[sequence];} |
---|
869 | inline double & reducedCostAddress(int sequence) |
---|
870 | { return dj_[sequence];} |
---|
871 | inline double lower(int sequence) |
---|
872 | { return lower_[sequence];} |
---|
873 | /// Return address of row or column lower bound |
---|
874 | inline double & lowerAddress(int sequence) |
---|
875 | { return lower_[sequence];} |
---|
876 | inline double upper(int sequence) |
---|
877 | { return upper_[sequence];} |
---|
878 | /// Return address of row or column upper bound |
---|
879 | inline double & upperAddress(int sequence) |
---|
880 | { return upper_[sequence];} |
---|
881 | inline double cost(int sequence) |
---|
882 | { return cost_[sequence];} |
---|
883 | /// Return address of row or column cost |
---|
884 | inline double & costAddress(int sequence) |
---|
885 | { return cost_[sequence];} |
---|
886 | /// Return original lower bound |
---|
887 | inline double originalLower(int iSequence) const |
---|
888 | { if (iSequence<numberColumns_) return columnLower_[iSequence]; else |
---|
889 | return rowLower_[iSequence-numberColumns_];} |
---|
890 | /// Return original lower bound |
---|
891 | inline double originalUpper(int iSequence) const |
---|
892 | { if (iSequence<numberColumns_) return columnUpper_[iSequence]; else |
---|
893 | return rowUpper_[iSequence-numberColumns_];} |
---|
894 | /// Theta (pivot change) |
---|
895 | inline double theta() const |
---|
896 | { return theta_;} |
---|
897 | /// Return pointer to details of costs |
---|
898 | inline ClpNonLinearCost * nonLinearCost() const |
---|
899 | { return nonLinearCost_;} |
---|
900 | /** Return more special options |
---|
901 | 1 bit - if presolve says infeasible in ClpSolve return |
---|
902 | 2 bit - if presolved problem infeasible return |
---|
903 | 4 bit - keep arrays like upper_ around |
---|
904 | */ |
---|
905 | inline int moreSpecialOptions() const |
---|
906 | { return moreSpecialOptions_;} |
---|
907 | /** Set more special options |
---|
908 | 1 bit - if presolve says infeasible in ClpSolve return |
---|
909 | 2 bit - if presolved problem infeasible return |
---|
910 | 4 bit - keep arrays like upper_ around |
---|
911 | */ |
---|
912 | inline void setMoreSpecialOptions(int value) |
---|
913 | { moreSpecialOptions_ = value;} |
---|
914 | //@} |
---|
915 | /**@name status methods */ |
---|
916 | //@{ |
---|
917 | inline void setFakeBound(int sequence, FakeBound fakeBound) |
---|
918 | { |
---|
919 | unsigned char & st_byte = status_[sequence]; |
---|
920 | st_byte &= ~24; |
---|
921 | st_byte |= fakeBound<<3; |
---|
922 | } |
---|
923 | inline FakeBound getFakeBound(int sequence) const |
---|
924 | {return static_cast<FakeBound> ((status_[sequence]>>3)&3);} |
---|
925 | inline void setRowStatus(int sequence, Status status) |
---|
926 | { |
---|
927 | unsigned char & st_byte = status_[sequence+numberColumns_]; |
---|
928 | st_byte &= ~7; |
---|
929 | st_byte |= status; |
---|
930 | } |
---|
931 | inline Status getRowStatus(int sequence) const |
---|
932 | {return static_cast<Status> (status_[sequence+numberColumns_]&7);} |
---|
933 | inline void setColumnStatus(int sequence, Status status) |
---|
934 | { |
---|
935 | unsigned char & st_byte = status_[sequence]; |
---|
936 | st_byte &= ~7; |
---|
937 | st_byte |= status; |
---|
938 | } |
---|
939 | inline Status getColumnStatus(int sequence) const |
---|
940 | {return static_cast<Status> (status_[sequence]&7);} |
---|
941 | inline void setPivoted( int sequence) |
---|
942 | { status_[sequence] |= 32;} |
---|
943 | inline void clearPivoted( int sequence) |
---|
944 | { status_[sequence] &= ~32; } |
---|
945 | inline bool pivoted(int sequence) const |
---|
946 | {return (((status_[sequence]>>5)&1)!=0);} |
---|
947 | /// To flag a variable (not inline to allow for column generation) |
---|
948 | void setFlagged( int sequence); |
---|
949 | inline void clearFlagged( int sequence) |
---|
950 | { |
---|
951 | status_[sequence] &= ~64; |
---|
952 | } |
---|
953 | inline bool flagged(int sequence) const |
---|
954 | {return ((status_[sequence]&64)!=0);} |
---|
955 | /// To say row active in primal pivot row choice |
---|
956 | inline void setActive( int iRow) |
---|
957 | { |
---|
958 | status_[iRow] |= 128; |
---|
959 | } |
---|
960 | inline void clearActive( int iRow) |
---|
961 | { |
---|
962 | status_[iRow] &= ~128; |
---|
963 | } |
---|
964 | inline bool active(int iRow) const |
---|
965 | {return ((status_[iRow]&128)!=0);} |
---|
966 | /** Set up status array (can be used by OsiClp). |
---|
967 | Also can be used to set up all slack basis */ |
---|
968 | void createStatus() ; |
---|
969 | /** Sets up all slack basis and resets solution to |
---|
970 | as it was after initial load or readMps */ |
---|
971 | void allSlackBasis(bool resetSolution=false); |
---|
972 | |
---|
973 | /// So we know when to be cautious |
---|
974 | inline int lastBadIteration() const |
---|
975 | {return lastBadIteration_;} |
---|
976 | /// Progress flag - at present 0 bit says artificials out |
---|
977 | inline int progressFlag() const |
---|
978 | {return progressFlag_;} |
---|
979 | /// Force re-factorization early |
---|
980 | inline void forceFactorization(int value) |
---|
981 | { forceFactorization_ = value;} |
---|
982 | /// Raw objective value (so always minimize in primal) |
---|
983 | inline double rawObjectiveValue() const |
---|
984 | { return objectiveValue_;} |
---|
985 | /// Compute objective value from solution and put in objectiveValue_ |
---|
986 | void computeObjectiveValue(bool useWorkingSolution=false); |
---|
987 | /// Compute minimization objective value from internal solution without perturbation |
---|
988 | double computeInternalObjectiveValue(); |
---|
989 | /** Number of extra rows. These are ones which will be dynamically created |
---|
990 | each iteration. This is for GUB but may have other uses. |
---|
991 | */ |
---|
992 | inline int numberExtraRows() const |
---|
993 | { return numberExtraRows_;} |
---|
994 | /** Maximum number of basic variables - can be more than number of rows if GUB |
---|
995 | */ |
---|
996 | inline int maximumBasic() const |
---|
997 | { return maximumBasic_;} |
---|
998 | /// Iteration when we entered dual or primal |
---|
999 | inline int baseIteration() const |
---|
1000 | { return baseIteration_;} |
---|
1001 | /// Create C++ lines to get to current state |
---|
1002 | void generateCpp( FILE * fp,bool defaultFactor=false); |
---|
1003 | /// Gets clean and emptyish factorization |
---|
1004 | ClpFactorization * getEmptyFactorization(); |
---|
1005 | /// May delete or may make clean and emptyish factorization |
---|
1006 | void setEmptyFactorization(); |
---|
1007 | /// Move status and solution across |
---|
1008 | void moveInfo(const ClpSimplex & rhs, bool justStatus=false); |
---|
1009 | //@} |
---|
1010 | |
---|
1011 | ///@name Basis handling |
---|
1012 | // These are only to be used using startFinishOptions (ClpSimplexDual, ClpSimplexPrimal) |
---|
1013 | // *** At present only without scaling |
---|
1014 | // *** Slacks havve -1.0 element (so == row activity) - take care |
---|
1015 | ///Get a row of the tableau (slack part in slack if not NULL) |
---|
1016 | void getBInvARow(int row, double* z, double * slack=NULL); |
---|
1017 | |
---|
1018 | ///Get a row of the basis inverse |
---|
1019 | void getBInvRow(int row, double* z); |
---|
1020 | |
---|
1021 | ///Get a column of the tableau |
---|
1022 | void getBInvACol(int col, double* vec); |
---|
1023 | |
---|
1024 | ///Get a column of the basis inverse |
---|
1025 | void getBInvCol(int col, double* vec); |
---|
1026 | |
---|
1027 | /** Get basic indices (order of indices corresponds to the |
---|
1028 | order of elements in a vector retured by getBInvACol() and |
---|
1029 | getBInvCol()). |
---|
1030 | */ |
---|
1031 | void getBasics(int* index); |
---|
1032 | |
---|
1033 | //@} |
---|
1034 | //------------------------------------------------------------------------- |
---|
1035 | /**@name Changing bounds on variables and constraints */ |
---|
1036 | //@{ |
---|
1037 | /** Set an objective function coefficient */ |
---|
1038 | void setObjectiveCoefficient( int elementIndex, double elementValue ); |
---|
1039 | /** Set an objective function coefficient */ |
---|
1040 | inline void setObjCoeff( int elementIndex, double elementValue ) |
---|
1041 | { setObjectiveCoefficient( elementIndex, elementValue);} |
---|
1042 | |
---|
1043 | /** Set a single column lower bound<br> |
---|
1044 | Use -DBL_MAX for -infinity. */ |
---|
1045 | void setColumnLower( int elementIndex, double elementValue ); |
---|
1046 | |
---|
1047 | /** Set a single column upper bound<br> |
---|
1048 | Use DBL_MAX for infinity. */ |
---|
1049 | void setColumnUpper( int elementIndex, double elementValue ); |
---|
1050 | |
---|
1051 | /** Set a single column lower and upper bound */ |
---|
1052 | void setColumnBounds( int elementIndex, |
---|
1053 | double lower, double upper ); |
---|
1054 | |
---|
1055 | /** Set the bounds on a number of columns simultaneously<br> |
---|
1056 | The default implementation just invokes setColLower() and |
---|
1057 | setColUpper() over and over again. |
---|
1058 | @param indexFirst,indexLast pointers to the beginning and after the |
---|
1059 | end of the array of the indices of the variables whose |
---|
1060 | <em>either</em> bound changes |
---|
1061 | @param boundList the new lower/upper bound pairs for the variables |
---|
1062 | */ |
---|
1063 | void setColumnSetBounds(const int* indexFirst, |
---|
1064 | const int* indexLast, |
---|
1065 | const double* boundList); |
---|
1066 | |
---|
1067 | /** Set a single column lower bound<br> |
---|
1068 | Use -DBL_MAX for -infinity. */ |
---|
1069 | inline void setColLower( int elementIndex, double elementValue ) |
---|
1070 | { setColumnLower(elementIndex, elementValue);} |
---|
1071 | /** Set a single column upper bound<br> |
---|
1072 | Use DBL_MAX for infinity. */ |
---|
1073 | inline void setColUpper( int elementIndex, double elementValue ) |
---|
1074 | { setColumnUpper(elementIndex, elementValue);} |
---|
1075 | |
---|
1076 | /** Set a single column lower and upper bound */ |
---|
1077 | inline void setColBounds( int elementIndex, |
---|
1078 | double lower, double upper ) |
---|
1079 | { setColumnBounds(elementIndex, lower, upper);} |
---|
1080 | |
---|
1081 | /** Set the bounds on a number of columns simultaneously<br> |
---|
1082 | @param indexFirst,indexLast pointers to the beginning and after the |
---|
1083 | end of the array of the indices of the variables whose |
---|
1084 | <em>either</em> bound changes |
---|
1085 | @param boundList the new lower/upper bound pairs for the variables |
---|
1086 | */ |
---|
1087 | inline void setColSetBounds(const int* indexFirst, |
---|
1088 | const int* indexLast, |
---|
1089 | const double* boundList) |
---|
1090 | { setColumnSetBounds(indexFirst, indexLast, boundList);} |
---|
1091 | |
---|
1092 | /** Set a single row lower bound<br> |
---|
1093 | Use -DBL_MAX for -infinity. */ |
---|
1094 | void setRowLower( int elementIndex, double elementValue ); |
---|
1095 | |
---|
1096 | /** Set a single row upper bound<br> |
---|
1097 | Use DBL_MAX for infinity. */ |
---|
1098 | void setRowUpper( int elementIndex, double elementValue ) ; |
---|
1099 | |
---|
1100 | /** Set a single row lower and upper bound */ |
---|
1101 | void setRowBounds( int elementIndex, |
---|
1102 | double lower, double upper ) ; |
---|
1103 | |
---|
1104 | /** Set the bounds on a number of rows simultaneously<br> |
---|
1105 | @param indexFirst,indexLast pointers to the beginning and after the |
---|
1106 | end of the array of the indices of the constraints whose |
---|
1107 | <em>either</em> bound changes |
---|
1108 | @param boundList the new lower/upper bound pairs for the constraints |
---|
1109 | */ |
---|
1110 | void setRowSetBounds(const int* indexFirst, |
---|
1111 | const int* indexLast, |
---|
1112 | const double* boundList); |
---|
1113 | |
---|
1114 | //@} |
---|
1115 | |
---|
1116 | ////////////////// data ////////////////// |
---|
1117 | protected: |
---|
1118 | |
---|
1119 | /**@name data. Many arrays have a row part and a column part. |
---|
1120 | There is a single array with both - columns then rows and |
---|
1121 | then normally two arrays pointing to rows and columns. The |
---|
1122 | single array is the owner of memory |
---|
1123 | */ |
---|
1124 | //@{ |
---|
1125 | /// Worst column primal infeasibility |
---|
1126 | double columnPrimalInfeasibility_; |
---|
1127 | /// Worst row primal infeasibility |
---|
1128 | double rowPrimalInfeasibility_; |
---|
1129 | /// Sequence of worst (-1 if feasible) |
---|
1130 | int columnPrimalSequence_; |
---|
1131 | /// Sequence of worst (-1 if feasible) |
---|
1132 | int rowPrimalSequence_; |
---|
1133 | /// Worst column dual infeasibility |
---|
1134 | double columnDualInfeasibility_; |
---|
1135 | /// Worst row dual infeasibility |
---|
1136 | double rowDualInfeasibility_; |
---|
1137 | /// More special options - see set for details |
---|
1138 | int moreSpecialOptions_; |
---|
1139 | /// Iteration when we entered dual or primal |
---|
1140 | int baseIteration_; |
---|
1141 | /// Primal tolerance needed to make dual feasible (<largeTolerance) |
---|
1142 | double primalToleranceToGetOptimal_; |
---|
1143 | /// Remaining largest dual infeasibility |
---|
1144 | double remainingDualInfeasibility_; |
---|
1145 | /// Large bound value (for complementarity etc) |
---|
1146 | double largeValue_; |
---|
1147 | /// Largest error on Ax-b |
---|
1148 | double largestPrimalError_; |
---|
1149 | /// Largest error on basic duals |
---|
1150 | double largestDualError_; |
---|
1151 | /// For computing whether to re-factorize |
---|
1152 | double alphaAccuracy_; |
---|
1153 | /// Dual bound |
---|
1154 | double dualBound_; |
---|
1155 | /// Alpha (pivot element) |
---|
1156 | double alpha_; |
---|
1157 | /// Theta (pivot change) |
---|
1158 | double theta_; |
---|
1159 | /// Lower Bound on In variable |
---|
1160 | double lowerIn_; |
---|
1161 | /// Value of In variable |
---|
1162 | double valueIn_; |
---|
1163 | /// Upper Bound on In variable |
---|
1164 | double upperIn_; |
---|
1165 | /// Reduced cost of In variable |
---|
1166 | double dualIn_; |
---|
1167 | /// Lower Bound on Out variable |
---|
1168 | double lowerOut_; |
---|
1169 | /// Value of Out variable |
---|
1170 | double valueOut_; |
---|
1171 | /// Upper Bound on Out variable |
---|
1172 | double upperOut_; |
---|
1173 | /// Infeasibility (dual) or ? (primal) of Out variable |
---|
1174 | double dualOut_; |
---|
1175 | /// Current dual tolerance for algorithm |
---|
1176 | double dualTolerance_; |
---|
1177 | /// Current primal tolerance for algorithm |
---|
1178 | double primalTolerance_; |
---|
1179 | /// Sum of dual infeasibilities |
---|
1180 | double sumDualInfeasibilities_; |
---|
1181 | /// Sum of primal infeasibilities |
---|
1182 | double sumPrimalInfeasibilities_; |
---|
1183 | /// Weight assigned to being infeasible in primal |
---|
1184 | double infeasibilityCost_; |
---|
1185 | /// Sum of Dual infeasibilities using tolerance based on error in duals |
---|
1186 | double sumOfRelaxedDualInfeasibilities_; |
---|
1187 | /// Sum of Primal infeasibilities using tolerance based on error in primals |
---|
1188 | double sumOfRelaxedPrimalInfeasibilities_; |
---|
1189 | /// Acceptable pivot value just after factorization |
---|
1190 | double acceptablePivot_; |
---|
1191 | /// Working copy of lower bounds (Owner of arrays below) |
---|
1192 | double * lower_; |
---|
1193 | /// Row lower bounds - working copy |
---|
1194 | double * rowLowerWork_; |
---|
1195 | /// Column lower bounds - working copy |
---|
1196 | double * columnLowerWork_; |
---|
1197 | /// Working copy of upper bounds (Owner of arrays below) |
---|
1198 | double * upper_; |
---|
1199 | /// Row upper bounds - working copy |
---|
1200 | double * rowUpperWork_; |
---|
1201 | /// Column upper bounds - working copy |
---|
1202 | double * columnUpperWork_; |
---|
1203 | /// Working copy of objective (Owner of arrays below) |
---|
1204 | double * cost_; |
---|
1205 | /// Row objective - working copy |
---|
1206 | double * rowObjectiveWork_; |
---|
1207 | /// Column objective - working copy |
---|
1208 | double * objectiveWork_; |
---|
1209 | /// Useful row length arrays |
---|
1210 | CoinIndexedVector * rowArray_[6]; |
---|
1211 | /// Useful column length arrays |
---|
1212 | CoinIndexedVector * columnArray_[6]; |
---|
1213 | /// Sequence of In variable |
---|
1214 | int sequenceIn_; |
---|
1215 | /// Direction of In, 1 going up, -1 going down, 0 not a clude |
---|
1216 | int directionIn_; |
---|
1217 | /// Sequence of Out variable |
---|
1218 | int sequenceOut_; |
---|
1219 | /// Direction of Out, 1 to upper bound, -1 to lower bound, 0 - superbasic |
---|
1220 | int directionOut_; |
---|
1221 | /// Pivot Row |
---|
1222 | int pivotRow_; |
---|
1223 | /// Last good iteration (immediately after a re-factorization) |
---|
1224 | int lastGoodIteration_; |
---|
1225 | /// Working copy of reduced costs (Owner of arrays below) |
---|
1226 | double * dj_; |
---|
1227 | /// Reduced costs of slacks not same as duals (or - duals) |
---|
1228 | double * rowReducedCost_; |
---|
1229 | /// Possible scaled reduced costs |
---|
1230 | double * reducedCostWork_; |
---|
1231 | /// Working copy of primal solution (Owner of arrays below) |
---|
1232 | double * solution_; |
---|
1233 | /// Row activities - working copy |
---|
1234 | double * rowActivityWork_; |
---|
1235 | /// Column activities - working copy |
---|
1236 | double * columnActivityWork_; |
---|
1237 | /// Auxiliary model |
---|
1238 | ClpSimplex * auxiliaryModel_; |
---|
1239 | /// Number of dual infeasibilities |
---|
1240 | int numberDualInfeasibilities_; |
---|
1241 | /// Number of dual infeasibilities (without free) |
---|
1242 | int numberDualInfeasibilitiesWithoutFree_; |
---|
1243 | /// Number of primal infeasibilities |
---|
1244 | int numberPrimalInfeasibilities_; |
---|
1245 | /// How many iterative refinements to do |
---|
1246 | int numberRefinements_; |
---|
1247 | /// dual row pivot choice |
---|
1248 | ClpDualRowPivot * dualRowPivot_; |
---|
1249 | /// primal column pivot choice |
---|
1250 | ClpPrimalColumnPivot * primalColumnPivot_; |
---|
1251 | /// Basic variables pivoting on which rows |
---|
1252 | int * pivotVariable_; |
---|
1253 | /// factorization |
---|
1254 | ClpFactorization * factorization_; |
---|
1255 | /// Saved version of solution |
---|
1256 | double * savedSolution_; |
---|
1257 | /// Number of times code has tentatively thought optimal |
---|
1258 | int numberTimesOptimal_; |
---|
1259 | /// Disaster handler |
---|
1260 | ClpDisasterHandler * disasterArea_; |
---|
1261 | /// If change has been made (first attempt at stopping looping) |
---|
1262 | int changeMade_; |
---|
1263 | /// Algorithm >0 == Primal, <0 == Dual |
---|
1264 | int algorithm_; |
---|
1265 | /** Now for some reliability aids |
---|
1266 | This forces re-factorization early */ |
---|
1267 | int forceFactorization_; |
---|
1268 | /** Perturbation: |
---|
1269 | -50 to +50 - perturb by this power of ten (-6 sounds good) |
---|
1270 | 100 - auto perturb if takes too long (1.0e-6 largest nonzero) |
---|
1271 | 101 - we are perturbed |
---|
1272 | 102 - don't try perturbing again |
---|
1273 | default is 100 |
---|
1274 | */ |
---|
1275 | int perturbation_; |
---|
1276 | /// Saved status regions |
---|
1277 | unsigned char * saveStatus_; |
---|
1278 | /** Very wasteful way of dealing with infeasibilities in primal. |
---|
1279 | However it will allow non-linearities and use of dual |
---|
1280 | analysis. If it doesn't work it can easily be replaced. |
---|
1281 | */ |
---|
1282 | ClpNonLinearCost * nonLinearCost_; |
---|
1283 | /// So we know when to be cautious |
---|
1284 | int lastBadIteration_; |
---|
1285 | /// So we know when to open up again |
---|
1286 | int lastFlaggedIteration_; |
---|
1287 | /// Can be used for count of fake bounds (dual) or fake costs (primal) |
---|
1288 | int numberFake_; |
---|
1289 | /// Can be used for count of changed costs (dual) or changed bounds (primal) |
---|
1290 | int numberChanged_; |
---|
1291 | /// Progress flag - at present 0 bit says artificials out, 1 free in |
---|
1292 | int progressFlag_; |
---|
1293 | /// First free/super-basic variable (-1 if none) |
---|
1294 | int firstFree_; |
---|
1295 | /** Number of extra rows. These are ones which will be dynamically created |
---|
1296 | each iteration. This is for GUB but may have other uses. |
---|
1297 | */ |
---|
1298 | int numberExtraRows_; |
---|
1299 | /** Maximum number of basic variables - can be more than number of rows if GUB |
---|
1300 | */ |
---|
1301 | int maximumBasic_; |
---|
1302 | /** For advanced use. When doing iterative solves things can get |
---|
1303 | nasty so on values pass if incoming solution has largest |
---|
1304 | infeasibility < incomingInfeasibility throw out variables |
---|
1305 | from basis until largest infeasibility < allowedInfeasibility. |
---|
1306 | if allowedInfeasibility>= incomingInfeasibility this is |
---|
1307 | always possible altough you may end up with an all slack basis. |
---|
1308 | |
---|
1309 | Defaults are 1.0,10.0 |
---|
1310 | */ |
---|
1311 | double incomingInfeasibility_; |
---|
1312 | double allowedInfeasibility_; |
---|
1313 | /// Automatic scaling of objective and rhs and bounds |
---|
1314 | int automaticScale_; |
---|
1315 | /// A copy of model with certain state - normally without cuts |
---|
1316 | ClpSimplex * baseModel_; |
---|
1317 | /// For dealing with all issues of cycling etc |
---|
1318 | ClpSimplexProgress progress_; |
---|
1319 | public: |
---|
1320 | /// Spare int array for passing information [0]!=0 switches on |
---|
1321 | mutable int spareIntArray_[4]; |
---|
1322 | /// Spare double array for passing information [0]!=0 switches on |
---|
1323 | mutable double spareDoubleArray_[4]; |
---|
1324 | protected: |
---|
1325 | /// Allow OsiClp certain perks |
---|
1326 | friend class OsiClpSolverInterface; |
---|
1327 | //@} |
---|
1328 | }; |
---|
1329 | //############################################################################# |
---|
1330 | /** A function that tests the methods in the ClpSimplex class. The |
---|
1331 | only reason for it not to be a member method is that this way it doesn't |
---|
1332 | have to be compiled into the library. And that's a gain, because the |
---|
1333 | library should be compiled with optimization on, but this method should be |
---|
1334 | compiled with debugging. |
---|
1335 | |
---|
1336 | It also does some testing of ClpFactorization class |
---|
1337 | */ |
---|
1338 | void |
---|
1339 | ClpSimplexUnitTest(const std::string & mpsDir); |
---|
1340 | |
---|
1341 | // For Devex stuff |
---|
1342 | #define DEVEX_TRY_NORM 1.0e-4 |
---|
1343 | #define DEVEX_ADD_ONE 1.0 |
---|
1344 | #endif |
---|