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

Last change on this file since 912 was 912, checked in by forrest, 13 years ago

ranging

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