-
Notifications
You must be signed in to change notification settings - Fork 85
/
ClpModel.hpp
1463 lines (1419 loc) · 45.2 KB
/
ClpModel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2002, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#ifndef ClpModel_H
#define ClpModel_H
#include "CoinUtilsConfig.h"
#include "ClpConfig.h"
#include <iostream>
#include <cassert>
#include <cmath>
#include <vector>
#include <string>
//#ifndef COIN_USE_CLP
//#define COIN_USE_CLP
//#endif
#include "ClpPackedMatrix.hpp"
#include "CoinMessageHandler.hpp"
#include "CoinHelperFunctions.hpp"
#include "CoinTypes.h"
#include "CoinFinite.hpp"
#include "CoinMpsIO.hpp"
#include "ClpModelParameters.hpp"
#include "ClpObjective.hpp"
#if defined(COINUTILS_HAS_GLPK) && defined(CLP_HAS_GLPK)
#include "glpk.h"
#endif
class ClpEventHandler;
/** This is the base class for Linear and quadratic Models
This knows nothing about the algorithm, but it seems to
have a reasonable amount of information
I would welcome suggestions for what should be in this and
how it relates to OsiSolverInterface. Some methods look
very similar.
*/
class CoinBuild;
class CoinModel;
class CLPLIB_EXPORT ClpModel {
public:
/**@name Constructors and destructor
Note - copy methods copy ALL data so can chew up memory
until other copy is freed
*/
//@{
/// Default constructor
ClpModel(bool emptyMessages = false);
/** Copy constructor. May scale depending on mode
-1 leave mode as is
0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 auto-but-as-initialSolve-in-bab
*/
ClpModel(const ClpModel &rhs, int scalingMode = -1);
/// Assignment operator. This copies the data
ClpModel &operator=(const ClpModel &rhs);
/** Subproblem constructor. A subset of whole model is created from the
row and column lists given. The new order is given by list order and
duplicates are allowed. Name and integer information can be dropped
*/
ClpModel(const ClpModel *wholeModel,
int numberRows, const int *whichRows,
int numberColumns, const int *whichColumns,
bool dropNames = true, bool dropIntegers = true);
/// Destructor
~ClpModel();
//@}
/**@name Load model - loads some stuff and initializes others */
//@{
/** Loads a problem (the constraints on the
rows are given by lower and upper bounds). If a pointer is 0 then the
following values are the default:
<ul>
<li> <code>colub</code>: all columns have upper bound infinity
<li> <code>collb</code>: all columns have lower bound 0
<li> <code>rowub</code>: all rows have upper bound infinity
<li> <code>rowlb</code>: all rows have lower bound -infinity
<li> <code>obj</code>: all variables have 0 objective coefficient
</ul>
*/
void loadProblem(const ClpMatrixBase &matrix,
const double *collb, const double *colub,
const double *obj,
const double *rowlb, const double *rowub,
const double *rowObjective = NULL);
void loadProblem(const CoinPackedMatrix &matrix,
const double *collb, const double *colub,
const double *obj,
const double *rowlb, const double *rowub,
const double *rowObjective = NULL);
/** Just like the other loadProblem() method except that the matrix is
given in a standard column major ordered format (without gaps). */
void loadProblem(const int numcols, const int numrows,
const CoinBigIndex *start, const int *index,
const double *value,
const double *collb, const double *colub,
const double *obj,
const double *rowlb, const double *rowub,
const double *rowObjective = NULL);
/** This loads a model from a coinModel object - returns number of errors.
modelObject not const as may be changed as part of process
If tryPlusMinusOne then will try adding as +-1 matrix
*/
int loadProblem(CoinModel &modelObject, bool tryPlusMinusOne = false);
/// This one is for after presolve to save memory
void loadProblem(const int numcols, const int numrows,
const CoinBigIndex *start, const int *index,
const double *value, const int *length,
const double *collb, const double *colub,
const double *obj,
const double *rowlb, const double *rowub,
const double *rowObjective = NULL);
/** Load up quadratic objective. This is stored as a CoinPackedMatrix */
void loadQuadraticObjective(const int numberColumns,
const CoinBigIndex *start,
const int *column, const double *element);
void loadQuadraticObjective(const CoinPackedMatrix &matrix);
/// Get rid of quadratic objective
void deleteQuadraticObjective();
/// This just loads up a row objective
void setRowObjective(const double *rowObjective);
/// Read an mps file from the given filename
int readMps(const char *filename,
bool keepNames = false,
bool ignoreErrors = false);
/** Modify model to deal with indicators.
startBigM are values in input.
If bigM > 0.0 then use that,
if < 0.0 use but try and improve */
void modifyByIndicators(double startBigM=COIN_DBL_MAX,
double bigM=1.0e7);
#if defined(COINUTILS_HAS_GLPK) && defined(CLP_HAS_GLPK)
/// Read GMPL files from the given filenames
int readGMPL(const char *filename, const char *dataName, bool keepNames = false,
glp_tran **coin_glp_tran = NULL, glp_prob **coin_glp_prob = NULL);
#endif
/// Copy in integer informations
void copyInIntegerInformation(const char *information);
/// Drop integer informations
void deleteIntegerInformation();
/** Set the index-th variable to be a continuous variable */
void setContinuous(int index);
/** Set the index-th variable to be an integer variable */
void setInteger(int index);
/** Return true if the index-th variable is an integer variable */
bool isInteger(int index) const;
/// Resizes rim part of model
void resize(int newNumberRows, int newNumberColumns);
/// Makes sure matrix dimensions are at least model dimensions
void synchronizeMatrix();
/// Deletes rows
void deleteRows(int number, const int *which);
/// Add one row
void addRow(int numberInRow, const int *columns,
const double *elements, double rowLower = -COIN_DBL_MAX,
double rowUpper = COIN_DBL_MAX);
/// Add rows
void addRows(int number, const double *rowLower,
const double *rowUpper,
const CoinBigIndex *rowStarts, const int *columns,
const double *elements);
/// Add rows
void addRows(int number, const double *rowLower,
const double *rowUpper,
const CoinBigIndex *rowStarts, const int *rowLengths,
const int *columns,
const double *elements);
#ifndef CLP_NO_VECTOR
void addRows(int number, const double *rowLower,
const double *rowUpper,
const CoinPackedVectorBase *const *rows);
#endif
/** Add rows from a build object.
If tryPlusMinusOne then will try adding as +-1 matrix
if no matrix exists.
Returns number of errors e.g. duplicates
*/
int addRows(const CoinBuild &buildObject, bool tryPlusMinusOne = false,
bool checkDuplicates = true);
/** Add rows from a model object. returns
-1 if object in bad state (i.e. has column information)
otherwise number of errors.
modelObject non const as can be regularized as part of build
If tryPlusMinusOne then will try adding as +-1 matrix
if no matrix exists.
*/
int addRows(CoinModel &modelObject, bool tryPlusMinusOne = false,
bool checkDuplicates = true);
/// Deletes columns
void deleteColumns(int number, const int *which);
/// Deletes rows AND columns (keeps old sizes)
void deleteRowsAndColumns(int numberRows, const int *whichRows,
int numberColumns, const int *whichColumns);
/// Add one column
void addColumn(int numberInColumn,
const int *rows,
const double *elements,
double columnLower = 0.0,
double columnUpper = COIN_DBL_MAX,
double objective = 0.0);
/// Add columns
void addColumns(int number, const double *columnLower,
const double *columnUpper,
const double *objective,
const CoinBigIndex *columnStarts, const int *rows,
const double *elements);
void addColumns(int number, const double *columnLower,
const double *columnUpper,
const double *objective,
const CoinBigIndex *columnStarts, const int *columnLengths,
const int *rows,
const double *elements);
#ifndef CLP_NO_VECTOR
void addColumns(int number, const double *columnLower,
const double *columnUpper,
const double *objective,
const CoinPackedVectorBase *const *columns);
#endif
/** Add columns from a build object
If tryPlusMinusOne then will try adding as +-1 matrix
if no matrix exists.
Returns number of errors e.g. duplicates
*/
int addColumns(const CoinBuild &buildObject, bool tryPlusMinusOne = false,
bool checkDuplicates = true);
/** Add columns from a model object. returns
-1 if object in bad state (i.e. has row information)
otherwise number of errors
modelObject non const as can be regularized as part of build
If tryPlusMinusOne then will try adding as +-1 matrix
if no matrix exists.
*/
int addColumns(CoinModel &modelObject, bool tryPlusMinusOne = false,
bool checkDuplicates = true);
/// Modify one element of a matrix
inline void modifyCoefficient(int row, int column, double newElement,
bool keepZero = false)
{
matrix_->modifyCoefficient(row, column, newElement, keepZero);
// Say matrix changed
whatsChanged_ &= ~15;
}
/** Change row lower bounds */
void chgRowLower(const double *rowLower);
/** Change row upper bounds */
void chgRowUpper(const double *rowUpper);
/** Change column lower bounds */
void chgColumnLower(const double *columnLower);
/** Change column upper bounds */
void chgColumnUpper(const double *columnUpper);
/** Change objective coefficients */
void chgObjCoefficients(const double *objIn);
/** Borrow model. This is so we don't have to copy large amounts
of data around. It assumes a derived class wants to overwrite
an empty model with a real one - while it does an algorithm */
void borrowModel(ClpModel &otherModel);
/** Return model - nulls all arrays so can be deleted safely
also updates any scalars */
void returnModel(ClpModel &otherModel);
/// Create empty ClpPackedMatrix
void createEmptyMatrix();
/** Really clean up matrix (if ClpPackedMatrix).
a) eliminate all duplicate AND small elements in matrix
b) remove all gaps and set extraGap_ and extraMajor_ to 0.0
c) reallocate arrays and make max lengths equal to lengths
d) orders elements
returns number of elements eliminated or -1 if not ClpPackedMatrix
*/
CoinBigIndex cleanMatrix(double threshold = 1.0e-20);
/// Copy contents - resizing if necessary - otherwise re-use memory
void copy(const ClpMatrixBase *from, ClpMatrixBase *&to);
#ifndef CLP_NO_STD
/// Drops names - makes lengthnames 0 and names empty
void dropNames();
/// Copies in names
void copyNames(const std::vector< std::string > &rowNames,
const std::vector< std::string > &columnNames);
/// Copies in Row names - modifies names first .. last-1
void copyRowNames(const std::vector< std::string > &rowNames, int first, int last);
/// Copies in Column names - modifies names first .. last-1
void copyColumnNames(const std::vector< std::string > &columnNames, int first, int last);
/// Copies in Row names - modifies names first .. last-1
void copyRowNames(const char *const *rowNames, int first, int last);
/// Copies in Column names - modifies names first .. last-1
void copyColumnNames(const char *const *columnNames, int first, int last);
/// Set name of row
void setRowName(int rowIndex, std::string &name);
/// Set name of col
void setColumnName(int colIndex, std::string &name);
#endif
/** Find a network subset.
rotate array should be numberRows. On output
-1 not in network
0 in network as is
1 in network with signs swapped
Returns number of network rows
*/
int findNetwork(char *rotate, double fractionNeeded = 0.75);
/** This creates a coinModel object
*/
CoinModel *createCoinModel() const;
/** Write the problem in MPS format to the specified file.
Row and column names may be null.
formatType is
<ul>
<li> 0 - normal
<li> 1 - extra accuracy
<li> 2 - IEEE hex
</ul>
Returns non-zero on I/O error
*/
int writeMps(const char *filename,
int formatType = 0, int numberAcross = 2,
double objSense = 0.0) const;
//@}
/**@name gets and sets */
//@{
/// Number of rows
inline int numberRows() const
{
return numberRows_;
}
inline int getNumRows() const
{
return numberRows_;
}
/// Number of columns
inline int getNumCols() const
{
return numberColumns_;
}
inline int numberColumns() const
{
return numberColumns_;
}
/// Primal tolerance to use
inline double primalTolerance() const
{
return dblParam_[ClpPrimalTolerance];
}
void setPrimalTolerance(double value);
/// Dual tolerance to use
inline double dualTolerance() const
{
return dblParam_[ClpDualTolerance];
}
void setDualTolerance(double value);
/// Primal objective limit
inline double primalObjectiveLimit() const
{
return dblParam_[ClpPrimalObjectiveLimit];
}
void setPrimalObjectiveLimit(double value);
/// Dual objective limit
inline double dualObjectiveLimit() const
{
return dblParam_[ClpDualObjectiveLimit];
}
void setDualObjectiveLimit(double value);
/// Objective offset
inline double objectiveOffset() const
{
return dblParam_[ClpObjOffset];
}
void setObjectiveOffset(double value);
/// Presolve tolerance to use
inline double presolveTolerance() const
{
return dblParam_[ClpPresolveTolerance];
}
#ifndef CLP_NO_STD
inline const std::string &problemName() const
{
return strParam_[ClpProbName];
}
#endif
/// Number of iterations
inline int numberIterations() const
{
return numberIterations_;
}
inline int getIterationCount() const
{
return numberIterations_;
}
inline void setNumberIterations(int numberIterationsNew)
{
numberIterations_ = numberIterationsNew;
}
/** Solve type - 1 simplex, 2 simplex interface, 3 Interior.*/
inline int solveType() const
{
return solveType_;
}
inline void setSolveType(int type)
{
solveType_ = type;
}
/// Maximum number of iterations
inline int maximumIterations() const
{
return intParam_[ClpMaxNumIteration];
}
void setMaximumIterations(int value);
/// Maximum time in seconds (from when set called)
inline double maximumSeconds() const
{
return dblParam_[ClpMaxSeconds];
}
void setMaximumSeconds(double value);
void setMaximumWallSeconds(double value);
/// Returns true if hit maximum iterations (or time)
bool hitMaximumIterations() const;
/** Status of problem:
-1 - unknown e.g. before solve or if postSolve says not optimal
0 - optimal
1 - primal infeasible
2 - dual infeasible
3 - stopped on iterations or time
4 - stopped due to errors
5 - stopped by event handler (virtual int ClpEventHandler::event())
*/
inline int status() const
{
return problemStatus_;
}
inline int problemStatus() const
{
return problemStatus_;
}
/// Set problem status
inline void setProblemStatus(int problemStatusNew)
{
problemStatus_ = problemStatusNew;
}
/** Secondary status of problem - may get extended
0 - none
1 - primal infeasible because dual limit reached OR (probably primal
infeasible but can't prove it - main status was 4)
2 - scaled problem optimal - unscaled problem has primal infeasibilities
3 - scaled problem optimal - unscaled problem has dual infeasibilities
4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities
5 - giving up in primal with flagged variables
6 - failed due to empty problem check
7 - postSolve says not optimal
8 - failed due to bad element check
9 - status was 3 and stopped on time
10 - status was 3 but stopped as primal feasible
11 - status was 1/2 from presolve found infeasible or unbounded
100 up - translation of enum from ClpEventHandler
*/
inline int secondaryStatus() const
{
return secondaryStatus_;
}
inline void setSecondaryStatus(int newstatus)
{
secondaryStatus_ = newstatus;
}
/// Are there a numerical difficulties?
inline bool isAbandoned() const
{
return problemStatus_ == 4;
}
/// Is optimality proven?
inline bool isProvenOptimal() const
{
return problemStatus_ == 0;
}
/// Is primal infeasiblity proven?
inline bool isProvenPrimalInfeasible() const
{
return problemStatus_ == 1;
}
/// Is dual infeasiblity proven?
inline bool isProvenDualInfeasible() const
{
return problemStatus_ == 2;
}
/// Is the given primal objective limit reached?
bool isPrimalObjectiveLimitReached() const;
/// Is the given dual objective limit reached?
bool isDualObjectiveLimitReached() const;
/// Iteration limit reached?
inline bool isIterationLimitReached() const
{
return problemStatus_ == 3;
}
/// Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore
inline double optimizationDirection() const
{
return optimizationDirection_;
}
inline double getObjSense() const
{
return optimizationDirection_;
}
void setOptimizationDirection(double value);
/// Primal row solution
inline double *primalRowSolution() const
{
return rowActivity_;
}
inline const double *getRowActivity() const
{
return rowActivity_;
}
/// Primal column solution
inline double *primalColumnSolution() const
{
return columnActivity_;
}
inline const double *getColSolution() const
{
return columnActivity_;
}
inline void setColSolution(const double *input)
{
memcpy(columnActivity_, input, numberColumns_ * sizeof(double));
}
/// Dual row solution
inline double *dualRowSolution() const
{
return dual_;
}
inline const double *getRowPrice() const
{
return dual_;
}
/// Reduced costs
inline double *dualColumnSolution() const
{
return reducedCost_;
}
inline const double *getReducedCost() const
{
return reducedCost_;
}
/// Row lower
inline double *rowLower() const
{
return rowLower_;
}
inline const double *getRowLower() const
{
return rowLower_;
}
/// Row upper
inline double *rowUpper() const
{
return rowUpper_;
}
inline const double *getRowUpper() const
{
return rowUpper_;
}
//-------------------------------------------------------------------------
/**@name Changing bounds on variables and constraints */
//@{
/** Set an objective function coefficient */
void setObjectiveCoefficient(int elementIndex, double elementValue);
/** Set an objective function coefficient */
inline void setObjCoeff(int elementIndex, double elementValue)
{
setObjectiveCoefficient(elementIndex, elementValue);
}
/** Set a single column lower bound<br>
Use -DBL_MAX for -infinity. */
void setColumnLower(int elementIndex, double elementValue);
/** Set a single column upper bound<br>
Use DBL_MAX for infinity. */
void setColumnUpper(int elementIndex, double elementValue);
/** Set a single column lower and upper bound */
void setColumnBounds(int elementIndex,
double lower, double upper);
/** Set the bounds on a number of columns simultaneously<br>
The default implementation just invokes setColLower() and
setColUpper() over and over again.
@param indexFirst,indexLast pointers to the beginning and after the
end of the array of the indices of the variables whose
<em>either</em> bound changes
@param boundList the new lower/upper bound pairs for the variables
*/
void setColumnSetBounds(const int *indexFirst,
const int *indexLast,
const double *boundList);
/** Set a single column lower bound<br>
Use -DBL_MAX for -infinity. */
inline void setColLower(int elementIndex, double elementValue)
{
setColumnLower(elementIndex, elementValue);
}
/** Set a single column upper bound<br>
Use DBL_MAX for infinity. */
inline void setColUpper(int elementIndex, double elementValue)
{
setColumnUpper(elementIndex, elementValue);
}
/** Set a single column lower and upper bound */
inline void setColBounds(int elementIndex,
double lower, double upper)
{
setColumnBounds(elementIndex, lower, upper);
}
/** Set the bounds on a number of columns simultaneously<br>
@param indexFirst,indexLast pointers to the beginning and after the
end of the array of the indices of the variables whose
<em>either</em> bound changes
@param boundList the new lower/upper bound pairs for the variables
*/
inline void setColSetBounds(const int *indexFirst,
const int *indexLast,
const double *boundList)
{
setColumnSetBounds(indexFirst, indexLast, boundList);
}
/** Set a single row lower bound<br>
Use -DBL_MAX for -infinity. */
void setRowLower(int elementIndex, double elementValue);
/** Set a single row upper bound<br>
Use DBL_MAX for infinity. */
void setRowUpper(int elementIndex, double elementValue);
/** Set a single row lower and upper bound */
void setRowBounds(int elementIndex,
double lower, double upper);
/** Set the bounds on a number of rows simultaneously<br>
@param indexFirst,indexLast pointers to the beginning and after the
end of the array of the indices of the constraints whose
<em>either</em> bound changes
@param boundList the new lower/upper bound pairs for the constraints
*/
void setRowSetBounds(const int *indexFirst,
const int *indexLast,
const double *boundList);
//@}
/// Scaling
inline const double *rowScale() const
{
return rowScale_;
}
inline const double *columnScale() const
{
return columnScale_;
}
inline const double *inverseRowScale() const
{
return inverseRowScale_;
}
inline const double *inverseColumnScale() const
{
return inverseColumnScale_;
}
inline double *mutableRowScale() const
{
return rowScale_;
}
inline double *mutableColumnScale() const
{
return columnScale_;
}
inline double *mutableInverseRowScale() const
{
return inverseRowScale_;
}
inline double *mutableInverseColumnScale() const
{
return inverseColumnScale_;
}
inline double *swapRowScale(double *newScale)
{
double *oldScale = rowScale_;
rowScale_ = newScale;
return oldScale;
}
void setRowScale(double *scale);
void setColumnScale(double *scale);
/// get rid of scaling etc
void cleanScalingEtc();
/// Scaling of objective
inline double objectiveScale() const
{
return objectiveScale_;
}
inline void setObjectiveScale(double value)
{
objectiveScale_ = value;
}
/// Scaling of rhs and bounds
inline double rhsScale() const
{
return rhsScale_;
}
inline void setRhsScale(double value)
{
rhsScale_ = value;
}
/// Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3 auto, 4 auto-but-as-initialSolve-in-bab
void scaling(int mode = 1);
/** If we constructed a "really" scaled model then this reverses the operation.
Quantities may not be exactly as they were before due to rounding errors */
void unscale();
/// Gets scalingFlag
inline int scalingFlag() const
{
return scalingFlag_;
}
/// Objective
inline double *objective() const
{
if (objective_) {
double offset;
return objective_->gradient(NULL, NULL, offset, false);
} else {
return NULL;
}
}
inline double *objective(const double *solution, double &offset, bool refresh = true) const
{
offset = 0.0;
if (objective_) {
return objective_->gradient(NULL, solution, offset, refresh);
} else {
return NULL;
}
}
inline const double *getObjCoefficients() const
{
if (objective_) {
double offset;
return objective_->gradient(NULL, NULL, offset, false);
} else {
return NULL;
}
}
/// Row Objective
inline double *rowObjective() const
{
return rowObjective_;
}
inline const double *getRowObjCoefficients() const
{
return rowObjective_;
}
/// Column Lower
inline double *columnLower() const
{
return columnLower_;
}
inline const double *getColLower() const
{
return columnLower_;
}
/// Column Upper
inline double *columnUpper() const
{
return columnUpper_;
}
inline const double *getColUpper() const
{
return columnUpper_;
}
/// Matrix (if not ClpPackedmatrix be careful about memory leak
inline CoinPackedMatrix *matrix() const
{
if (matrix_ == NULL)
return NULL;
else
return matrix_->getPackedMatrix();
}
/// Number of elements in matrix
inline CoinBigIndex getNumElements() const
{
return matrix_->getNumElements();
}
/** Small element value - elements less than this set to zero,
default is 1.0e-20 */
inline double getSmallElementValue() const
{
return smallElement_;
}
inline void setSmallElementValue(double value)
{
smallElement_ = value;
}
/// Row Matrix
inline ClpMatrixBase *rowCopy() const
{
return rowCopy_;
}
/// Set new row matrix
void setNewRowCopy(ClpMatrixBase *newCopy);
/// Clp Matrix
inline ClpMatrixBase *clpMatrix() const
{
return matrix_;
}
/// Scaled ClpPackedMatrix
inline ClpPackedMatrix *clpScaledMatrix() const
{
return scaledMatrix_;
}
/// Sets pointer to scaled ClpPackedMatrix
inline void setClpScaledMatrix(ClpPackedMatrix *scaledMatrix)
{
delete scaledMatrix_;
scaledMatrix_ = scaledMatrix;
}
/// Swaps pointer to scaled ClpPackedMatrix
inline ClpPackedMatrix *swapScaledMatrix(ClpPackedMatrix *scaledMatrix)
{
ClpPackedMatrix *oldMatrix = scaledMatrix_;
scaledMatrix_ = scaledMatrix;
return oldMatrix;
}
/** Replace Clp Matrix (current is not deleted unless told to
and new is used)
So up to user to delete current. This was used where
matrices were being rotated. ClpModel takes ownership.
*/
void replaceMatrix(ClpMatrixBase *matrix, bool deleteCurrent = false);
/** Replace Clp Matrix (current is not deleted unless told to
and new is used) So up to user to delete current. This was used where
matrices were being rotated. This version changes CoinPackedMatrix
to ClpPackedMatrix. ClpModel takes ownership.
*/
inline void replaceMatrix(CoinPackedMatrix *newmatrix,
bool deleteCurrent = false)
{
replaceMatrix(new ClpPackedMatrix(newmatrix), deleteCurrent);
}
/// Objective value
inline double objectiveValue() const
{
return objectiveValue_ * optimizationDirection_ - dblParam_[ClpObjOffset];
}
inline void setObjectiveValue(double value)
{
objectiveValue_ = (value + dblParam_[ClpObjOffset]) / optimizationDirection_;
}
inline double getObjValue() const
{
return objectiveValue_ * optimizationDirection_ - dblParam_[ClpObjOffset];
}
/// Integer information
inline char *integerInformation() const
{
return integerType_;
}
/** Infeasibility/unbounded ray (NULL returned if none/wrong)
Up to user to use delete [] on these arrays. */
double *infeasibilityRay(bool fullRay = false) const;
double *unboundedRay() const;
/// For advanced users - no need to delete - sign not changed
inline double *ray() const
{
return ray_;
}
/// just test if infeasibility or unbounded Ray exists
inline bool rayExists() const
{
return (ray_ != NULL);
}
/// just delete ray if exists
inline void deleteRay()
{
delete[] ray_;
ray_ = NULL;
}
/// Access internal ray storage. Users should call infeasibilityRay() or unboundedRay() instead.
inline const double *internalRay() const
{
return ray_;
}
/// See if status (i.e. basis) array exists (partly for OsiClp)
inline bool statusExists() const
{
return (status_ != NULL);
}
/// Return address of status (i.e. basis) array (char[numberRows+numberColumns])
inline unsigned char *statusArray() const
{
return status_;
}
/** Return copy of status (i.e. basis) array (char[numberRows+numberColumns]),
use delete [] */
unsigned char *statusCopy() const;
/// Copy in status (basis) vector
void copyinStatus(const unsigned char *statusArray);
/// User pointer for whatever reason
inline void setUserPointer(void *pointer)
{
userPointer_ = pointer;
}
inline void *getUserPointer() const
{
return userPointer_;
}
/// Trusted user pointer
inline void setTrustedUserPointer(ClpTrustedData *pointer)
{
trustedUserPointer_ = pointer;
}
inline ClpTrustedData *getTrustedUserPointer() const
{
return trustedUserPointer_;
}
/// What has changed in model (only for masochistic users)
inline int whatsChanged() const
{
return whatsChanged_;
}
inline void setWhatsChanged(int value)
{
whatsChanged_ = value;
}
/// Number of threads (not really being used)
inline int numberThreads() const
{
return numberThreads_;
}
inline void setNumberThreads(int value)
{
numberThreads_ = value;
}
//@}
/**@name Message handling */
//@{
/// Pass in Message handler (not deleted at end)
void passInMessageHandler(CoinMessageHandler *handler);
/// Pass in Message handler (not deleted at end) and return current
CoinMessageHandler *pushMessageHandler(CoinMessageHandler *handler,
bool &oldDefault);
/// back to previous message handler
void popMessageHandler(CoinMessageHandler *oldHandler, bool oldDefault);
/// Set language
void newLanguage(CoinMessages::Language language);
inline void setLanguage(CoinMessages::Language language)
{
newLanguage(language);
}
/// Overrides message handler with a default one
void setDefaultMessageHandler();
/// Return handler
inline CoinMessageHandler *messageHandler() const
{
return handler_;
}
/// Return messages
inline CoinMessages messages() const
{
return messages_;
}
/// Return pointer to messages
inline CoinMessages *messagesPointer()
{
return &messages_;
}
/// Return Coin messages
inline CoinMessages coinMessages() const
{
return coinMessages_;
}
/// Return pointer to Coin messages
inline CoinMessages *coinMessagesPointer()
{
return &coinMessages_;
}
/** Amount of print out:
0 - none
1 - just final
2 - just factorizations
3 - as 2 plus a bit more
4 - verbose