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

Last change on this file since 2030 was 2025, checked in by forrest, 6 years ago

mainly dantzig-wolfe - also Clp strong branching (rather than OsiClp?)

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