forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpress_interface.cc
2291 lines (2062 loc) · 82.5 KB
/
xpress_interface.cc
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 2019-2023 RTE
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Initial version of this code was provided by RTE
#include <algorithm>
#include <clocale>
#include <fstream>
#include <istream>
#include <limits>
#include <memory>
#include <mutex>
#include <string>
#include "absl/strings/str_format.h"
#include "ortools/base/logging.h"
#include "ortools/base/timer.h"
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/xpress/environment.h"
#define XPRS_INTEGER 'I'
#define XPRS_CONTINUOUS 'C'
// The argument to this macro is the invocation of a XPRS function that
// returns a status. If the function returns non-zero the macro aborts
// the program with an appropriate error message.
#define CHECK_STATUS(s) \
do { \
int const status_ = s; \
CHECK_EQ(0, status_); \
} while (0)
namespace operations_research {
std::string getSolverVersion(XPRSprob const& prob) {
// XPRS_VERSION gives the version number as MAJOR*100 + RELEASE.
// It does not include the build number.
int version;
if (!prob || XPRSgetintcontrol(prob, XPRS_VERSION, &version))
return "XPRESS library version unknown";
int const major = version / 100;
version -= major * 100;
int const release = version;
return absl::StrFormat("XPRESS library version %d.%02d", major, release);
}
// Apply the specified name=value setting to prob.
bool readParameter(XPRSprob const& prob, std::string const& name,
std::string const& value) {
// We cannot set empty parameters.
if (!value.size()) {
LOG(DFATAL) << "Empty value for parameter '" << name << "' in "
<< getSolverVersion(prob);
return false;
}
// Figure out the type of the control.
int id, type;
if (XPRSgetcontrolinfo(prob, name.c_str(), &id, &type) ||
type == XPRS_TYPE_NOTDEFINED) {
LOG(DFATAL) << "Unknown parameter '" << name << "' in "
<< getSolverVersion(prob);
return false;
}
// Depending on the type, parse the text in value and apply it.
std::stringstream v(value);
v.imbue(std::locale("C"));
switch (type) {
case XPRS_TYPE_INT: {
int i;
v >> i;
if (!v.eof()) {
LOG(DFATAL) << "Failed to parse value '" << value
<< "' for int parameter '" << name << "' in "
<< getSolverVersion(prob);
return false;
}
if (XPRSsetintcontrol(prob, id, i)) {
LOG(DFATAL) << "Failed to set int parameter '" << name << "' to "
<< value << " (" << i << ") in " << getSolverVersion(prob);
return false;
}
} break;
case XPRS_TYPE_INT64: {
XPRSint64 i;
v >> i;
if (!v.eof()) {
LOG(DFATAL) << "Failed to parse value '" << value
<< "' for int64_t parameter '" << name << "' in "
<< getSolverVersion(prob);
return false;
}
if (XPRSsetintcontrol64(prob, id, i)) {
LOG(DFATAL) << "Failed to set int64_t parameter '" << name << "' to "
<< value << " (" << i << ") in " << getSolverVersion(prob);
return false;
}
} break;
case XPRS_TYPE_DOUBLE: {
double d;
v >> d;
if (!v.eof()) {
LOG(DFATAL) << "Failed to parse value '" << value
<< "' for dbl parameter '" << name << "' in "
<< getSolverVersion(prob);
return false;
}
if (XPRSsetdblcontrol(prob, id, d)) {
LOG(DFATAL) << "Failed to set double parameter '" << name << "' to "
<< value << " (" << d << ") in " << getSolverVersion(prob);
return false;
}
} break;
default:
// Note that string parameters are not supported at the moment since
// we don't want to deal with potential encoding or escaping issues.
LOG(DFATAL) << "Unsupported parameter type " << type << " for parameter '"
<< name << "' in " << getSolverVersion(prob);
return false;
}
return true;
}
void printError(const XPRSprob& mLp, int line) {
char errmsg[512];
XPRSgetlasterror(mLp, errmsg);
VLOG(0) << absl::StrFormat("Function line %d did not execute correctly: %s\n",
line, errmsg);
exit(0);
}
void XPRS_CC XpressIntSolCallbackImpl(XPRSprob cbprob, void* cbdata);
/**********************************************************************************\
* Name: optimizermsg *
* Purpose: Display Optimizer error messages and warnings. *
* Arguments: const char *sMsg Message string *
* int nLen Message length *
* int nMsgLvl Message type *
* Return Value: None *
\**********************************************************************************/
void XPRS_CC optimizermsg(XPRSprob prob, void* data, const char* sMsg, int nLen,
int nMsgLvl);
int getnumcols(const XPRSprob& mLp) {
int nCols = 0;
XPRSgetintattrib(mLp, XPRS_COLS, &nCols);
return nCols;
}
int getnumrows(const XPRSprob& mLp) {
int nRows = 0;
XPRSgetintattrib(mLp, XPRS_ROWS, &nRows);
return nRows;
}
int getitcnt(const XPRSprob& mLp) {
int nIters = 0;
XPRSgetintattrib(mLp, XPRS_SIMPLEXITER, &nIters);
return nIters;
}
int getnodecnt(const XPRSprob& mLp) {
int nNodes = 0;
XPRSgetintattrib(mLp, XPRS_NODES, &nNodes);
return nNodes;
}
int setobjoffset(const XPRSprob& mLp, double value) {
// TODO detect xpress version
static int indexes[1] = {-1};
double values[1] = {-value};
XPRSchgobj(mLp, 1, indexes, values);
return 0;
}
void addhint(const XPRSprob& mLp, int length, const double solval[],
const int colind[]) {
// The OR-Tools API does not allow setting a name for the solution
// passing NULL to XPRESS will have it generate a unique ID for the solution
if (int status = XPRSaddmipsol(mLp, length, solval, colind, NULL)) {
LOG(WARNING) << "Failed to set solution hint.";
}
}
enum CUSTOM_INTERRUPT_REASON { CALLBACK_EXCEPTION = 0 };
void interruptXPRESS(XPRSprob& xprsProb, CUSTOM_INTERRUPT_REASON reason) {
// Reason values below 1000 are reserved by XPRESS
XPRSinterrupt(xprsProb, 1000 + reason);
}
enum XPRS_BASIS_STATUS {
XPRS_AT_LOWER = 0,
XPRS_BASIC = 1,
XPRS_AT_UPPER = 2,
XPRS_FREE_SUPER = 3
};
// In case we need to return a double but don't have a value for that
// we just return a NaN.
#if !defined(XPRS_NAN)
#define XPRS_NAN std::numeric_limits<double>::quiet_NaN()
#endif
using std::unique_ptr;
class XpressMPCallbackContext : public MPCallbackContext {
friend class XpressInterface;
public:
XpressMPCallbackContext(XPRSprob* xprsprob, MPCallbackEvent event,
int num_nodes)
: xprsprob_(xprsprob),
event_(event),
num_nodes_(num_nodes),
variable_values_(0) {};
// Implementation of the interface.
MPCallbackEvent Event() override { return event_; };
bool CanQueryVariableValues() override;
double VariableValue(const MPVariable* variable) override;
void AddCut(const LinearRange& cutting_plane) override {
LOG(WARNING) << "AddCut is not implemented yet in XPRESS interface";
};
void AddLazyConstraint(const LinearRange& lazy_constraint) override {
LOG(WARNING)
<< "AddLazyConstraint is not implemented yet in XPRESS interface";
};
double SuggestSolution(
const absl::flat_hash_map<const MPVariable*, double>& solution) override;
int64_t NumExploredNodes() override { return num_nodes_; };
// Call this method to update the internal state of the callback context
// before passing it to MPCallback::RunCallback().
// Returns true if the internal state has changed.
bool UpdateFromXpressState(XPRSprob cbprob);
private:
XPRSprob* xprsprob_;
MPCallbackEvent event_;
std::vector<double>
variable_values_; // same order as MPVariable* elements in MPSolver
int num_nodes_;
};
// Wraps the MPCallback in order to catch and store exceptions
class MPCallbackWrapper {
public:
explicit MPCallbackWrapper(MPCallback* callback) : callback_(callback) {};
MPCallback* GetCallback() const { return callback_; }
// Since our (C++) call-back functions are called from the XPRESS (C) code,
// exceptions thrown in our call-back code are not caught by XPRESS.
// We have to catch them, interrupt XPRESS, and log them after XPRESS is
// effectively interrupted (ie after solve).
void CatchException(XPRSprob cbprob) {
exceptions_mutex_.lock();
caught_exceptions_.push_back(std::current_exception());
interruptXPRESS(cbprob, CALLBACK_EXCEPTION);
exceptions_mutex_.unlock();
}
void LogCaughtExceptions() {
exceptions_mutex_.lock();
for (const std::exception_ptr& ex : caught_exceptions_) {
try {
std::rethrow_exception(ex);
} catch (std::exception& ex) {
// We don't want the interface to throw exceptions, plus it causes
// SWIG issues in Java & Python. Instead, we'll only log them.
// (The use cases where the user has to raise an exception inside their
// call-back does not seem to be frequent, anyway.)
LOG(ERROR) << "Caught exception during user-defined call-back: "
<< ex.what();
}
}
caught_exceptions_.clear();
exceptions_mutex_.unlock();
};
private:
MPCallback* callback_;
std::vector<std::exception_ptr> caught_exceptions_;
std::mutex exceptions_mutex_;
};
// For a model that is extracted to an instance of this class there is a
// 1:1 correspondence between MPVariable instances and XPRESS columns: the
// index of an extracted variable is the column index in the XPRESS model.
// Similar for instances of MPConstraint: the index of the constraint in
// the model is the row index in the XPRESS model.
class XpressInterface : public MPSolverInterface {
public:
// NOTE: 'mip' specifies the type of the problem (either continuous or
// mixed integer). This type is fixed for the lifetime of the
// instance. There are no dynamic changes to the model type.
explicit XpressInterface(MPSolver* solver, bool mip);
~XpressInterface() override;
// Sets the optimization direction (min/max).
void SetOptimizationDirection(bool maximize) override;
// ----- Solve -----
// Solve the problem using the parameter values specified.
MPSolver::ResultStatus Solve(MPSolverParameters const& param) override;
// Writes the model.
void Write(const std::string& filename) override;
// ----- Model modifications and extraction -----
// Resets extracted model
void Reset() override;
void SetVariableBounds(int var_index, double lb, double ub) override;
void SetVariableInteger(int var_index, bool integer) override;
void SetConstraintBounds(int row_index, double lb, double ub) override;
void AddRowConstraint(MPConstraint* ct) override;
void AddVariable(MPVariable* var) override;
void SetCoefficient(MPConstraint* constraint, MPVariable const* variable,
double new_value, double old_value) override;
// Clear a constraint from all its terms.
void ClearConstraint(MPConstraint* constraint) override;
// Change a coefficient in the linear objective
void SetObjectiveCoefficient(MPVariable const* variable,
double coefficient) override;
// Change the constant term in the linear objective.
void SetObjectiveOffset(double value) override;
// Clear the objective from all its terms.
void ClearObjective() override;
// ------ Query statistics on the solution and the solve ------
// Number of simplex iterations
virtual int64_t iterations() const;
// Number of branch-and-bound nodes. Only available for discrete problems.
virtual int64_t nodes() const;
// Returns the basis status of a row.
MPSolver::BasisStatus row_status(int constraint_index) const override;
// Returns the basis status of a column.
MPSolver::BasisStatus column_status(int variable_index) const override;
// ----- Misc -----
// Query problem type.
// Remember that problem type is a static property that is set
// in the constructor and never changed.
bool IsContinuous() const override { return IsLP(); }
bool IsLP() const override { return !mMip; }
bool IsMIP() const override { return mMip; }
void SetStartingLpBasis(
const std::vector<MPSolver::BasisStatus>& variable_statuses,
const std::vector<MPSolver::BasisStatus>& constraint_statuses) override;
void ExtractNewVariables() override;
void ExtractNewConstraints() override;
void ExtractObjective() override;
std::string SolverVersion() const override;
void* underlying_solver() override { return reinterpret_cast<void*>(mLp); }
double ComputeExactConditionNumber() const override {
if (!IsContinuous()) {
LOG(DFATAL) << "ComputeExactConditionNumber not implemented for"
<< " XPRESS_MIXED_INTEGER_PROGRAMMING";
return 0.0;
}
// TODO(user): Not yet working.
LOG(DFATAL) << "ComputeExactConditionNumber not implemented for"
<< " XPRESS_LINEAR_PROGRAMMING";
return 0.0;
}
void SetCallback(MPCallback* mp_callback) override;
bool SupportsCallbacks() const override { return true; }
bool InterruptSolve() override {
if (mLp) XPRSinterrupt(mLp, XPRS_STOP_USER);
return true;
}
protected:
// Set all parameters in the underlying solver.
void SetParameters(MPSolverParameters const& param) override;
// Set each parameter in the underlying solver.
void SetRelativeMipGap(double value) override;
void SetPrimalTolerance(double value) override;
void SetDualTolerance(double value) override;
void SetPresolveMode(int value) override;
void SetScalingMode(int value) override;
void SetLpAlgorithm(int value) override;
virtual bool ReadParameterFile(std::string const& filename);
virtual std::string ValidFileExtensionForParameterFile() const;
private:
// Mark modeling object "out of sync". This implicitly invalidates
// solution information as well. It is the counterpart of
// MPSolverInterface::InvalidateSolutionSynchronization
void InvalidateModelSynchronization() {
mCstat.clear();
mRstat.clear();
sync_status_ = MUST_RELOAD;
}
// Adds a new feasible, infeasible or partial MIP solution for the problem to
// the Optimizer. The hint is read in the MPSolver where the user set it using
// SetHint()
void AddSolutionHintToOptimizer();
bool readParameters(std::istream& is, char sep);
private:
XPRSprob mLp;
bool const mMip;
// Incremental extraction.
// Without incremental extraction we have to re-extract the model every
// time we perform a solve. Due to the way the Reset() function is
// implemented, this will lose MIP start or basis information from a
// previous solve. On the other hand, if there is a significant changes
// to the model then just re-extracting everything is usually faster than
// keeping the low-level modeling object in sync with the high-level
// variables/constraints.
// Note that incremental extraction is particularly expensive in function
// ExtractNewVariables() since there we must scan _all_ old constraints
// and update them with respect to the new variables.
bool const supportIncrementalExtraction;
// Use slow and immediate updates or try to do bulk updates.
// For many updates to the model we have the option to either perform
// the update immediately with a potentially slow operation or to
// just mark the low-level modeling object out of sync and re-extract
// the model later.
enum SlowUpdates {
SlowSetCoefficient = 0x0001,
SlowClearConstraint = 0x0002,
SlowSetObjectiveCoefficient = 0x0004,
SlowClearObjective = 0x0008,
SlowSetConstraintBounds = 0x0010,
SlowSetVariableInteger = 0x0020,
SlowSetVariableBounds = 0x0040,
SlowUpdatesAll = 0xffff
} const slowUpdates;
// XPRESS has no method to query the basis status of a single variable.
// Hence, we query the status only once and cache the array. This is
// much faster in case the basis status of more than one row/column
// is required.
// TODO
std::vector<int> mutable mCstat;
std::vector<int> mutable mRstat;
std::vector<int> mutable initial_variables_basis_status_;
std::vector<int> mutable initial_constraint_basis_status_;
// Setup the right-hand side of a constraint from its lower and upper bound.
static void MakeRhs(double lb, double ub, double& rhs, char& sense,
double& range);
std::map<std::string, int>& mapStringControls_;
std::map<std::string, int>& mapDoubleControls_;
std::map<std::string, int>& mapIntegerControls_;
std::map<std::string, int>& mapInteger64Controls_;
bool SetSolverSpecificParametersAsString(
const std::string& parameters) override;
MPCallback* callback_ = nullptr;
};
// Transform MPSolver basis status to XPRESS status
static int MPSolverToXpressBasisStatus(
MPSolver::BasisStatus mpsolver_basis_status);
// Transform XPRESS basis status to MPSolver basis status.
static MPSolver::BasisStatus XpressToMPSolverBasisStatus(
int xpress_basis_status);
static std::map<std::string, int>& getMapStringControls() {
static std::map<std::string, int> mapControls = {
{"MPSRHSNAME", XPRS_MPSRHSNAME},
{"MPSOBJNAME", XPRS_MPSOBJNAME},
{"MPSRANGENAME", XPRS_MPSRANGENAME},
{"MPSBOUNDNAME", XPRS_MPSBOUNDNAME},
{"OUTPUTMASK", XPRS_OUTPUTMASK},
{"TUNERMETHODFILE", XPRS_TUNERMETHODFILE},
{"TUNEROUTPUTPATH", XPRS_TUNEROUTPUTPATH},
{"TUNERSESSIONNAME", XPRS_TUNERSESSIONNAME},
{"COMPUTEEXECSERVICE", XPRS_COMPUTEEXECSERVICE},
};
return mapControls;
}
static std::map<std::string, int>& getMapDoubleControls() {
static std::map<std::string, int> mapControls = {
{"MAXCUTTIME", XPRS_MAXCUTTIME},
{"MAXSTALLTIME", XPRS_MAXSTALLTIME},
{"TUNERMAXTIME", XPRS_TUNERMAXTIME},
{"MATRIXTOL", XPRS_MATRIXTOL},
{"PIVOTTOL", XPRS_PIVOTTOL},
{"FEASTOL", XPRS_FEASTOL},
{"OUTPUTTOL", XPRS_OUTPUTTOL},
{"SOSREFTOL", XPRS_SOSREFTOL},
{"OPTIMALITYTOL", XPRS_OPTIMALITYTOL},
{"ETATOL", XPRS_ETATOL},
{"RELPIVOTTOL", XPRS_RELPIVOTTOL},
{"MIPTOL", XPRS_MIPTOL},
{"MIPTOLTARGET", XPRS_MIPTOLTARGET},
{"BARPERTURB", XPRS_BARPERTURB},
{"MIPADDCUTOFF", XPRS_MIPADDCUTOFF},
{"MIPABSCUTOFF", XPRS_MIPABSCUTOFF},
{"MIPRELCUTOFF", XPRS_MIPRELCUTOFF},
{"PSEUDOCOST", XPRS_PSEUDOCOST},
{"PENALTY", XPRS_PENALTY},
{"BIGM", XPRS_BIGM},
{"MIPABSSTOP", XPRS_MIPABSSTOP},
{"MIPRELSTOP", XPRS_MIPRELSTOP},
{"CROSSOVERACCURACYTOL", XPRS_CROSSOVERACCURACYTOL},
{"PRIMALPERTURB", XPRS_PRIMALPERTURB},
{"DUALPERTURB", XPRS_DUALPERTURB},
{"BAROBJSCALE", XPRS_BAROBJSCALE},
{"BARRHSSCALE", XPRS_BARRHSSCALE},
{"CHOLESKYTOL", XPRS_CHOLESKYTOL},
{"BARGAPSTOP", XPRS_BARGAPSTOP},
{"BARDUALSTOP", XPRS_BARDUALSTOP},
{"BARPRIMALSTOP", XPRS_BARPRIMALSTOP},
{"BARSTEPSTOP", XPRS_BARSTEPSTOP},
{"ELIMTOL", XPRS_ELIMTOL},
{"MARKOWITZTOL", XPRS_MARKOWITZTOL},
{"MIPABSGAPNOTIFY", XPRS_MIPABSGAPNOTIFY},
{"MIPRELGAPNOTIFY", XPRS_MIPRELGAPNOTIFY},
{"BARLARGEBOUND", XPRS_BARLARGEBOUND},
{"PPFACTOR", XPRS_PPFACTOR},
{"REPAIRINDEFINITEQMAX", XPRS_REPAIRINDEFINITEQMAX},
{"BARGAPTARGET", XPRS_BARGAPTARGET},
{"DUMMYCONTROL", XPRS_DUMMYCONTROL},
{"BARSTARTWEIGHT", XPRS_BARSTARTWEIGHT},
{"BARFREESCALE", XPRS_BARFREESCALE},
{"SBEFFORT", XPRS_SBEFFORT},
{"HEURDIVERANDOMIZE", XPRS_HEURDIVERANDOMIZE},
{"HEURSEARCHEFFORT", XPRS_HEURSEARCHEFFORT},
{"CUTFACTOR", XPRS_CUTFACTOR},
{"EIGENVALUETOL", XPRS_EIGENVALUETOL},
{"INDLINBIGM", XPRS_INDLINBIGM},
{"TREEMEMORYSAVINGTARGET", XPRS_TREEMEMORYSAVINGTARGET},
{"INDPRELINBIGM", XPRS_INDPRELINBIGM},
{"RELAXTREEMEMORYLIMIT", XPRS_RELAXTREEMEMORYLIMIT},
{"MIPABSGAPNOTIFYOBJ", XPRS_MIPABSGAPNOTIFYOBJ},
{"MIPABSGAPNOTIFYBOUND", XPRS_MIPABSGAPNOTIFYBOUND},
{"PRESOLVEMAXGROW", XPRS_PRESOLVEMAXGROW},
{"HEURSEARCHTARGETSIZE", XPRS_HEURSEARCHTARGETSIZE},
{"CROSSOVERRELPIVOTTOL", XPRS_CROSSOVERRELPIVOTTOL},
{"CROSSOVERRELPIVOTTOLSAFE", XPRS_CROSSOVERRELPIVOTTOLSAFE},
{"DETLOGFREQ", XPRS_DETLOGFREQ},
{"MAXIMPLIEDBOUND", XPRS_MAXIMPLIEDBOUND},
{"FEASTOLTARGET", XPRS_FEASTOLTARGET},
{"OPTIMALITYTOLTARGET", XPRS_OPTIMALITYTOLTARGET},
{"PRECOMPONENTSEFFORT", XPRS_PRECOMPONENTSEFFORT},
{"LPLOGDELAY", XPRS_LPLOGDELAY},
{"HEURDIVEITERLIMIT", XPRS_HEURDIVEITERLIMIT},
{"BARKERNEL", XPRS_BARKERNEL},
{"FEASTOLPERTURB", XPRS_FEASTOLPERTURB},
{"CROSSOVERFEASWEIGHT", XPRS_CROSSOVERFEASWEIGHT},
{"LUPIVOTTOL", XPRS_LUPIVOTTOL},
{"MIPRESTARTGAPTHRESHOLD", XPRS_MIPRESTARTGAPTHRESHOLD},
{"NODEPROBINGEFFORT", XPRS_NODEPROBINGEFFORT},
{"INPUTTOL", XPRS_INPUTTOL},
{"MIPRESTARTFACTOR", XPRS_MIPRESTARTFACTOR},
{"BAROBJPERTURB", XPRS_BAROBJPERTURB},
{"CPIALPHA", XPRS_CPIALPHA},
{"GLOBALBOUNDINGBOX", XPRS_GLOBALBOUNDINGBOX},
{"TIMELIMIT", XPRS_TIMELIMIT},
{"SOLTIMELIMIT", XPRS_SOLTIMELIMIT},
{"REPAIRINFEASTIMELIMIT", XPRS_REPAIRINFEASTIMELIMIT},
};
return mapControls;
}
static std::map<std::string, int>& getMapIntControls() {
static std::map<std::string, int> mapControls = {
{"EXTRAROWS", XPRS_EXTRAROWS},
{"EXTRACOLS", XPRS_EXTRACOLS},
{"LPITERLIMIT", XPRS_LPITERLIMIT},
{"LPLOG", XPRS_LPLOG},
{"SCALING", XPRS_SCALING},
{"PRESOLVE", XPRS_PRESOLVE},
{"CRASH", XPRS_CRASH},
{"PRICINGALG", XPRS_PRICINGALG},
{"INVERTFREQ", XPRS_INVERTFREQ},
{"INVERTMIN", XPRS_INVERTMIN},
{"MAXNODE", XPRS_MAXNODE},
{"MAXTIME", XPRS_MAXTIME},
{"MAXMIPSOL", XPRS_MAXMIPSOL},
{"SIFTPASSES", XPRS_SIFTPASSES},
{"DEFAULTALG", XPRS_DEFAULTALG},
{"VARSELECTION", XPRS_VARSELECTION},
{"NODESELECTION", XPRS_NODESELECTION},
{"BACKTRACK", XPRS_BACKTRACK},
{"MIPLOG", XPRS_MIPLOG},
{"KEEPNROWS", XPRS_KEEPNROWS},
{"MPSECHO", XPRS_MPSECHO},
{"MAXPAGELINES", XPRS_MAXPAGELINES},
{"OUTPUTLOG", XPRS_OUTPUTLOG},
{"BARSOLUTION", XPRS_BARSOLUTION},
{"CACHESIZE", XPRS_CACHESIZE},
{"CROSSOVER", XPRS_CROSSOVER},
{"BARITERLIMIT", XPRS_BARITERLIMIT},
{"CHOLESKYALG", XPRS_CHOLESKYALG},
{"BAROUTPUT", XPRS_BAROUTPUT},
{"EXTRAMIPENTS", XPRS_EXTRAMIPENTS},
{"REFACTOR", XPRS_REFACTOR},
{"BARTHREADS", XPRS_BARTHREADS},
{"KEEPBASIS", XPRS_KEEPBASIS},
{"CROSSOVEROPS", XPRS_CROSSOVEROPS},
{"VERSION", XPRS_VERSION},
{"CROSSOVERTHREADS", XPRS_CROSSOVERTHREADS},
{"BIGMMETHOD", XPRS_BIGMMETHOD},
{"MPSNAMELENGTH", XPRS_MPSNAMELENGTH},
{"ELIMFILLIN", XPRS_ELIMFILLIN},
{"PRESOLVEOPS", XPRS_PRESOLVEOPS},
{"MIPPRESOLVE", XPRS_MIPPRESOLVE},
{"MIPTHREADS", XPRS_MIPTHREADS},
{"BARORDER", XPRS_BARORDER},
{"BREADTHFIRST", XPRS_BREADTHFIRST},
{"AUTOPERTURB", XPRS_AUTOPERTURB},
{"DENSECOLLIMIT", XPRS_DENSECOLLIMIT},
{"CALLBACKFROMMASTERTHREAD", XPRS_CALLBACKFROMMASTERTHREAD},
{"MAXMCOEFFBUFFERELEMS", XPRS_MAXMCOEFFBUFFERELEMS},
{"REFINEOPS", XPRS_REFINEOPS},
{"LPREFINEITERLIMIT", XPRS_LPREFINEITERLIMIT},
{"MIPREFINEITERLIMIT", XPRS_MIPREFINEITERLIMIT},
{"DUALIZEOPS", XPRS_DUALIZEOPS},
{"CROSSOVERITERLIMIT", XPRS_CROSSOVERITERLIMIT},
{"PREBASISRED", XPRS_PREBASISRED},
{"PRESORT", XPRS_PRESORT},
{"PREPERMUTE", XPRS_PREPERMUTE},
{"PREPERMUTESEED", XPRS_PREPERMUTESEED},
{"MAXMEMORYSOFT", XPRS_MAXMEMORYSOFT},
{"CUTFREQ", XPRS_CUTFREQ},
{"SYMSELECT", XPRS_SYMSELECT},
{"SYMMETRY", XPRS_SYMMETRY},
{"MAXMEMORYHARD", XPRS_MAXMEMORYHARD},
{"MIQCPALG", XPRS_MIQCPALG},
{"QCCUTS", XPRS_QCCUTS},
{"QCROOTALG", XPRS_QCROOTALG},
{"PRECONVERTSEPARABLE", XPRS_PRECONVERTSEPARABLE},
{"ALGAFTERNETWORK", XPRS_ALGAFTERNETWORK},
{"TRACE", XPRS_TRACE},
{"MAXIIS", XPRS_MAXIIS},
{"CPUTIME", XPRS_CPUTIME},
{"COVERCUTS", XPRS_COVERCUTS},
{"GOMCUTS", XPRS_GOMCUTS},
{"LPFOLDING", XPRS_LPFOLDING},
{"MPSFORMAT", XPRS_MPSFORMAT},
{"CUTSTRATEGY", XPRS_CUTSTRATEGY},
{"CUTDEPTH", XPRS_CUTDEPTH},
{"TREECOVERCUTS", XPRS_TREECOVERCUTS},
{"TREEGOMCUTS", XPRS_TREEGOMCUTS},
{"CUTSELECT", XPRS_CUTSELECT},
{"TREECUTSELECT", XPRS_TREECUTSELECT},
{"DUALIZE", XPRS_DUALIZE},
{"DUALGRADIENT", XPRS_DUALGRADIENT},
{"SBITERLIMIT", XPRS_SBITERLIMIT},
{"SBBEST", XPRS_SBBEST},
{"BARINDEFLIMIT", XPRS_BARINDEFLIMIT},
{"HEURFREQ", XPRS_HEURFREQ},
{"HEURDEPTH", XPRS_HEURDEPTH},
{"HEURMAXSOL", XPRS_HEURMAXSOL},
{"HEURNODES", XPRS_HEURNODES},
{"LNPBEST", XPRS_LNPBEST},
{"LNPITERLIMIT", XPRS_LNPITERLIMIT},
{"BRANCHCHOICE", XPRS_BRANCHCHOICE},
{"BARREGULARIZE", XPRS_BARREGULARIZE},
{"SBSELECT", XPRS_SBSELECT},
{"LOCALCHOICE", XPRS_LOCALCHOICE},
{"LOCALBACKTRACK", XPRS_LOCALBACKTRACK},
{"DUALSTRATEGY", XPRS_DUALSTRATEGY},
{"L1CACHE", XPRS_L1CACHE},
{"HEURDIVESTRATEGY", XPRS_HEURDIVESTRATEGY},
{"HEURSELECT", XPRS_HEURSELECT},
{"BARSTART", XPRS_BARSTART},
{"PRESOLVEPASSES", XPRS_PRESOLVEPASSES},
{"BARNUMSTABILITY", XPRS_BARNUMSTABILITY},
{"BARORDERTHREADS", XPRS_BARORDERTHREADS},
{"EXTRASETS", XPRS_EXTRASETS},
{"FEASIBILITYPUMP", XPRS_FEASIBILITYPUMP},
{"PRECOEFELIM", XPRS_PRECOEFELIM},
{"PREDOMCOL", XPRS_PREDOMCOL},
{"HEURSEARCHFREQ", XPRS_HEURSEARCHFREQ},
{"HEURDIVESPEEDUP", XPRS_HEURDIVESPEEDUP},
{"SBESTIMATE", XPRS_SBESTIMATE},
{"BARCORES", XPRS_BARCORES},
{"MAXCHECKSONMAXTIME", XPRS_MAXCHECKSONMAXTIME},
{"MAXCHECKSONMAXCUTTIME", XPRS_MAXCHECKSONMAXCUTTIME},
{"HISTORYCOSTS", XPRS_HISTORYCOSTS},
{"ALGAFTERCROSSOVER", XPRS_ALGAFTERCROSSOVER},
{"MUTEXCALLBACKS", XPRS_MUTEXCALLBACKS},
{"BARCRASH", XPRS_BARCRASH},
{"HEURDIVESOFTROUNDING", XPRS_HEURDIVESOFTROUNDING},
{"HEURSEARCHROOTSELECT", XPRS_HEURSEARCHROOTSELECT},
{"HEURSEARCHTREESELECT", XPRS_HEURSEARCHTREESELECT},
{"MPS18COMPATIBLE", XPRS_MPS18COMPATIBLE},
{"ROOTPRESOLVE", XPRS_ROOTPRESOLVE},
{"CROSSOVERDRP", XPRS_CROSSOVERDRP},
{"FORCEOUTPUT", XPRS_FORCEOUTPUT},
{"PRIMALOPS", XPRS_PRIMALOPS},
{"DETERMINISTIC", XPRS_DETERMINISTIC},
{"PREPROBING", XPRS_PREPROBING},
{"TREEMEMORYLIMIT", XPRS_TREEMEMORYLIMIT},
{"TREECOMPRESSION", XPRS_TREECOMPRESSION},
{"TREEDIAGNOSTICS", XPRS_TREEDIAGNOSTICS},
{"MAXTREEFILESIZE", XPRS_MAXTREEFILESIZE},
{"PRECLIQUESTRATEGY", XPRS_PRECLIQUESTRATEGY},
{"REPAIRINFEASMAXTIME", XPRS_REPAIRINFEASMAXTIME},
{"IFCHECKCONVEXITY", XPRS_IFCHECKCONVEXITY},
{"PRIMALUNSHIFT", XPRS_PRIMALUNSHIFT},
{"REPAIRINDEFINITEQ", XPRS_REPAIRINDEFINITEQ},
{"MIPRAMPUP", XPRS_MIPRAMPUP},
{"MAXLOCALBACKTRACK", XPRS_MAXLOCALBACKTRACK},
{"USERSOLHEURISTIC", XPRS_USERSOLHEURISTIC},
{"FORCEPARALLELDUAL", XPRS_FORCEPARALLELDUAL},
{"BACKTRACKTIE", XPRS_BACKTRACKTIE},
{"BRANCHDISJ", XPRS_BRANCHDISJ},
{"MIPFRACREDUCE", XPRS_MIPFRACREDUCE},
{"CONCURRENTTHREADS", XPRS_CONCURRENTTHREADS},
{"MAXSCALEFACTOR", XPRS_MAXSCALEFACTOR},
{"HEURTHREADS", XPRS_HEURTHREADS},
{"THREADS", XPRS_THREADS},
{"HEURBEFORELP", XPRS_HEURBEFORELP},
{"PREDOMROW", XPRS_PREDOMROW},
{"BRANCHSTRUCTURAL", XPRS_BRANCHSTRUCTURAL},
{"QUADRATICUNSHIFT", XPRS_QUADRATICUNSHIFT},
{"BARPRESOLVEOPS", XPRS_BARPRESOLVEOPS},
{"QSIMPLEXOPS", XPRS_QSIMPLEXOPS},
{"MIPRESTART", XPRS_MIPRESTART},
{"CONFLICTCUTS", XPRS_CONFLICTCUTS},
{"PREPROTECTDUAL", XPRS_PREPROTECTDUAL},
{"CORESPERCPU", XPRS_CORESPERCPU},
{"RESOURCESTRATEGY", XPRS_RESOURCESTRATEGY},
{"CLAMPING", XPRS_CLAMPING},
{"SLEEPONTHREADWAIT", XPRS_SLEEPONTHREADWAIT},
{"PREDUPROW", XPRS_PREDUPROW},
{"CPUPLATFORM", XPRS_CPUPLATFORM},
{"BARALG", XPRS_BARALG},
{"SIFTING", XPRS_SIFTING},
{"LPLOGSTYLE", XPRS_LPLOGSTYLE},
{"RANDOMSEED", XPRS_RANDOMSEED},
{"TREEQCCUTS", XPRS_TREEQCCUTS},
{"PRELINDEP", XPRS_PRELINDEP},
{"DUALTHREADS", XPRS_DUALTHREADS},
{"PREOBJCUTDETECT", XPRS_PREOBJCUTDETECT},
{"PREBNDREDQUAD", XPRS_PREBNDREDQUAD},
{"PREBNDREDCONE", XPRS_PREBNDREDCONE},
{"PRECOMPONENTS", XPRS_PRECOMPONENTS},
{"MAXMIPTASKS", XPRS_MAXMIPTASKS},
{"MIPTERMINATIONMETHOD", XPRS_MIPTERMINATIONMETHOD},
{"PRECONEDECOMP", XPRS_PRECONEDECOMP},
{"HEURFORCESPECIALOBJ", XPRS_HEURFORCESPECIALOBJ},
{"HEURSEARCHROOTCUTFREQ", XPRS_HEURSEARCHROOTCUTFREQ},
{"PREELIMQUAD", XPRS_PREELIMQUAD},
{"PREIMPLICATIONS", XPRS_PREIMPLICATIONS},
{"TUNERMODE", XPRS_TUNERMODE},
{"TUNERMETHOD", XPRS_TUNERMETHOD},
{"TUNERTARGET", XPRS_TUNERTARGET},
{"TUNERTHREADS", XPRS_TUNERTHREADS},
{"TUNERHISTORY", XPRS_TUNERHISTORY},
{"TUNERPERMUTE", XPRS_TUNERPERMUTE},
{"TUNERVERBOSE", XPRS_TUNERVERBOSE},
{"TUNEROUTPUT", XPRS_TUNEROUTPUT},
{"PREANALYTICCENTER", XPRS_PREANALYTICCENTER},
{"NETCUTS", XPRS_NETCUTS},
{"LPFLAGS", XPRS_LPFLAGS},
{"MIPKAPPAFREQ", XPRS_MIPKAPPAFREQ},
{"OBJSCALEFACTOR", XPRS_OBJSCALEFACTOR},
{"TREEFILELOGINTERVAL", XPRS_TREEFILELOGINTERVAL},
{"IGNORECONTAINERCPULIMIT", XPRS_IGNORECONTAINERCPULIMIT},
{"IGNORECONTAINERMEMORYLIMIT", XPRS_IGNORECONTAINERMEMORYLIMIT},
{"MIPDUALREDUCTIONS", XPRS_MIPDUALREDUCTIONS},
{"GENCONSDUALREDUCTIONS", XPRS_GENCONSDUALREDUCTIONS},
{"PWLDUALREDUCTIONS", XPRS_PWLDUALREDUCTIONS},
{"BARFAILITERLIMIT", XPRS_BARFAILITERLIMIT},
{"AUTOSCALING", XPRS_AUTOSCALING},
{"GENCONSABSTRANSFORMATION", XPRS_GENCONSABSTRANSFORMATION},
{"COMPUTEJOBPRIORITY", XPRS_COMPUTEJOBPRIORITY},
{"PREFOLDING", XPRS_PREFOLDING},
{"NETSTALLLIMIT", XPRS_NETSTALLLIMIT},
{"SERIALIZEPREINTSOL", XPRS_SERIALIZEPREINTSOL},
{"NUMERICALEMPHASIS", XPRS_NUMERICALEMPHASIS},
{"PWLNONCONVEXTRANSFORMATION", XPRS_PWLNONCONVEXTRANSFORMATION},
{"MIPCOMPONENTS", XPRS_MIPCOMPONENTS},
{"MIPCONCURRENTNODES", XPRS_MIPCONCURRENTNODES},
{"MIPCONCURRENTSOLVES", XPRS_MIPCONCURRENTSOLVES},
{"OUTPUTCONTROLS", XPRS_OUTPUTCONTROLS},
{"SIFTSWITCH", XPRS_SIFTSWITCH},
{"HEUREMPHASIS", XPRS_HEUREMPHASIS},
{"COMPUTEMATX", XPRS_COMPUTEMATX},
{"COMPUTEMATX_IIS", XPRS_COMPUTEMATX_IIS},
{"COMPUTEMATX_IISMAXTIME", XPRS_COMPUTEMATX_IISMAXTIME},
{"BARREFITER", XPRS_BARREFITER},
{"COMPUTELOG", XPRS_COMPUTELOG},
{"SIFTPRESOLVEOPS", XPRS_SIFTPRESOLVEOPS},
{"CHECKINPUTDATA", XPRS_CHECKINPUTDATA},
{"ESCAPENAMES", XPRS_ESCAPENAMES},
{"IOTIMEOUT", XPRS_IOTIMEOUT},
{"AUTOCUTTING", XPRS_AUTOCUTTING},
{"CALLBACKCHECKTIMEDELAY", XPRS_CALLBACKCHECKTIMEDELAY},
{"MULTIOBJOPS", XPRS_MULTIOBJOPS},
{"MULTIOBJLOG", XPRS_MULTIOBJLOG},
{"GLOBALSPATIALBRANCHIFPREFERORIG", XPRS_GLOBALSPATIALBRANCHIFPREFERORIG},
{"PRECONFIGURATION", XPRS_PRECONFIGURATION},
{"FEASIBILITYJUMP", XPRS_FEASIBILITYJUMP},
};
return mapControls;
}
static std::map<std::string, int>& getMapInt64Controls() {
static std::map<std::string, int> mapControls = {
{"EXTRAELEMS", XPRS_EXTRAELEMS},
{"EXTRASETELEMS", XPRS_EXTRASETELEMS},
};
return mapControls;
}
// Creates an LP/MIP instance.
XpressInterface::XpressInterface(MPSolver* const solver, bool mip)
: MPSolverInterface(solver),
mLp(nullptr),
mMip(mip),
supportIncrementalExtraction(false),
slowUpdates(SlowClearObjective),
mapStringControls_(getMapStringControls()),
mapDoubleControls_(getMapDoubleControls()),
mapIntegerControls_(getMapIntControls()),
mapInteger64Controls_(getMapInt64Controls()) {
bool correctlyLoaded = initXpressEnv();
CHECK(correctlyLoaded);
int status = XPRScreateprob(&mLp);
CHECK_STATUS(status);
DCHECK(mLp != nullptr); // should not be NULL if status=0
int nReturn = XPRSaddcbmessage(mLp, optimizermsg, (void*)this, 0);
CHECK_STATUS(XPRSloadlp(mLp, "newProb", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
CHECK_STATUS(
XPRSchgobjsense(mLp, maximize_ ? XPRS_OBJ_MAXIMIZE : XPRS_OBJ_MINIMIZE));
}
XpressInterface::~XpressInterface() {
CHECK_STATUS(XPRSdestroyprob(mLp));
CHECK_STATUS(XPRSfree());
}
std::string XpressInterface::SolverVersion() const {
// We prefer XPRSversionnumber() over XPRSversion() since the
// former will never pose any encoding issues.
int version = 0;
CHECK_STATUS(XPRSgetintcontrol(mLp, XPRS_VERSION, &version));
int const major = version / 1000000;
version -= major * 1000000;
int const release = version / 10000;
version -= release * 10000;
int const mod = version / 100;
version -= mod * 100;
int const fix = version;
return absl::StrFormat("XPRESS library version %d.%02d.%02d.%02d", major,
release, mod, fix);
}
// ------ Model modifications and extraction -----
void XpressInterface::Reset() {
// Instead of explicitly clearing all modeling objects we
// just delete the problem object and allocate a new one.
CHECK_STATUS(XPRSdestroyprob(mLp));
int status;
status = XPRScreateprob(&mLp);
CHECK_STATUS(status);
DCHECK(mLp != nullptr); // should not be NULL if status=0
int nReturn = XPRSaddcbmessage(mLp, optimizermsg, (void*)this, 0);
CHECK_STATUS(XPRSloadlp(mLp, "newProb", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
CHECK_STATUS(
XPRSchgobjsense(mLp, maximize_ ? XPRS_OBJ_MAXIMIZE : XPRS_OBJ_MINIMIZE));
ResetExtractionInformation();
mCstat.clear();
mRstat.clear();
}
void XpressInterface::SetOptimizationDirection(bool maximize) {
InvalidateSolutionSynchronization();
XPRSchgobjsense(mLp, maximize ? XPRS_OBJ_MAXIMIZE : XPRS_OBJ_MINIMIZE);
}
void XpressInterface::SetVariableBounds(int var_index, double lb, double ub) {
InvalidateSolutionSynchronization();
// Changing the bounds of a variable is fast. However, doing this for
// many variables may still be slow. So we don't perform the update by
// default. However, if we support incremental extraction
// (supportIncrementalExtraction is true) then we MUST perform the
// update here, or we will lose it.
if (!supportIncrementalExtraction && !(slowUpdates & SlowSetVariableBounds)) {
InvalidateModelSynchronization();
} else {
if (variable_is_extracted(var_index)) {
// Variable has already been extracted, so we must modify the
// modeling object.
DCHECK_LT(var_index, last_variable_index_);
char const lu[2] = {'L', 'U'};
double const bd[2] = {lb, ub};
int const idx[2] = {var_index, var_index};
CHECK_STATUS(XPRSchgbounds(mLp, 2, idx, lu, bd));
} else {
// Variable is not yet extracted. It is sufficient to just mark
// the modeling object "out of sync"
InvalidateModelSynchronization();
}
}
}
// Modifies integrality of an extracted variable.
void XpressInterface::SetVariableInteger(int var_index, bool integer) {
InvalidateSolutionSynchronization();
// NOTE: The type of the model (continuous or mixed integer) is
// defined once and for all in the constructor. There are no
// dynamic changes to the model type.
// Changing the type of a variable should be fast. Still, doing all
// updates in one big chunk right before solve() is usually faster.
// However, if we support incremental extraction
// (supportIncrementalExtraction is true) then we MUST change the
// type of extracted variables here.
if (!supportIncrementalExtraction &&
!(slowUpdates & SlowSetVariableInteger)) {
InvalidateModelSynchronization();
} else {
if (mMip) {
if (variable_is_extracted(var_index)) {
// Variable is extracted. Change the type immediately.
// TODO: Should we check the current type and don't do anything
// in case the type does not change?
DCHECK_LE(var_index, getnumcols(mLp));
char const type = integer ? XPRS_INTEGER : XPRS_CONTINUOUS;
CHECK_STATUS(XPRSchgcoltype(mLp, 1, &var_index, &type));
} else {
InvalidateModelSynchronization();
}
} else {
LOG(DFATAL)
<< "Attempt to change variable to integer in non-MIP problem!";
}
}
}
// Setup the right-hand side of a constraint.
void XpressInterface::MakeRhs(double lb, double ub, double& rhs, char& sense,
double& range) {
if (lb == ub) {
// Both bounds are equal -> this is an equality constraint
rhs = lb;
range = 0.0;
sense = 'E';
} else if (lb > XPRS_MINUSINFINITY && ub < XPRS_PLUSINFINITY) {
// Both bounds are finite -> this is a ranged constraint
// The value of a ranged constraint is allowed to be in
// [ rhs-rngval, rhs ]
// Xpress does not support contradictory bounds. Instead the sign on
// rndval is always ignored.
if (lb > ub) {
// TODO check if this is ok for the user
LOG(DFATAL) << "XPRESS does not support contradictory bounds on range "
"constraints! ["
<< lb << ", " << ub << "] will be converted to " << ub << ", "
<< (ub - std::abs(ub - lb)) << "]";
}
rhs = ub;
range = std::abs(
ub - lb); // This happens implicitly by XPRSaddrows() and XPRSloadlp()
sense = 'R';
} else if (ub < XPRS_PLUSINFINITY || (std::abs(ub) == XPRS_PLUSINFINITY &&
std::abs(lb) > XPRS_PLUSINFINITY)) {
// Finite upper, infinite lower bound -> this is a <= constraint