source: stable/1.11/Clp/src/ClpSimplex.hpp @ 1461

Last change on this file since 1461 was 1461, checked in by stefan, 11 years ago

fix compiler warnings declaration of XXX shadows a member of YYY; remove unnecessary include to avoid warnings from CoinFactorization?

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