-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathhighs_c_api.cpp
More file actions
1804 lines (1601 loc) · 73.5 KB
/
Copy pathhighs_c_api.cpp
File metadata and controls
1804 lines (1601 loc) · 73.5 KB
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the HiGHS linear optimization suite */
/* */
/* Available as open-source under the MIT License */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "highs_c_api.h"
#include "Highs.h"
HighsInt Highs_lpCall(const HighsInt num_col, const HighsInt num_row,
const HighsInt num_nz, const HighsInt a_format,
const HighsInt sense, const double offset,
const double* col_cost, const double* col_lower,
const double* col_upper, const double* row_lower,
const double* row_upper, const HighsInt* a_start,
const HighsInt* a_index, const double* a_value,
double* col_value, double* col_dual, double* row_value,
double* row_dual, HighsInt* col_basis_status,
HighsInt* row_basis_status, HighsInt* model_status) {
Highs highs;
highs.setOptionValue("output_flag", false);
*model_status = kHighsModelStatusNotset;
HighsStatus status = highs.passModel(
num_col, num_row, num_nz, a_format, sense, offset, col_cost, col_lower,
col_upper, row_lower, row_upper, a_start, a_index, a_value);
if (status == HighsStatus::kError) return (HighsInt)status;
status = highs.run();
if (status == HighsStatus::kOk) {
const HighsSolution& solution = highs.getSolution();
const HighsBasis& basis = highs.getBasis();
*model_status = (HighsInt)highs.getModelStatus();
const HighsInfo& info = highs.getInfo();
const bool copy_col_value =
col_value != nullptr &&
info.primal_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_col_dual =
col_dual != nullptr &&
info.dual_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_col_basis = col_basis_status != nullptr && basis.valid;
for (HighsInt i = 0; i < num_col; i++) {
if (copy_col_value) col_value[i] = solution.col_value[i];
if (copy_col_dual) col_dual[i] = solution.col_dual[i];
if (copy_col_basis) col_basis_status[i] = (HighsInt)basis.col_status[i];
}
const bool copy_row_value =
row_value != nullptr &&
info.primal_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_row_dual =
row_dual != nullptr &&
info.dual_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_row_basis = row_basis_status != nullptr && basis.valid;
for (HighsInt i = 0; i < num_row; i++) {
if (copy_row_value) row_value[i] = solution.row_value[i];
if (copy_row_dual) row_dual[i] = solution.row_dual[i];
if (copy_row_basis) row_basis_status[i] = (HighsInt)basis.row_status[i];
}
}
return (HighsInt)status;
}
HighsInt Highs_mipCall(const HighsInt num_col, const HighsInt num_row,
const HighsInt num_nz, const HighsInt a_format,
const HighsInt sense, const double offset,
const double* col_cost, const double* col_lower,
const double* col_upper, const double* row_lower,
const double* row_upper, const HighsInt* a_start,
const HighsInt* a_index, const double* a_value,
const HighsInt* integrality, double* col_value,
double* row_value, HighsInt* model_status) {
Highs highs;
highs.setOptionValue("output_flag", false);
*model_status = kHighsModelStatusNotset;
HighsStatus status = highs.passModel(
num_col, num_row, num_nz, a_format, sense, offset, col_cost, col_lower,
col_upper, row_lower, row_upper, a_start, a_index, a_value, integrality);
if (status == HighsStatus::kError) return (HighsInt)status;
status = highs.run();
if (status == HighsStatus::kOk) {
const HighsSolution& solution = highs.getSolution();
*model_status = (HighsInt)highs.getModelStatus();
const HighsInfo& info = highs.getInfo();
const bool copy_col_value =
col_value != nullptr &&
info.primal_solution_status != SolutionStatus::kSolutionStatusNone;
if (copy_col_value) {
for (HighsInt i = 0; i < num_col; i++)
col_value[i] = solution.col_value[i];
}
const bool copy_row_value =
row_value != nullptr &&
info.primal_solution_status != SolutionStatus::kSolutionStatusNone;
if (copy_row_value) {
for (HighsInt i = 0; i < num_row; i++)
row_value[i] = solution.row_value[i];
}
}
return (HighsInt)status;
}
HighsInt Highs_qpCall(
const HighsInt num_col, const HighsInt num_row, const HighsInt num_nz,
const HighsInt q_num_nz, const HighsInt a_format, const HighsInt q_format,
const HighsInt sense, const double offset, const double* col_cost,
const double* col_lower, const double* col_upper, const double* row_lower,
const double* row_upper, const HighsInt* a_start, const HighsInt* a_index,
const double* a_value, const HighsInt* q_start, const HighsInt* q_index,
const double* q_value, double* col_value, double* col_dual,
double* row_value, double* row_dual, HighsInt* col_basis_status,
HighsInt* row_basis_status, HighsInt* model_status) {
Highs highs;
highs.setOptionValue("output_flag", false);
*model_status = kHighsModelStatusNotset;
HighsStatus status = highs.passModel(
num_col, num_row, num_nz, q_num_nz, a_format, q_format, sense, offset,
col_cost, col_lower, col_upper, row_lower, row_upper, a_start, a_index,
a_value, q_start, q_index, q_value);
if (status == HighsStatus::kError) return (HighsInt)status;
status = highs.run();
if (status == HighsStatus::kOk) {
const HighsSolution& solution = highs.getSolution();
const HighsBasis& basis = highs.getBasis();
*model_status = (HighsInt)highs.getModelStatus();
const HighsInfo& info = highs.getInfo();
const bool copy_col_value =
col_value != nullptr &&
info.primal_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_col_dual =
col_dual != nullptr &&
info.dual_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_col_basis = col_basis_status != nullptr && basis.valid;
for (HighsInt i = 0; i < num_col; i++) {
if (copy_col_value) col_value[i] = solution.col_value[i];
if (copy_col_dual) col_dual[i] = solution.col_dual[i];
if (copy_col_basis) col_basis_status[i] = (HighsInt)basis.col_status[i];
}
const bool copy_row_value =
row_value != nullptr &&
info.primal_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_row_dual =
row_dual != nullptr &&
info.dual_solution_status != SolutionStatus::kSolutionStatusNone;
const bool copy_row_basis = row_basis_status != nullptr && basis.valid;
for (HighsInt i = 0; i < num_row; i++) {
if (copy_row_value) row_value[i] = solution.row_value[i];
if (copy_row_dual) row_dual[i] = solution.row_dual[i];
if (copy_row_basis) row_basis_status[i] = (HighsInt)basis.row_status[i];
}
}
return (HighsInt)status;
}
void* Highs_create(void) { return new Highs(); }
void Highs_destroy(void* highs) { delete (Highs*)highs; }
const char* Highs_version(void) { return highsVersion(); }
HighsInt Highs_versionMajor(void) { return highsVersionMajor(); }
HighsInt Highs_versionMinor(void) { return highsVersionMinor(); }
HighsInt Highs_versionPatch(void) { return highsVersionPatch(); }
const char* Highs_githash(void) { return highsGithash(); }
HighsInt Highs_presolve(void* highs) {
return (HighsInt)((Highs*)highs)->presolve();
}
HighsInt Highs_run(void* highs) { return (HighsInt)((Highs*)highs)->run(); }
HighsInt Highs_postsolve(void* highs, const double* col_value,
const double* col_dual, const double* row_dual) {
const HighsLp& presolved_lp = ((Highs*)highs)->getPresolvedLp();
HighsInt num_col = presolved_lp.num_col_;
HighsInt num_row = presolved_lp.num_row_;
// Create a HighsSolution from what's been passed
HighsSolution solution;
if (col_value) {
solution.value_valid = true;
solution.col_value.resize(num_col);
// No need for primal row values, but resize the vector for later
// use
solution.row_value.resize(num_row);
}
if (col_dual || row_dual) {
// If column or row duals are passed, assume that they are
// valid. If either is a null pointer, then the corresponding
// vector will have no data, and the size check will fail
solution.dual_valid = true;
if (col_dual) solution.col_dual.resize(num_col);
if (row_dual) solution.row_dual.resize(num_row);
}
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
if (col_value) solution.col_value[iCol] = col_value[iCol];
if (col_dual) solution.col_dual[iCol] = col_dual[iCol];
}
if (row_dual) {
for (HighsInt iRow = 0; iRow < num_row; iRow++)
solution.row_dual[iRow] = row_dual[iRow];
}
return (HighsInt)((Highs*)highs)->postsolve(solution);
}
HighsInt Highs_readModel(void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)->readModel(std::string(filename));
}
HighsInt Highs_writeModel(void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)->writeModel(std::string(filename));
}
HighsInt Highs_writePresolvedModel(void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)->writePresolvedModel(std::string(filename));
}
HighsInt Highs_writeSolution(const void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)
->writeSolution(std::string(filename), kSolutionStyleRaw);
}
HighsInt Highs_writeSolutionPretty(const void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)
->writeSolution(std::string(filename), kSolutionStylePretty);
}
HighsInt Highs_passLp(void* highs, const HighsInt num_col,
const HighsInt num_row, const HighsInt num_nz,
const HighsInt a_format, const HighsInt sense,
const double offset, const double* col_cost,
const double* col_lower, const double* col_upper,
const double* row_lower, const double* row_upper,
const HighsInt* a_start, const HighsInt* a_index,
const double* a_value) {
return (HighsInt)((Highs*)highs)
->passModel(num_col, num_row, num_nz, a_format, sense, offset, col_cost,
col_lower, col_upper, row_lower, row_upper, a_start, a_index,
a_value);
}
HighsInt Highs_passMip(void* highs, const HighsInt num_col,
const HighsInt num_row, const HighsInt num_nz,
const HighsInt a_format, const HighsInt sense,
const double offset, const double* col_cost,
const double* col_lower, const double* col_upper,
const double* row_lower, const double* row_upper,
const HighsInt* a_start, const HighsInt* a_index,
const double* a_value, const HighsInt* integrality) {
return (HighsInt)((Highs*)highs)
->passModel(num_col, num_row, num_nz, a_format, sense, offset, col_cost,
col_lower, col_upper, row_lower, row_upper, a_start, a_index,
a_value, integrality);
}
HighsInt Highs_passModel(void* highs, const HighsInt num_col,
const HighsInt num_row, const HighsInt num_nz,
const HighsInt q_num_nz, const HighsInt a_format,
const HighsInt q_format, const HighsInt sense,
const double offset, const double* col_cost,
const double* col_lower, const double* col_upper,
const double* row_lower, const double* row_upper,
const HighsInt* a_start, const HighsInt* a_index,
const double* a_value, const HighsInt* q_start,
const HighsInt* q_index, const double* q_value,
const HighsInt* integrality) {
return (HighsInt)((Highs*)highs)
->passModel(num_col, num_row, num_nz, q_num_nz, a_format, q_format, sense,
offset, col_cost, col_lower, col_upper, row_lower, row_upper,
a_start, a_index, a_value, q_start, q_index, q_value,
integrality);
}
HighsInt Highs_passHessian(void* highs, const HighsInt dim,
const HighsInt num_nz, const HighsInt format,
const HighsInt* start, const HighsInt* index,
const double* value) {
return (HighsInt)((Highs*)highs)
->passHessian(dim, num_nz, format, start, index, value);
}
HighsInt Highs_passLinearObjectives(const void* highs,
const HighsInt num_linear_objective,
const double* weight, const double* offset,
const double* coefficients,
const double* abs_tolerance,
const double* rel_tolerance,
const HighsInt* priority) {
HighsInt status = Highs_clearLinearObjectives(highs);
if (status != kHighsStatusOk) return status;
HighsLinearObjective linear_objective;
for (HighsInt iObj = 0; iObj < num_linear_objective; iObj++) {
HighsInt num_col = Highs_getNumCol(highs);
linear_objective.weight = weight[iObj];
linear_objective.offset = offset[iObj];
for (HighsInt iCol = 0; iCol < num_col; iCol++)
linear_objective.coefficients.push_back(
coefficients[iObj * num_col + iCol]);
linear_objective.abs_tolerance = abs_tolerance[iObj];
linear_objective.rel_tolerance = rel_tolerance[iObj];
linear_objective.priority = priority[iObj];
linear_objective.weight = weight[iObj];
status =
HighsInt(((Highs*)highs)->addLinearObjective(linear_objective, iObj));
if (status != kHighsStatusOk) return status;
linear_objective.coefficients.clear();
}
return kHighsStatusOk;
}
HighsInt Highs_addLinearObjective(const void* highs, const double weight,
const double offset,
const double* coefficients,
const double abs_tolerance,
const double rel_tolerance,
const HighsInt priority) {
HighsLinearObjective linear_objective;
HighsInt num_col = Highs_getNumCol(highs);
linear_objective.weight = weight;
linear_objective.offset = offset;
for (HighsInt iCol = 0; iCol < num_col; iCol++)
linear_objective.coefficients.push_back(coefficients[iCol]);
linear_objective.abs_tolerance = abs_tolerance;
linear_objective.rel_tolerance = rel_tolerance;
linear_objective.priority = priority;
linear_objective.weight = weight;
return HighsInt(((Highs*)highs)->addLinearObjective(linear_objective));
}
HighsInt Highs_clearLinearObjectives(const void* highs) {
return HighsInt(((Highs*)highs)->clearLinearObjectives());
}
HighsInt Highs_passRowName(const void* highs, const HighsInt row,
const char* name) {
return (HighsInt)((Highs*)highs)->passRowName(row, std::string(name));
}
HighsInt Highs_passColName(const void* highs, const HighsInt col,
const char* name) {
return (HighsInt)((Highs*)highs)->passColName(col, std::string(name));
}
HighsInt Highs_passModelName(const void* highs, const char* name) {
return (HighsInt)((Highs*)highs)->passModelName(std::string(name));
}
HighsInt Highs_readOptions(const void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)->readOptions(filename);
}
HighsInt Highs_clear(void* highs) { return (HighsInt)((Highs*)highs)->clear(); }
HighsInt Highs_clearModel(void* highs) {
return (HighsInt)((Highs*)highs)->clearModel();
}
HighsInt Highs_clearSolver(void* highs) {
return (HighsInt)((Highs*)highs)->clearSolver();
}
HighsInt Highs_releaseMemory(void* highs) {
return (HighsInt)((Highs*)highs)->releaseMemory();
}
HighsInt Highs_setBoolOptionValue(void* highs, const char* option,
const HighsInt value) {
return (HighsInt)((Highs*)highs)
->setOptionValue(std::string(option), (bool)value);
}
HighsInt Highs_setIntOptionValue(void* highs, const char* option,
const HighsInt value) {
return (HighsInt)((Highs*)highs)->setOptionValue(std::string(option), value);
}
HighsInt Highs_setDoubleOptionValue(void* highs, const char* option,
const double value) {
return (HighsInt)((Highs*)highs)->setOptionValue(std::string(option), value);
}
HighsInt Highs_setStringOptionValue(void* highs, const char* option,
const char* value) {
return (HighsInt)((Highs*)highs)
->setOptionValue(std::string(option), std::string(value));
}
HighsInt Highs_getNumOptions(const void* highs) {
return ((Highs*)highs)->getNumOptions();
}
HighsInt Highs_getOptionName(const void* highs, const HighsInt index,
char** name) {
std::string name_v;
HighsInt retcode = (HighsInt)((Highs*)highs)->getOptionName(index, &name_v);
// Guess we have to add one (for Windows, lol!) because char* is
// null-terminated
const HighsInt malloc_size = sizeof(char) * (name_v.length() + 1);
*name = (char*)malloc(malloc_size);
strcpy(*name, name_v.c_str());
return retcode;
}
HighsInt Highs_getBoolOptionValue(const void* highs, const char* option,
HighsInt* value) {
return Highs_getBoolOptionValues(highs, option, value, nullptr);
}
HighsInt Highs_getIntOptionValue(const void* highs, const char* option,
HighsInt* value) {
return Highs_getIntOptionValues(highs, option, value, nullptr, nullptr,
nullptr);
}
HighsInt Highs_getDoubleOptionValue(const void* highs, const char* option,
double* value) {
return Highs_getDoubleOptionValues(highs, option, value, nullptr, nullptr,
nullptr);
}
HighsInt Highs_getStringOptionValue(const void* highs, const char* option,
char* value) {
return Highs_getStringOptionValues(highs, option, value, nullptr);
}
HighsInt Highs_getOptionType(const void* highs, const char* option,
HighsInt* type) {
HighsOptionType t;
HighsInt retcode =
(HighsInt)((Highs*)highs)->getOptionType(std::string(option), t);
*type = (HighsInt)t;
return retcode;
}
HighsInt Highs_getBoolOptionValues(const void* highs, const char* option,
HighsInt* current_value,
HighsInt* default_value) {
bool current_v;
bool default_v;
HighsInt retcode =
(HighsInt)((Highs*)highs)
->getBoolOptionValues(std::string(option), ¤t_v, &default_v);
if (current_value) *current_value = current_v;
if (default_value) *default_value = default_v;
return retcode;
}
HighsInt Highs_getIntOptionValues(const void* highs, const char* option,
HighsInt* current_value, HighsInt* min_value,
HighsInt* max_value,
HighsInt* default_value) {
return (HighsInt)((Highs*)highs)
->getIntOptionValues(std::string(option), current_value, min_value,
max_value, default_value);
}
HighsInt Highs_getDoubleOptionValues(const void* highs, const char* option,
double* current_value, double* min_value,
double* max_value, double* default_value) {
return (HighsInt)((Highs*)highs)
->getDoubleOptionValues(std::string(option), current_value, min_value,
max_value, default_value);
}
HighsInt Highs_getStringOptionValues(const void* highs, const char* option,
char* current_value, char* default_value) {
std::string current_v;
std::string default_v;
// Inherited from Highs_getStringOptionValue: cannot see why this
// was ever useful. Must assume that current_value is of length at
// least 7, which isn't necessarily true
//
// if (current_value) memset(current_value, 0, 7);
// if (default_value) memset(default_value, 0, 7);
HighsInt retcode =
(HighsInt)((Highs*)highs)
->getStringOptionValues(std::string(option), ¤t_v, &default_v);
// current_value and default_value are nullptr by default
if (current_value) strcpy(current_value, current_v.c_str());
if (default_value) strcpy(default_value, default_v.c_str());
return retcode;
}
HighsInt Highs_resetOptions(void* highs) {
return (HighsInt)((Highs*)highs)->resetOptions();
}
HighsInt Highs_writeOptions(const void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)->writeOptions(filename);
}
HighsInt Highs_writeOptionsDeviations(const void* highs, const char* filename) {
return (HighsInt)((Highs*)highs)->writeOptions(filename, true);
}
HighsInt Highs_getIntInfoValue(const void* highs, const char* info,
HighsInt* value) {
return (HighsInt)((Highs*)highs)->getInfoValue(info, *value);
}
HighsInt Highs_getDoubleInfoValue(const void* highs, const char* info,
double* value) {
return (HighsInt)((Highs*)highs)->getInfoValue(info, *value);
}
HighsInt Highs_getInt64InfoValue(const void* highs, const char* info,
int64_t* value) {
return (HighsInt)((Highs*)highs)->getInfoValue(info, *value);
}
HighsInt Highs_getInfoType(const void* highs, const char* info,
HighsInt* type) {
HighsInfoType t;
HighsInt retcode =
(HighsInt)((Highs*)highs)->getInfoType(std::string(info), t);
*type = (HighsInt)t;
return retcode;
}
HighsInt Highs_getSolution(const void* highs, double* col_value,
double* col_dual, double* row_value,
double* row_dual) {
const HighsSolution& solution = ((Highs*)highs)->getSolution();
if (col_value != nullptr) {
for (size_t i = 0; i < solution.col_value.size(); i++) {
col_value[i] = solution.col_value[i];
}
}
if (col_dual != nullptr) {
for (size_t i = 0; i < solution.col_dual.size(); i++) {
col_dual[i] = solution.col_dual[i];
}
}
if (row_value != nullptr) {
for (size_t i = 0; i < solution.row_value.size(); i++) {
row_value[i] = solution.row_value[i];
}
}
if (row_dual != nullptr) {
for (size_t i = 0; i < solution.row_dual.size(); i++) {
row_dual[i] = solution.row_dual[i];
}
}
return kHighsStatusOk;
}
HighsInt Highs_getBasis(const void* highs, HighsInt* col_status,
HighsInt* row_status) {
const HighsBasis& basis = ((Highs*)highs)->getBasis();
for (size_t i = 0; i < basis.col_status.size(); i++) {
col_status[i] = static_cast<HighsInt>(basis.col_status[i]);
}
for (size_t i = 0; i < basis.row_status.size(); i++) {
row_status[i] = static_cast<HighsInt>(basis.row_status[i]);
}
return kHighsStatusOk;
}
HighsInt Highs_getModelStatus(const void* highs) {
return (HighsInt)((Highs*)highs)->getModelStatus();
}
HighsInt Highs_getDualRay(const void* highs, HighsInt* has_dual_ray,
double* dual_ray_value) {
bool v;
HighsInt retcode = (HighsInt)((Highs*)highs)->getDualRay(v, dual_ray_value);
*has_dual_ray = (HighsInt)v;
return retcode;
}
HighsInt Highs_getDualUnboundednessDirection(
const void* highs, HighsInt* has_dual_unboundedness_direction,
double* dual_unboundedness_direction_value) {
bool v;
HighsInt retcode = (HighsInt)((Highs*)highs)
->getDualUnboundednessDirection(
v, dual_unboundedness_direction_value);
*has_dual_unboundedness_direction = (HighsInt)v;
return retcode;
}
HighsInt Highs_getPrimalRay(const void* highs, HighsInt* has_primal_ray,
double* primal_ray_value) {
bool v;
HighsInt retcode =
(HighsInt)((Highs*)highs)->getPrimalRay(v, primal_ray_value);
*has_primal_ray = (HighsInt)v;
return retcode;
}
double Highs_getObjectiveValue(const void* highs) {
return ((Highs*)highs)->getObjectiveValue();
}
HighsInt Highs_getBasicVariables(const void* highs, HighsInt* basic_variables) {
return (HighsInt)((Highs*)highs)->getBasicVariables(basic_variables);
}
HighsInt Highs_getBasisInverseRow(const void* highs, const HighsInt row,
double* row_vector, HighsInt* row_num_nz,
HighsInt* row_index) {
return (HighsInt)((Highs*)highs)
->getBasisInverseRow(row, row_vector, row_num_nz, row_index);
}
HighsInt Highs_getBasisInverseCol(const void* highs, const HighsInt col,
double* col_vector, HighsInt* col_num_nz,
HighsInt* col_index) {
return (HighsInt)((Highs*)highs)
->getBasisInverseCol(col, col_vector, col_num_nz, col_index);
}
HighsInt Highs_getBasisSolve(const void* highs, const double* rhs,
double* solution_vector, HighsInt* solution_num_nz,
HighsInt* solution_index) {
return (HighsInt)((Highs*)highs)
->getBasisSolve(rhs, solution_vector, solution_num_nz, solution_index);
}
HighsInt Highs_getBasisTransposeSolve(const void* highs, const double* rhs,
double* solution_vector,
HighsInt* solution_nz,
HighsInt* solution_index) {
return (HighsInt)((Highs*)highs)
->getBasisTransposeSolve(rhs, solution_vector, solution_nz,
solution_index);
}
HighsInt Highs_getReducedRow(const void* highs, const HighsInt row,
double* row_vector, HighsInt* row_num_nz,
HighsInt* row_index) {
return (HighsInt)((Highs*)highs)
->getReducedRow(row, row_vector, row_num_nz, row_index);
}
HighsInt Highs_getReducedColumn(const void* highs, const HighsInt col,
double* col_vector, HighsInt* col_num_nz,
HighsInt* col_index) {
return (HighsInt)((Highs*)highs)
->getReducedColumn(col, col_vector, col_num_nz, col_index);
}
HighsInt Highs_setBasis(void* highs, const HighsInt* col_status,
const HighsInt* row_status) {
HighsBasis basis;
const HighsInt num__col = Highs_getNumCol(highs);
if (num__col > 0) {
basis.col_status.resize(num__col);
for (HighsInt i = 0; i < num__col; i++) {
if (col_status[i] == (HighsInt)HighsBasisStatus::kLower) {
basis.col_status[i] = HighsBasisStatus::kLower;
} else if (col_status[i] == (HighsInt)HighsBasisStatus::kBasic) {
basis.col_status[i] = HighsBasisStatus::kBasic;
} else if (col_status[i] == (HighsInt)HighsBasisStatus::kUpper) {
basis.col_status[i] = HighsBasisStatus::kUpper;
} else if (col_status[i] == (HighsInt)HighsBasisStatus::kZero) {
basis.col_status[i] = HighsBasisStatus::kZero;
} else if (col_status[i] == (HighsInt)HighsBasisStatus::kNonbasic) {
basis.col_status[i] = HighsBasisStatus::kNonbasic;
} else {
return (HighsInt)HighsStatus::kError;
}
}
}
const HighsInt num__row = Highs_getNumRow(highs);
if (num__row > 0) {
basis.row_status.resize(num__row);
for (HighsInt i = 0; i < num__row; i++) {
if (row_status[i] == (HighsInt)HighsBasisStatus::kLower) {
basis.row_status[i] = HighsBasisStatus::kLower;
} else if (row_status[i] == (HighsInt)HighsBasisStatus::kBasic) {
basis.row_status[i] = HighsBasisStatus::kBasic;
} else if (row_status[i] == (HighsInt)HighsBasisStatus::kUpper) {
basis.row_status[i] = HighsBasisStatus::kUpper;
} else if (row_status[i] == (HighsInt)HighsBasisStatus::kZero) {
basis.row_status[i] = HighsBasisStatus::kZero;
} else if (row_status[i] == (HighsInt)HighsBasisStatus::kNonbasic) {
basis.row_status[i] = HighsBasisStatus::kNonbasic;
} else {
return (HighsInt)HighsStatus::kError;
}
}
}
return (HighsInt)((Highs*)highs)->setBasis(basis);
}
HighsInt Highs_setLogicalBasis(void* highs) {
return (HighsInt)((Highs*)highs)->setBasis();
}
HighsInt Highs_setSolution(void* highs, const double* col_value,
const double* row_value, const double* col_dual,
const double* row_dual) {
HighsSolution solution;
const HighsInt num__col = Highs_getNumCol(highs);
if (num__col > 0) {
if (col_value) {
solution.col_value.resize(num__col);
for (HighsInt i = 0; i < num__col; i++)
solution.col_value[i] = col_value[i];
}
if (col_dual) {
solution.col_dual.resize(num__col);
for (HighsInt i = 0; i < num__col; i++)
solution.col_dual[i] = col_dual[i];
}
}
const HighsInt num__row = Highs_getNumRow(highs);
if (num__row > 0) {
if (row_value) {
solution.row_value.resize(num__row);
for (HighsInt i = 0; i < num__row; i++)
solution.row_value[i] = row_value[i];
}
if (row_dual) {
solution.row_dual.resize(num__row);
for (HighsInt i = 0; i < num__row; i++)
solution.row_dual[i] = row_dual[i];
}
}
return (HighsInt)((Highs*)highs)->setSolution(solution);
}
HighsInt Highs_setSparseSolution(void* highs, const HighsInt num_entries,
const HighsInt* index, const double* value) {
return (HighsInt)((Highs*)highs)->setSolution(num_entries, index, value);
}
HighsInt Highs_setCallback(void* highs, HighsCCallbackType user_callback,
void* user_callback_data) {
auto status = static_cast<Highs*>(highs)->setCallback(user_callback,
user_callback_data);
return static_cast<int>(status);
}
HighsInt Highs_startCallback(void* highs, const HighsInt callback_type) {
return (HighsInt)((Highs*)highs)->startCallback(callback_type);
}
HighsInt Highs_stopCallback(void* highs, const HighsInt callback_type) {
return (HighsInt)((Highs*)highs)->stopCallback(callback_type);
}
double Highs_getRunTime(const void* highs) {
return (double)((Highs*)highs)->getRunTime();
}
HighsInt Highs_zeroAllClocks(const void* highs) {
((Highs*)highs)->zeroAllClocks();
return (HighsInt)HighsStatus::kOk;
}
HighsInt Highs_addCol(void* highs, const double cost, const double lower,
const double upper, const HighsInt num_new_nz,
const HighsInt* index, const double* value) {
return (HighsInt)((Highs*)highs)
->addCol(cost, lower, upper, num_new_nz, index, value);
}
HighsInt Highs_addCols(void* highs, const HighsInt num_new_col,
const double* costs, const double* lower,
const double* upper, const HighsInt num_new_nz,
const HighsInt* starts, const HighsInt* index,
const double* value) {
return (HighsInt)((Highs*)highs)
->addCols(num_new_col, costs, lower, upper, num_new_nz, starts, index,
value);
}
HighsInt Highs_addVar(void* highs, const double lower, const double upper) {
return (HighsInt)((Highs*)highs)->addVar(lower, upper);
}
HighsInt Highs_addVars(void* highs, const HighsInt num_new_var,
const double* lower, const double* upper) {
return (HighsInt)((Highs*)highs)->addVars(num_new_var, lower, upper);
}
HighsInt Highs_addRow(void* highs, const double lower, const double upper,
const HighsInt num_new_nz, const HighsInt* index,
const double* value) {
return (HighsInt)((Highs*)highs)
->addRow(lower, upper, num_new_nz, index, value);
}
HighsInt Highs_addRows(void* highs, const HighsInt num_new_row,
const double* lower, const double* upper,
const HighsInt num_new_nz, const HighsInt* starts,
const HighsInt* index, const double* value) {
return (HighsInt)((Highs*)highs)
->addRows(num_new_row, lower, upper, num_new_nz, starts, index, value);
}
HighsInt Highs_ensureColwise(void* highs) {
return (HighsInt)((Highs*)highs)->ensureColwise();
}
HighsInt Highs_ensureRowwise(void* highs) {
return (HighsInt)((Highs*)highs)->ensureRowwise();
}
HighsInt Highs_changeObjectiveSense(void* highs, const HighsInt sense) {
ObjSense pass_sense = ObjSense::kMinimize;
if (sense == (HighsInt)ObjSense::kMaximize) pass_sense = ObjSense::kMaximize;
return (HighsInt)((Highs*)highs)->changeObjectiveSense(pass_sense);
}
HighsInt Highs_changeObjectiveOffset(void* highs, const double offset) {
return (HighsInt)((Highs*)highs)->changeObjectiveOffset(offset);
}
HighsInt Highs_changeColIntegrality(void* highs, const HighsInt col,
const HighsInt integrality) {
return (HighsInt)((Highs*)highs)
->changeColIntegrality(col, (HighsVarType)integrality);
}
HighsInt Highs_changeColsIntegralityByRange(void* highs,
const HighsInt from_col,
const HighsInt to_col,
const HighsInt* integrality) {
vector<HighsVarType> pass_integrality;
HighsInt num_ix = to_col - from_col + 1;
if (num_ix > 0) {
pass_integrality.resize(num_ix);
for (HighsInt ix = 0; ix < num_ix; ix++) {
pass_integrality[ix] = (HighsVarType)integrality[ix];
}
}
return (HighsInt)((Highs*)highs)
->changeColsIntegrality(from_col, to_col, pass_integrality.data());
}
HighsInt Highs_changeColsIntegralityBySet(void* highs,
const HighsInt num_set_entries,
const HighsInt* set,
const HighsInt* integrality) {
vector<HighsVarType> pass_integrality;
if (num_set_entries > 0) {
pass_integrality.resize(num_set_entries);
for (HighsInt ix = 0; ix < num_set_entries; ix++) {
pass_integrality[ix] = (HighsVarType)integrality[ix];
}
}
return (HighsInt)((Highs*)highs)
->changeColsIntegrality(num_set_entries, set, pass_integrality.data());
}
HighsInt Highs_changeColsIntegralityByMask(void* highs, const HighsInt* mask,
const HighsInt* integrality) {
const HighsInt num__col = Highs_getNumCol(highs);
vector<HighsVarType> pass_integrality;
if (num__col > 0) {
pass_integrality.resize(num__col);
for (HighsInt iCol = 0; iCol < num__col; iCol++) {
pass_integrality[iCol] = (HighsVarType)integrality[iCol];
}
}
return (HighsInt)((Highs*)highs)
->changeColsIntegrality(mask, pass_integrality.data());
}
HighsInt Highs_clearIntegrality(void* highs) {
return (HighsInt)((Highs*)highs)->clearIntegrality();
}
HighsInt Highs_changeColCost(void* highs, const HighsInt col,
const double cost) {
return (HighsInt)((Highs*)highs)->changeColCost(col, cost);
}
HighsInt Highs_changeColsCostByRange(void* highs, const HighsInt from_col,
const HighsInt to_col,
const double* cost) {
return (HighsInt)((Highs*)highs)->changeColsCost(from_col, to_col, cost);
}
HighsInt Highs_changeColsCostBySet(void* highs, const HighsInt num_set_entries,
const HighsInt* set, const double* cost) {
return (HighsInt)((Highs*)highs)->changeColsCost(num_set_entries, set, cost);
}
HighsInt Highs_changeColsCostByMask(void* highs, const HighsInt* mask,
const double* cost) {
return (HighsInt)((Highs*)highs)->changeColsCost(mask, cost);
}
HighsInt Highs_changeColBounds(void* highs, const HighsInt col,
const double lower, const double upper) {
return (HighsInt)((Highs*)highs)->changeColBounds(col, lower, upper);
}
HighsInt Highs_changeColsBoundsByRange(void* highs, const HighsInt from_col,
const HighsInt to_col,
const double* lower,
const double* upper) {
return (HighsInt)((Highs*)highs)
->changeColsBounds(from_col, to_col, lower, upper);
}
HighsInt Highs_changeColsBoundsBySet(void* highs,
const HighsInt num_set_entries,
const HighsInt* set, const double* lower,
const double* upper) {
return (HighsInt)((Highs*)highs)
->changeColsBounds(num_set_entries, set, lower, upper);
}
HighsInt Highs_changeColsBoundsByMask(void* highs, const HighsInt* mask,
const double* lower,
const double* upper) {
return (HighsInt)((Highs*)highs)->changeColsBounds(mask, lower, upper);
}
HighsInt Highs_changeRowBounds(void* highs, const HighsInt row,
const double lower, const double upper) {
return (HighsInt)((Highs*)highs)->changeRowBounds(row, lower, upper);
}
HighsInt Highs_changeRowsBoundsByRange(void* highs, const HighsInt from_row,
const HighsInt to_row,
const double* lower,
const double* upper) {
return (HighsInt)((Highs*)highs)
->changeRowsBounds(from_row, to_row, lower, upper);
}
HighsInt Highs_changeRowsBoundsBySet(void* highs,
const HighsInt num_set_entries,
const HighsInt* set, const double* lower,
const double* upper) {
return (HighsInt)((Highs*)highs)
->changeRowsBounds(num_set_entries, set, lower, upper);
}
HighsInt Highs_changeRowsBoundsByMask(void* highs, const HighsInt* mask,
const double* lower,
const double* upper) {
return (HighsInt)((Highs*)highs)->changeRowsBounds(mask, lower, upper);
}
HighsInt Highs_changeCoeff(void* highs, const HighsInt row, const HighsInt col,
const double value) {
return (HighsInt)((Highs*)highs)->changeCoeff(row, col, value);
}
HighsInt Highs_getObjectiveSense(const void* highs, HighsInt* sense) {
ObjSense get_sense;
HighsStatus status = ((Highs*)highs)->getObjectiveSense(get_sense);
*sense = (HighsInt)get_sense;
return (HighsInt)status;
}
HighsInt Highs_getObjectiveOffset(const void* highs, double* offset) {
return (HighsInt)((Highs*)highs)->getObjectiveOffset(*offset);
}
HighsInt Highs_getColsByRange(const void* highs, const HighsInt from_col,
const HighsInt to_col, HighsInt* num_col,
double* costs, double* lower, double* upper,
HighsInt* num_nz, HighsInt* matrix_start,
HighsInt* matrix_index, double* matrix_value) {
HighsInt local_num_col, local_num_nz;
HighsStatus status =
((Highs*)highs)
->getCols(from_col, to_col, local_num_col, costs, lower, upper,
local_num_nz, matrix_start, matrix_index, matrix_value);
*num_col = local_num_col;
*num_nz = local_num_nz;
return (HighsInt)status;
}
HighsInt Highs_getColsBySet(const void* highs, const HighsInt num_set_entries,
const HighsInt* set, HighsInt* num_col,
double* costs, double* lower, double* upper,
HighsInt* num_nz, HighsInt* matrix_start,
HighsInt* matrix_index, double* matrix_value) {
HighsInt local_num_col, local_num_nz;
HighsStatus status =
((Highs*)highs)
->getCols(num_set_entries, set, local_num_col, costs, lower, upper,
local_num_nz, matrix_start, matrix_index, matrix_value);
*num_col = local_num_col;
*num_nz = local_num_nz;
return (HighsInt)status;
}