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

Last change on this file since 1015 was 1015, checked in by forrest, 12 years ago

to try and help with trunk branches mess

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