source: trunk/Clp/src/ClpSimplex.hpp @ 1921

Last change on this file since 1921 was 1921, checked in by stefan, 7 years ago

include AbcCommon? only if Aboca is enabled

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