source: branches/devel/Clp/src/ClpSimplex.hpp @ 989

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

this may be a mistake

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.4 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#include <iostream>
14#include <cfloat>
15#include "ClpModel.hpp"
16#include "ClpMatrixBase.hpp"
17#include "ClpSolve.hpp"
18class ClpDualRowPivot;
19class ClpPrimalColumnPivot;
20class ClpFactorization;
21class CoinIndexedVector;
22class ClpNonLinearCost;
23class ClpSimplexProgress;
24class CoinModel;
25class OsiClpSolverInterface;
26class CoinWarmStartBasis;
27class ClpDisasterHandler;
28
29/** This solves LPs using the simplex method
30
31    It inherits from ClpModel and all its arrays are created at
32    algorithm time. Originally I tried to work with model arrays
33    but for simplicity of coding I changed to single arrays with
34    structural variables then row variables.  Some coding is still
35    based on old style and needs cleaning up.
36
37    For a description of algorithms:
38
39    for dual see ClpSimplexDual.hpp and at top of ClpSimplexDual.cpp
40    for primal see ClpSimplexPrimal.hpp and at top of ClpSimplexPrimal.cpp
41
42    There is an algorithm data member.  + for primal variations
43    and - for dual variations
44
45    This file also includes (at end) a very simple class ClpSimplexProgress
46    which is where anti-looping stuff should migrate to
47
48*/
49
50class ClpSimplex : public ClpModel {
51   friend void ClpSimplexUnitTest(const std::string & mpsDir,
52                                  const std::string & netlibDir);
53
54public:
55  /** enums for status of various sorts.
56      First 4 match CoinWarmStartBasis,
57      isFixed means fixed at lower bound and out of basis
58  */
59  enum Status {
60    isFree = 0x00,
61    basic = 0x01,
62    atUpperBound = 0x02,
63    atLowerBound = 0x03,
64    superBasic = 0x04,
65    isFixed = 0x05
66  };
67  // For Dual
68  enum FakeBound {
69    noFake = 0x00,
70    bothFake = 0x01,
71    upperFake = 0x02,
72    lowerFake = 0x03
73  };
74
75  /**@name Constructors and destructor and copy */
76  //@{
77  /// Default constructor
78    ClpSimplex (bool emptyMessages = false  );
79
80  /** Copy constructor. May scale depending on mode
81      -1 leave mode as is
82      0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later)
83  */
84  ClpSimplex(const ClpSimplex & rhs, int scalingMode =-1);
85  /** Copy constructor from model. 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 ClpModel & rhs, int scalingMode=-1);
90  /** Subproblem constructor.  A subset of whole model is created from the
91      row and column lists given.  The new order is given by list order and
92      duplicates are allowed.  Name and integer information can be dropped
93      Can optionally modify rhs to take into account variables NOT in list
94      in this case duplicates are not allowed (also see getbackSolution)
95  */
96  ClpSimplex (const ClpModel * wholeModel,
97              int numberRows, const int * whichRows,
98              int numberColumns, const int * whichColumns,
99              bool dropNames=true, bool dropIntegers=true,
100              bool fixOthers=false);
101  /** This constructor modifies original ClpSimplex and stores
102      original stuff in created ClpSimplex.  It is only to be used in
103      conjunction with originalModel */
104  ClpSimplex (ClpSimplex * wholeModel,
105              int numberColumns, const int * whichColumns);
106  /** This copies back stuff from miniModel and then deletes miniModel.
107      Only to be used with mini constructor */
108  void originalModel(ClpSimplex * miniModel);
109  /** Array persistence flag
110      If 0 then as now (delete/new)
111      1 then only do arrays if bigger needed
112      2 as 1 but give a bit extra if bigger needed
113  */
114  void setPersistenceFlag(int value);
115  /**
116     If you are re-using the same matrix again and again then the setup time
117     to do scaling may be significant.  Also you may not want to initialize all values
118     or return all values (especially if infeasible).  While an auxiliary model exists
119     it will be faster.  If options -1 then model is switched off.  Otherwise switched on
120     with following options.
121     1 - rhs is constant
122     2 - bounds are constant
123     4 - objective is constant
124     8 - solution in by basis and no djs etc in
125     16 - no duals out (but reduced costs)
126     32 - no output if infeasible
127  */
128  void auxiliaryModel(int options);
129  /// Switch off e.g. if people using presolve
130  void deleteAuxiliaryModel();
131  /// See if we have auxiliary model
132  inline bool usingAuxiliaryModel() const
133  { return auxiliaryModel_!=NULL;};
134  /// Assignment operator. This copies the data
135    ClpSimplex & operator=(const ClpSimplex & rhs);
136  /// Destructor
137   ~ClpSimplex (  );
138  // Ones below are just ClpModel with some changes
139  /** Loads a problem (the constraints on the
140        rows are given by lower and upper bounds). If a pointer is 0 then the
141        following values are the default:
142        <ul>
143          <li> <code>colub</code>: all columns have upper bound infinity
144          <li> <code>collb</code>: all columns have lower bound 0
145          <li> <code>rowub</code>: all rows have upper bound infinity
146          <li> <code>rowlb</code>: all rows have lower bound -infinity
147          <li> <code>obj</code>: all variables have 0 objective coefficient
148        </ul>
149    */
150  void loadProblem (  const ClpMatrixBase& matrix,
151                     const double* collb, const double* colub,   
152                     const double* obj,
153                     const double* rowlb, const double* rowub,
154                      const double * rowObjective=NULL);
155  void loadProblem (  const CoinPackedMatrix& matrix,
156                     const double* collb, const double* colub,   
157                     const double* obj,
158                     const double* rowlb, const double* rowub,
159                      const double * rowObjective=NULL);
160
161  /** Just like the other loadProblem() method except that the matrix is
162        given in a standard column major ordered format (without gaps). */
163  void loadProblem (  const int numcols, const int numrows,
164                     const CoinBigIndex* start, const int* index,
165                     const double* value,
166                     const double* collb, const double* colub,   
167                     const double* obj,
168                      const double* rowlb, const double* rowub,
169                      const double * rowObjective=NULL);
170  /// This one is for after presolve to save memory
171  void loadProblem (  const int numcols, const int numrows,
172                     const CoinBigIndex* start, const int* index,
173                      const double* value,const int * length,
174                     const double* collb, const double* colub,   
175                     const double* obj,
176                      const double* rowlb, const double* rowub,
177                      const double * rowObjective=NULL);
178  /** This loads a model from a coinModel object - returns number of errors.
179      If keepSolution true and size is same as current then
180      keeps current status and solution
181  */
182  int loadProblem (  CoinModel & modelObject,bool keepSolution=false);
183  /// Read an mps file from the given filename
184  int readMps(const char *filename,
185              bool keepNames=false,
186              bool ignoreErrors = false);
187  /// Read GMPL files from the given filenames
188  int readGMPL(const char *filename,const char * dataName,
189               bool keepNames=false);
190  /** Borrow model.  This is so we dont have to copy large amounts
191      of data around.  It assumes a derived class wants to overwrite
192      an empty model with a real one - while it does an algorithm.
193      This is same as ClpModel one, but sets scaling on etc. */
194  void borrowModel(ClpModel & otherModel);
195  void borrowModel(ClpSimplex & otherModel);
196   /// Pass in Event handler (cloned and deleted at end)
197   void passInEventHandler(const ClpEventHandler * eventHandler);
198  /// Puts solution back into small model
199  void getbackSolution(const ClpSimplex & smallModel,const int * whichRow, const int * whichColumn);
200  //@}
201
202  /**@name Functions most useful to user */
203  //@{
204  /** General solve algorithm which can do presolve.
205      See  ClpSolve.hpp for options
206   */
207  int initialSolve(ClpSolve & options);
208  /// Default initial solve
209  int initialSolve();
210  /// Dual initial solve
211  int initialDualSolve();
212  /// Primal initial solve
213  int initialPrimalSolve();
214 /// Barrier initial solve
215  int initialBarrierSolve();
216  /// Barrier initial solve, not to be followed by crossover
217  int initialBarrierNoCrossSolve();
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  /** 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  /// Number of dual infeasibilities (without free)
492  inline int numberDualInfeasibilitiesWithoutFree() const 
493          { return numberDualInfeasibilitiesWithoutFree_;} ;
494  /// Sum of primal infeasibilities
495  inline double sumPrimalInfeasibilities() const 
496          { return sumPrimalInfeasibilities_;} ;
497  inline void setSumPrimalInfeasibilities(double value)
498          { sumPrimalInfeasibilities_=value;} ;
499  /// Sum of relaxed primal infeasibilities
500  inline double sumOfRelaxedPrimalInfeasibilities() const 
501          { return sumOfRelaxedPrimalInfeasibilities_;} ;
502  inline void setSumOfRelaxedPrimalInfeasibilities(double value)
503          { sumOfRelaxedPrimalInfeasibilities_=value;} ;
504  /// Number of primal infeasibilities
505  inline int numberPrimalInfeasibilities() const 
506          { return numberPrimalInfeasibilities_;} ;
507  inline void setNumberPrimalInfeasibilities(int value)
508          { numberPrimalInfeasibilities_=value;} ;
509  /** Save model to file, returns 0 if success.  This is designed for
510      use outside algorithms so does not save iterating arrays etc.
511  It does not save any messaging information.
512  Does not save scaling values.
513  It does not know about all types of virtual functions.
514  */
515  int saveModel(const char * fileName);
516  /** Restore model from file, returns 0 if success,
517      deletes current model */
518  int restoreModel(const char * fileName);
519 
520  /** Just check solution (for external use) - sets sum of
521      infeasibilities etc.
522      If setToBounds 0 then primal column values not changed
523      and used to compute primal row activity values.  If 1 or 2
524      then status used - so all nonbasic variables set to
525      indicated bound and if any values changed (or ==2)  basic values re-computed.
526  */
527  void checkSolution(int setToBounds=false);
528  /** Just check solution (for internal use) - sets sum of
529      infeasibilities etc. */
530  void checkSolutionInternal();
531  /// Useful row length arrays (0,1,2,3,4,5)
532  inline CoinIndexedVector * rowArray(int index) const
533  { return rowArray_[index];};
534  /// Useful column length arrays (0,1,2,3,4,5)
535  inline CoinIndexedVector * columnArray(int index) const
536  { return columnArray_[index];};
537  //@}
538
539  /******************** End of most useful part **************/
540  /**@name Functions less likely to be useful to casual user */
541  //@{
542  /** Given an existing factorization computes and checks
543      primal and dual solutions.  Uses input arrays for variables at
544      bounds.  Returns feasibility states */
545  int getSolution (  const double * rowActivities,
546                     const double * columnActivities);
547  /** Given an existing factorization computes and checks
548      primal and dual solutions.  Uses current problem arrays for
549      bounds.  Returns feasibility states */
550  int getSolution ();
551  /** Constructs a non linear cost from list of non-linearities (columns only)
552      First lower of each column is taken as real lower
553      Last lower is taken as real upper and cost ignored
554
555      Returns nonzero if bad data e.g. lowers not monotonic
556  */
557  int createPiecewiseLinearCosts(const int * starts,
558                   const double * lower, const double * gradient);
559  /** Return model - updates any scalars */
560  void returnModel(ClpSimplex & otherModel);
561  /** Factorizes using current basis. 
562      solveType - 1 iterating, 0 initial, -1 external
563      If 10 added then in primal values pass
564      Return codes are as from ClpFactorization unless initial factorization
565      when total number of singularities is returned.
566      Special case is numberRows_+1 -> all slack basis.
567  */
568  int internalFactorize(int solveType);
569  /// Save data
570  ClpDataSave saveData() ;
571  /// Restore data
572  void restoreData(ClpDataSave saved);
573  /// Clean up status
574  void cleanStatus();
575  /// Factorizes using current basis. For external use
576  int factorize();
577  /** Computes duals from scratch. If givenDjs then
578      allows for nonzero basic djs */
579  void computeDuals(double * givenDjs);
580  /// Computes primals from scratch
581  void computePrimals (  const double * rowActivities,
582                     const double * columnActivities);
583  /** Adds multiple of a column into an array */
584  void add(double * array,
585                   int column, double multiplier) const;
586  /**
587     Unpacks one column of the matrix into indexed array
588     Uses sequenceIn_
589     Also applies scaling if needed
590  */
591  void unpack(CoinIndexedVector * rowArray) const ;
592  /**
593     Unpacks one column of the matrix into indexed array
594     Slack if sequence>= numberColumns
595     Also applies scaling if needed
596  */
597  void unpack(CoinIndexedVector * rowArray,int sequence) const;
598  /**
599     Unpacks one column of the matrix into indexed array
600     ** as packed vector
601     Uses sequenceIn_
602     Also applies scaling if needed
603  */
604  void unpackPacked(CoinIndexedVector * rowArray) ;
605  /**
606     Unpacks one column of the matrix into indexed array
607     ** as packed vector
608     Slack if sequence>= numberColumns
609     Also applies scaling if needed
610  */
611  void unpackPacked(CoinIndexedVector * rowArray,int sequence);
612protected: 
613  /**
614      This does basis housekeeping and does values for in/out variables.
615      Can also decide to re-factorize
616  */
617  int housekeeping(double objectiveChange);
618  /** This sets largest infeasibility and most infeasible and sum
619      and number of infeasibilities (Primal) */
620  void checkPrimalSolution(const double * rowActivities=NULL,
621                           const double * columnActivies=NULL);
622  /** This sets largest infeasibility and most infeasible and sum
623      and number of infeasibilities (Dual) */
624  void checkDualSolution();
625  /** This sets sum and number of infeasibilities (Dual and Primal) */
626  void checkBothSolutions();
627public:
628  /** For advanced use.  When doing iterative solves things can get
629      nasty so on values pass if incoming solution has largest
630      infeasibility < incomingInfeasibility throw out variables
631      from basis until largest infeasibility < allowedInfeasibility
632      or incoming largest infeasibility.
633      If allowedInfeasibility>= incomingInfeasibility this is
634      always possible altough you may end up with an all slack basis.
635
636      Defaults are 1.0,10.0
637  */
638  void setValuesPassAction(float incomingInfeasibility,
639                           float allowedInfeasibility);
640  //@}
641  /**@name most useful gets and sets */
642  //@{
643public: 
644  /// Initial value for alpha accuracy calculation (-1.0 off)
645  inline double alphaAccuracy() const
646          { return alphaAccuracy_;} ;
647  inline void setAlphaAccuracy(double value)
648          { alphaAccuracy_ = value;} ;
649public:
650  /// Disaster handler
651  inline void setDisasterHandler(ClpDisasterHandler * handler)
652  { disasterArea_= handler;};
653  /// Large bound value (for complementarity etc)
654  inline double largeValue() const 
655          { return largeValue_;} ;
656  void setLargeValue( double value) ;
657  /// Largest error on Ax-b
658  inline double largestPrimalError() const
659          { return largestPrimalError_;} ;
660  /// Largest error on basic duals
661  inline double largestDualError() const
662          { return largestDualError_;} ;
663  /// Largest error on Ax-b
664  inline void setLargestPrimalError(double value)
665          { largestPrimalError_=value;} ;
666  /// Largest error on basic duals
667  inline void setLargestDualError(double value)
668          { largestDualError_=value;} ;
669  /// Basic variables pivoting on which rows
670  inline int * pivotVariable() const
671          { return pivotVariable_;};
672  /// If automatic scaling on
673  inline bool automaticScaling() const
674  { return automaticScale_!=0;};
675  inline void setAutomaticScaling(bool onOff)
676  { automaticScale_ = onOff ? 1: 0;}; 
677  /// Current dual tolerance
678  inline double currentDualTolerance() const 
679          { return dualTolerance_;} ;
680  inline void setCurrentDualTolerance(double value)
681          { dualTolerance_ = value;} ;
682  /// Current primal tolerance
683  inline double currentPrimalTolerance() const 
684          { return primalTolerance_;} ;
685  inline void setCurrentPrimalTolerance(double value)
686          { primalTolerance_ = value;} ;
687  /// How many iterative refinements to do
688  inline int numberRefinements() const 
689          { return numberRefinements_;} ;
690  void setNumberRefinements( int value) ;
691  /// Alpha (pivot element) for use by classes e.g. steepestedge
692  inline double alpha() const { return alpha_;};
693  inline void setAlpha(double value) { alpha_ = value;};
694  /// Reduced cost of last incoming for use by classes e.g. steepestedge
695  inline double dualIn() const { return dualIn_;};
696  /// Pivot Row for use by classes e.g. steepestedge
697  inline int pivotRow() const{ return pivotRow_;};
698  inline void setPivotRow(int value) { pivotRow_=value;};
699  /// value of incoming variable (in Dual)
700  double valueIncomingDual() const;
701  //@}
702
703  protected:
704  /**@name protected methods */
705  //@{
706  /** May change basis and then returns number changed.
707      Computation of solutions may be overriden by given pi and solution
708  */
709  int gutsOfSolution ( double * givenDuals,
710                       const double * givenPrimals,
711                       bool valuesPass=false);
712  /// Does most of deletion (0 = all, 1 = most, 2 most + factorization)
713  void gutsOfDelete(int type);
714  /// Does most of copying
715  void gutsOfCopy(const ClpSimplex & rhs);
716  /** puts in format I like (rowLower,rowUpper) also see StandardMatrix
717      1 bit does rows, 2 bit does column bounds, 4 bit does objective(s).
718      8 bit does solution scaling in
719      16 bit does rowArray and columnArray indexed vectors
720      and makes row copy if wanted, also sets columnStart_ etc
721      Also creates scaling arrays if needed.  It does scaling if needed.
722      16 also moves solutions etc in to work arrays
723      On 16 returns false if problem "bad" i.e. matrix or bounds bad
724      If startFinishOptions is -1 then called by user in getSolution
725      so do arrays but keep pivotVariable_
726  */
727  bool createRim(int what,bool makeRowCopy=false,int startFinishOptions=0);
728  /** releases above arrays and does solution scaling out.  May also
729      get rid of factorization data -
730      0 get rid of nothing, 1 get rid of arrays, 2 also factorization
731  */
732  void deleteRim(int getRidOfFactorizationData=2);
733  /// Sanity check on input rim data (after scaling) - returns true if okay
734  bool sanityCheck();
735  //@}
736  public:
737  /**@name public methods */
738  //@{
739  /** Return row or column sections - not as much needed as it
740      once was.  These just map into single arrays */
741  inline double * solutionRegion(int section) const
742  { if (!section) return rowActivityWork_; else return columnActivityWork_;};
743  inline double * djRegion(int section) const
744  { if (!section) return rowReducedCost_; else return reducedCostWork_;};
745  inline double * lowerRegion(int section) const
746  { if (!section) return rowLowerWork_; else return columnLowerWork_;};
747  inline double * upperRegion(int section) const
748  { if (!section) return rowUpperWork_; else return columnUpperWork_;};
749  inline double * costRegion(int section) const
750  { if (!section) return rowObjectiveWork_; else return objectiveWork_;};
751  /// Return region as single array
752  inline double * solutionRegion() const
753  { return solution_;};
754  inline double * djRegion() const
755  { return dj_;};
756  inline double * lowerRegion() const
757  { return lower_;};
758  inline double * upperRegion() const
759  { return upper_;};
760  inline double * costRegion() const
761  { return cost_;};
762  inline Status getStatus(int sequence) const
763  {return static_cast<Status> (status_[sequence]&7);};
764  inline void setStatus(int sequence, Status status)
765  {
766    unsigned char & st_byte = status_[sequence];
767    st_byte &= ~7;
768    st_byte |= status;
769  };
770  /** Normally the first factorization does sparse coding because
771      the factorization could be singular.  This allows initial dense
772      factorization when it is known to be safe
773  */
774  void setInitialDenseFactorization(bool onOff);
775  bool  initialDenseFactorization() const;
776  /** Return sequence In or Out */
777  inline int sequenceIn() const
778  {return sequenceIn_;};
779  inline int sequenceOut() const
780  {return sequenceOut_;};
781  /** Set sequenceIn or Out */
782  inline void  setSequenceIn(int sequence)
783  { sequenceIn_=sequence;};
784  inline void  setSequenceOut(int sequence)
785  { sequenceOut_=sequence;};
786  /** Return direction In or Out */
787  inline int directionIn() const
788  {return directionIn_;};
789  inline int directionOut() const
790  {return directionOut_;};
791  /** Set directionIn or Out */
792  inline void  setDirectionIn(int direction)
793  { directionIn_=direction;};
794  inline void  setDirectionOut(int direction)
795  { directionOut_=direction;};
796  /// Value of Out variable
797  inline double valueOut() const
798  { return valueOut_;};
799  /// Returns 1 if sequence indicates column
800  inline int isColumn(int sequence) const
801  { return sequence<numberColumns_ ? 1 : 0;};
802  /// Returns sequence number within section
803  inline int sequenceWithin(int sequence) const
804  { return sequence<numberColumns_ ? sequence : sequence-numberColumns_;};
805  /// Return row or column values
806  inline double solution(int sequence)
807  { return solution_[sequence];};
808  /// Return address of row or column values
809  inline double & solutionAddress(int sequence)
810  { return solution_[sequence];};
811  inline double reducedCost(int sequence)
812   { return dj_[sequence];};
813  inline double & reducedCostAddress(int sequence)
814   { return dj_[sequence];};
815  inline double lower(int sequence)
816  { return lower_[sequence];};
817  /// Return address of row or column lower bound
818  inline double & lowerAddress(int sequence)
819  { return lower_[sequence];};
820  inline double upper(int sequence)
821  { return upper_[sequence];};
822  /// Return address of row or column upper bound
823  inline double & upperAddress(int sequence)
824  { return upper_[sequence];};
825  inline double cost(int sequence)
826  { return cost_[sequence];};
827  /// Return address of row or column cost
828  inline double & costAddress(int sequence)
829  { return cost_[sequence];};
830  /// Return original lower bound
831  inline double originalLower(int iSequence) const
832  { if (iSequence<numberColumns_) return columnLower_[iSequence]; else
833    return rowLower_[iSequence-numberColumns_];};
834  /// Return original lower bound
835  inline double originalUpper(int iSequence) const
836  { if (iSequence<numberColumns_) return columnUpper_[iSequence]; else
837    return rowUpper_[iSequence-numberColumns_];};
838  /// Theta (pivot change)
839  inline double theta() const
840  { return theta_;};
841  /// Return pointer to details of costs
842  inline ClpNonLinearCost * nonLinearCost() const
843  { return nonLinearCost_;};
844  //@}
845  /**@name status methods */
846  //@{
847  inline void setFakeBound(int sequence, FakeBound fakeBound)
848  {
849    unsigned char & st_byte = status_[sequence];
850    st_byte &= ~24;
851    st_byte |= fakeBound<<3;
852  };
853  inline FakeBound getFakeBound(int sequence) const
854  {return static_cast<FakeBound> ((status_[sequence]>>3)&3);};
855  inline void setRowStatus(int sequence, Status status)
856  {
857    unsigned char & st_byte = status_[sequence+numberColumns_];
858    st_byte &= ~7;
859    st_byte |= status;
860  };
861  inline Status getRowStatus(int sequence) const
862  {return static_cast<Status> (status_[sequence+numberColumns_]&7);};
863  inline void setColumnStatus(int sequence, Status status)
864  {
865    unsigned char & st_byte = status_[sequence];
866    st_byte &= ~7;
867    st_byte |= status;
868  };
869  inline Status getColumnStatus(int sequence) const
870  {return static_cast<Status> (status_[sequence]&7);};
871  inline void setPivoted( int sequence)
872  { status_[sequence] |= 32;};
873  inline void clearPivoted( int sequence)
874  { status_[sequence] &= ~32; };
875  inline bool pivoted(int sequence) const
876  {return (((status_[sequence]>>5)&1)!=0);};
877  /// To flag a variable (not inline to allow for column generation)
878  void setFlagged( int sequence);
879  inline void clearFlagged( int sequence)
880  {
881    status_[sequence] &= ~64;
882  };
883  inline bool flagged(int sequence) const
884  {return ((status_[sequence]&64)!=0);};
885  /// To say row active in primal pivot row choice
886  inline void setActive( int iRow)
887  {
888    status_[iRow] |= 128;
889  };
890  inline void clearActive( int iRow)
891  {
892    status_[iRow] &= ~128;
893  };
894  inline bool active(int iRow) const
895  {return ((status_[iRow]&128)!=0);};
896  /** Set up status array (can be used by OsiClp).
897      Also can be used to set up all slack basis */
898  void createStatus() ;
899  /** Sets up all slack basis and resets solution to
900      as it was after initial load or readMps */
901  void allSlackBasis(bool resetSolution=false);
902   
903  /// So we know when to be cautious
904  inline int lastBadIteration() const
905  {return lastBadIteration_;};
906  /// Progress flag - at present 0 bit says artificials out
907  inline int progressFlag() const
908  {return progressFlag_;};
909  /// Force re-factorization early
910  inline void forceFactorization(int value)
911  { forceFactorization_ = value;};
912  /// Raw objective value (so always minimize in primal)
913  inline double rawObjectiveValue() const
914  { return objectiveValue_;};
915   /// Compute objective value from solution and put in objectiveValue_
916  void computeObjectiveValue(bool useWorkingSolution=false);
917  /// Compute minimization objective value from internal solution without perturbation
918  double computeInternalObjectiveValue();
919  /** Number of extra rows.  These are ones which will be dynamically created
920      each iteration.  This is for GUB but may have other uses.
921  */
922  inline int numberExtraRows() const
923  { return numberExtraRows_;};
924  /** Maximum number of basic variables - can be more than number of rows if GUB
925  */
926  inline int maximumBasic() const
927  { return maximumBasic_;};
928  /// Create C++ lines to get to current state
929  void generateCpp( FILE * fp,bool defaultFactor=false);
930  /// Gets clean and emptyish factorization
931  ClpFactorization * getEmptyFactorization();
932  /// May delete or may make clean and emptyish factorization
933  void setEmptyFactorization();
934  //@}
935
936  ///@name Basis handling
937  // These are only to be used using startFinishOptions (ClpSimplexDual, ClpSimplexPrimal)
938  // *** At present only without scaling
939  // *** Slacks havve -1.0 element (so == row activity) - take care
940  ///Get a row of the tableau (slack part in slack if not NULL)
941  void getBInvARow(int row, double* z, double * slack=NULL);
942 
943  ///Get a row of the basis inverse
944  void getBInvRow(int row, double* z);
945 
946  ///Get a column of the tableau
947  void getBInvACol(int col, double* vec);
948 
949  ///Get a column of the basis inverse
950  void getBInvCol(int col, double* vec);
951 
952  /** Get basic indices (order of indices corresponds to the
953      order of elements in a vector retured by getBInvACol() and
954      getBInvCol()).
955  */
956  void getBasics(int* index);
957 
958  //@}
959    //-------------------------------------------------------------------------
960    /**@name Changing bounds on variables and constraints */
961    //@{
962       /** Set an objective function coefficient */
963       void setObjectiveCoefficient( int elementIndex, double elementValue );
964       /** Set an objective function coefficient */
965       inline void setObjCoeff( int elementIndex, double elementValue )
966       { setObjectiveCoefficient( elementIndex, elementValue);};
967
968      /** Set a single column lower bound<br>
969          Use -DBL_MAX for -infinity. */
970       void setColumnLower( int elementIndex, double elementValue );
971     
972      /** Set a single column upper bound<br>
973          Use DBL_MAX for infinity. */
974       void setColumnUpper( int elementIndex, double elementValue );
975
976      /** Set a single column lower and upper bound */
977      void setColumnBounds( int elementIndex,
978        double lower, double upper );
979
980      /** Set the bounds on a number of columns simultaneously<br>
981          The default implementation just invokes setColLower() and
982          setColUpper() over and over again.
983          @param indexFirst,indexLast pointers to the beginning and after the
984                 end of the array of the indices of the variables whose
985                 <em>either</em> bound changes
986          @param boundList the new lower/upper bound pairs for the variables
987      */
988      void setColumnSetBounds(const int* indexFirst,
989                                   const int* indexLast,
990                                   const double* boundList);
991     
992      /** Set a single column lower bound<br>
993          Use -DBL_MAX for -infinity. */
994       inline void setColLower( int elementIndex, double elementValue )
995       { setColumnLower(elementIndex, elementValue);};
996      /** Set a single column upper bound<br>
997          Use DBL_MAX for infinity. */
998       inline void setColUpper( int elementIndex, double elementValue )
999       { setColumnUpper(elementIndex, elementValue);};
1000
1001      /** Set a single column lower and upper bound */
1002      inline void setColBounds( int elementIndex,
1003        double lower, double upper )
1004       { setColumnBounds(elementIndex, lower, upper);};
1005
1006      /** Set the bounds on a number of columns simultaneously<br>
1007          @param indexFirst,indexLast pointers to the beginning and after the
1008                 end of the array of the indices of the variables whose
1009                 <em>either</em> bound changes
1010          @param boundList the new lower/upper bound pairs for the variables
1011      */
1012      inline void setColSetBounds(const int* indexFirst,
1013                                   const int* indexLast,
1014                                   const double* boundList)
1015      { setColumnSetBounds(indexFirst, indexLast, boundList);};
1016     
1017      /** Set a single row lower bound<br>
1018          Use -DBL_MAX for -infinity. */
1019      void setRowLower( int elementIndex, double elementValue );
1020     
1021      /** Set a single row upper bound<br>
1022          Use DBL_MAX for infinity. */
1023      void setRowUpper( int elementIndex, double elementValue ) ;
1024   
1025      /** Set a single row lower and upper bound */
1026      void setRowBounds( int elementIndex,
1027                                 double lower, double upper ) ;
1028   
1029      /** Set the bounds on a number of rows simultaneously<br>
1030          @param indexFirst,indexLast pointers to the beginning and after the
1031                 end of the array of the indices of the constraints whose
1032                 <em>either</em> bound changes
1033          @param boundList the new lower/upper bound pairs for the constraints
1034      */
1035      void setRowSetBounds(const int* indexFirst,
1036                                   const int* indexLast,
1037                                   const double* boundList);
1038   
1039    //@}
1040
1041////////////////// data //////////////////
1042protected:
1043
1044  /**@name data.  Many arrays have a row part and a column part.
1045   There is a single array with both - columns then rows and
1046   then normally two arrays pointing to rows and columns.  The
1047   single array is the owner of memory
1048  */
1049  //@{
1050  /// Worst column primal infeasibility
1051  double columnPrimalInfeasibility_;
1052  /// Worst row primal infeasibility
1053  double rowPrimalInfeasibility_;
1054  /// Sequence of worst (-1 if feasible)
1055  int columnPrimalSequence_;
1056  /// Sequence of worst (-1 if feasible)
1057  int rowPrimalSequence_;
1058  /// Worst column dual infeasibility
1059  double columnDualInfeasibility_;
1060  /// Worst row dual infeasibility
1061  double rowDualInfeasibility_;
1062  /// Sequence of worst (-1 if feasible)
1063  int columnDualSequence_;
1064  /// Sequence of worst (-1 if feasible)
1065  int rowDualSequence_;
1066  /// Primal tolerance needed to make dual feasible (<largeTolerance)
1067  double primalToleranceToGetOptimal_;
1068  /// Remaining largest dual infeasibility
1069  double remainingDualInfeasibility_;
1070  /// Large bound value (for complementarity etc)
1071  double largeValue_;
1072  /// Largest error on Ax-b
1073  double largestPrimalError_;
1074  /// Largest error on basic duals
1075  double largestDualError_;
1076  /// For computing whether to re-factorize
1077  double alphaAccuracy_;
1078  /// Dual bound
1079  double dualBound_;
1080  /// Alpha (pivot element)
1081  double alpha_;
1082  /// Theta (pivot change)
1083  double theta_;
1084  /// Lower Bound on In variable
1085  double lowerIn_;
1086  /// Value of In variable
1087  double valueIn_;
1088  /// Upper Bound on In variable
1089  double upperIn_;
1090  /// Reduced cost of In variable
1091  double dualIn_;
1092  /// Lower Bound on Out variable
1093  double lowerOut_;
1094  /// Value of Out variable
1095  double valueOut_;
1096  /// Upper Bound on Out variable
1097  double upperOut_;
1098  /// Infeasibility (dual) or ? (primal) of Out variable
1099  double dualOut_;
1100  /// Current dual tolerance for algorithm
1101  double dualTolerance_;
1102  /// Current primal tolerance for algorithm
1103  double primalTolerance_;
1104  /// Sum of dual infeasibilities
1105  double sumDualInfeasibilities_;
1106  /// Sum of primal infeasibilities
1107  double sumPrimalInfeasibilities_;
1108  /// Weight assigned to being infeasible in primal
1109  double infeasibilityCost_;
1110  /// Sum of Dual infeasibilities using tolerance based on error in duals
1111  double sumOfRelaxedDualInfeasibilities_;
1112  /// Sum of Primal infeasibilities using tolerance based on error in primals
1113  double sumOfRelaxedPrimalInfeasibilities_;
1114  /// Acceptable pivot value just after factorization
1115  double acceptablePivot_;
1116  /// Working copy of lower bounds (Owner of arrays below)
1117  double * lower_;
1118  /// Row lower bounds - working copy
1119  double * rowLowerWork_;
1120  /// Column lower bounds - working copy
1121  double * columnLowerWork_;
1122  /// Working copy of upper bounds (Owner of arrays below)
1123  double * upper_;
1124  /// Row upper bounds - working copy
1125  double * rowUpperWork_;
1126  /// Column upper bounds - working copy
1127  double * columnUpperWork_;
1128  /// Working copy of objective (Owner of arrays below)
1129  double * cost_;
1130  /// Row objective - working copy
1131  double * rowObjectiveWork_;
1132  /// Column objective - working copy
1133  double * objectiveWork_;
1134  /// Useful row length arrays
1135  CoinIndexedVector * rowArray_[6];
1136  /// Useful column length arrays
1137  CoinIndexedVector * columnArray_[6];
1138  /// Sequence of In variable
1139  int sequenceIn_;
1140  /// Direction of In, 1 going up, -1 going down, 0 not a clude
1141  int directionIn_;
1142  /// Sequence of Out variable
1143  int sequenceOut_;
1144  /// Direction of Out, 1 to upper bound, -1 to lower bound, 0 - superbasic
1145  int directionOut_;
1146  /// Pivot Row
1147  int pivotRow_;
1148  /// Last good iteration (immediately after a re-factorization)
1149  int lastGoodIteration_;
1150  /// Working copy of reduced costs (Owner of arrays below)
1151  double * dj_;
1152  /// Reduced costs of slacks not same as duals (or - duals)
1153  double * rowReducedCost_;
1154  /// Possible scaled reduced costs
1155  double * reducedCostWork_;
1156  /// Working copy of primal solution (Owner of arrays below)
1157  double * solution_;
1158  /// Row activities - working copy
1159  double * rowActivityWork_;
1160  /// Column activities - working copy
1161  double * columnActivityWork_;
1162  /// Auxiliary model
1163  ClpSimplex * auxiliaryModel_;
1164  /// Number of dual infeasibilities
1165  int numberDualInfeasibilities_;
1166  /// Number of dual infeasibilities (without free)
1167  int numberDualInfeasibilitiesWithoutFree_;
1168  /// Number of primal infeasibilities
1169  int numberPrimalInfeasibilities_;
1170  /// How many iterative refinements to do
1171  int numberRefinements_;
1172  /// dual row pivot choice
1173  ClpDualRowPivot * dualRowPivot_;
1174  /// primal column pivot choice
1175  ClpPrimalColumnPivot * primalColumnPivot_;
1176  /// Basic variables pivoting on which rows
1177  int * pivotVariable_;
1178  /// factorization
1179  ClpFactorization * factorization_;
1180  /// Saved version of solution
1181  double * savedSolution_;
1182  /// Number of times code has tentatively thought optimal
1183  int numberTimesOptimal_;
1184  /// Disaster handler
1185  ClpDisasterHandler * disasterArea_;
1186  /// If change has been made (first attempt at stopping looping)
1187  int changeMade_;
1188  /// Algorithm >0 == Primal, <0 == Dual
1189  int algorithm_;
1190  /** Now for some reliability aids
1191      This forces re-factorization early */
1192  int forceFactorization_;
1193  /** Perturbation:
1194      -50 to +50 - perturb by this power of ten (-6 sounds good)
1195      100 - auto perturb if takes too long (1.0e-6 largest nonzero)
1196      101 - we are perturbed
1197      102 - don't try perturbing again
1198      default is 100
1199  */
1200  int perturbation_;
1201  /// Saved status regions
1202  unsigned char * saveStatus_;
1203  /** Very wasteful way of dealing with infeasibilities in primal.
1204      However it will allow non-linearities and use of dual
1205      analysis.  If it doesn't work it can easily be replaced.
1206  */
1207  ClpNonLinearCost * nonLinearCost_;
1208  /// So we know when to be cautious
1209  int lastBadIteration_;
1210  /// So we know when to open up again
1211  int lastFlaggedIteration_;
1212  /// Can be used for count of fake bounds (dual) or fake costs (primal)
1213  int numberFake_;
1214  /// Can be used for count of changed costs (dual) or changed bounds (primal)
1215  int numberChanged_;
1216  /// Progress flag - at present 0 bit says artificials out, 1 free in
1217  int progressFlag_;
1218  /// First free/super-basic variable (-1 if none)
1219  int firstFree_;
1220  /** Number of extra rows.  These are ones which will be dynamically created
1221      each iteration.  This is for GUB but may have other uses.
1222  */
1223  int numberExtraRows_;
1224  /** Maximum number of basic variables - can be more than number of rows if GUB
1225  */
1226  int maximumBasic_;
1227  /** For advanced use.  When doing iterative solves things can get
1228      nasty so on values pass if incoming solution has largest
1229      infeasibility < incomingInfeasibility throw out variables
1230      from basis until largest infeasibility < allowedInfeasibility.
1231      if allowedInfeasibility>= incomingInfeasibility this is
1232      always possible altough you may end up with an all slack basis.
1233
1234      Defaults are 1.0,10.0
1235  */
1236  float incomingInfeasibility_;
1237  float allowedInfeasibility_;
1238  /// Automatic scaling of objective and rhs and bounds
1239  int automaticScale_;
1240  /// For dealing with all issues of cycling etc
1241  ClpSimplexProgress * progress_;
1242public:
1243  /// Spare int array for passing information [0]!=0 switches on
1244  mutable int spareIntArray_[4];
1245  /// Spare double array for passing information [0]!=0 switches on
1246  mutable double spareDoubleArray_[4];
1247protected:
1248  /// Allow OsiClp certain perks
1249  friend class OsiClpSolverInterface;
1250  //@}
1251};
1252//#############################################################################
1253/** A function that tests the methods in the ClpSimplex class. The
1254    only reason for it not to be a member method is that this way it doesn't
1255    have to be compiled into the library. And that's a gain, because the
1256    library should be compiled with optimization on, but this method should be
1257    compiled with debugging.
1258
1259    It also does some testing of ClpFactorization class
1260 */
1261void
1262ClpSimplexUnitTest(const std::string & mpsDir,
1263                   const std::string & netlibDir);
1264
1265
1266/// For saving extra information to see if looping.
1267class ClpSimplexProgress {
1268
1269public:
1270
1271
1272  /**@name Constructors and destructor and copy */
1273  //@{
1274  /// Default constructor
1275    ClpSimplexProgress (  );
1276
1277  /// Constructor from model
1278    ClpSimplexProgress ( ClpSimplex * model );
1279
1280  /// Copy constructor.
1281  ClpSimplexProgress(const ClpSimplexProgress &);
1282
1283  /// Assignment operator. This copies the data
1284    ClpSimplexProgress & operator=(const ClpSimplexProgress & rhs);
1285  /// Destructor
1286   ~ClpSimplexProgress (  );
1287  //@}
1288
1289  /**@name Check progress */
1290  //@{
1291  /** Returns -1 if okay, -n+1 (n number of times bad) if bad but action taken,
1292      >=0 if give up and use as problem status
1293  */
1294    int looping (  );
1295  /// Start check at beginning of whileIterating
1296  void startCheck();
1297  /// Returns cycle length in whileIterating
1298  int cycle(int in, int out,int wayIn,int wayOut); 
1299
1300  /// Returns previous objective (if -1) - current if (0)
1301  double lastObjective(int back=1) const;
1302  /// Set real primal infeasibility and move back
1303  void setInfeasibility(double value);
1304  /// Returns real primal infeasibility (if -1) - current if (0)
1305  double lastInfeasibility(int back=1) const;
1306  /// Modify objective e.g. if dual infeasible in dual
1307  void modifyObjective(double value);
1308  /// Returns previous iteration number (if -1) - current if (0)
1309  int lastIterationNumber(int back=1) const;
1310  /// clears all iteration numbers (to switch off panic)
1311  void clearIterationNumbers();
1312  /// Odd state
1313  inline void newOddState()
1314  { oddState_= - oddState_-1;};
1315  inline void endOddState()
1316  { oddState_=abs(oddState_);};
1317  inline void clearOddState() 
1318  { oddState_=0;};
1319  inline int oddState() const
1320  { return oddState_;};
1321  /// number of bad times
1322  inline int badTimes() const
1323  { return numberBadTimes_;};
1324  inline void clearBadTimes()
1325  { numberBadTimes_=0;};
1326
1327  //@}
1328  /**@name Data  */
1329#define CLP_PROGRESS 5
1330  //#define CLP_PROGRESS_WEIGHT 10
1331  //@{
1332  /// Objective values
1333  double objective_[CLP_PROGRESS];
1334  /// Sum of infeasibilities for algorithm
1335  double infeasibility_[CLP_PROGRESS];
1336  /// Sum of real primal infeasibilities for primal
1337  double realInfeasibility_[CLP_PROGRESS];
1338#ifdef CLP_PROGRESS_WEIGHT
1339  /// Objective values for weights
1340  double objectiveWeight_[CLP_PROGRESS_WEIGHT];
1341  /// Sum of infeasibilities for algorithm for weights
1342  double infeasibilityWeight_[CLP_PROGRESS_WEIGHT];
1343  /// Sum of real primal infeasibilities for primal for weights
1344  double realInfeasibilityWeight_[CLP_PROGRESS_WEIGHT];
1345  /// Drop  for weights
1346  double drop_;
1347  /// Best? for weights
1348  double best_;
1349#endif
1350  /// Initial weight for weights
1351  double initialWeight_;
1352#define CLP_CYCLE 12
1353  /// For cycle checking
1354  //double obj_[CLP_CYCLE];
1355  int in_[CLP_CYCLE];
1356  int out_[CLP_CYCLE];
1357  char way_[CLP_CYCLE];
1358  /// Pointer back to model so we can get information
1359  ClpSimplex * model_;
1360  /// Number of infeasibilities
1361  int numberInfeasibilities_[CLP_PROGRESS];
1362  /// Iteration number at which occurred
1363  int iterationNumber_[CLP_PROGRESS];
1364#ifdef CLP_PROGRESS_WEIGHT
1365  /// Number of infeasibilities for weights
1366  int numberInfeasibilitiesWeight_[CLP_PROGRESS_WEIGHT];
1367  /// Iteration number at which occurred for weights
1368  int iterationNumberWeight_[CLP_PROGRESS_WEIGHT];
1369#endif
1370  /// Number of times checked (so won't stop too early)
1371  int numberTimes_;
1372  /// Number of times it looked like loop
1373  int numberBadTimes_;
1374  /// If things are in an odd state
1375  int oddState_;
1376  //@}
1377};
1378// For Devex stuff
1379#define DEVEX_TRY_NORM 1.0e-4
1380#define DEVEX_ADD_ONE 1.0
1381#endif
Note: See TracBrowser for help on using the repository browser.