-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathTestCallbacks.cpp
More file actions
608 lines (547 loc) · 23.5 KB
/
TestCallbacks.cpp
File metadata and controls
608 lines (547 loc) · 23.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
// #include <algorithm>
#include <cstdio>
#include <cstring>
#include "HCheckConfig.h"
#include "Highs.h"
#include "catch.hpp"
#include "lp_data/HConst.h"
#include "lp_data/HighsCallback.h"
const bool dev_run = false;
const double egout_optimal_objective = 568.1007;
const double egout_objective_target = 610;
const HighsInt adlittle_ipm_iteration_limit = 5;
const HighsInt adlittle_simplex_iteration_limit = 30;
const HighsInt kLogBufferSize = kIoBufferSize;
const HighsInt kUserCallbackNoData = -1;
const HighsInt kUserCallbackData = 99;
char printed_log[kLogBufferSize];
using std::memset;
using std::strcmp;
using std::strcpy;
using std::strlen;
using std::strncmp;
using std::strstr;
struct MipData {
HighsInt num_col;
HighsVarType* integrality;
};
struct UserMipSolution {
double optimal_objective_value;
std::vector<double> optimal_solution;
HighsInt require_external_solution_query_origin;
};
// Callback that saves message for comparison
HighsCallbackFunctionType myLogCallback =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) { strcpy(printed_log, message.c_str()); };
HighsCallbackFunctionType userMipSolutionCallback =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) {
if (dev_run) {
printf(
"MipSolutionCallback with objective = %15.8g and bounds [%15.8g, "
"%15.8g]",
data_out->objective_function_value, data_out->mip_dual_bound,
data_out->mip_primal_bound);
MipData callback_data = *(static_cast<MipData*>(user_callback_data));
HighsInt num_col = callback_data.num_col;
HighsVarType* integrality = callback_data.integrality;
HighsInt num_integer = 0;
for (HighsInt iCol = 0; iCol < num_col; iCol++)
if (integrality[iCol] == HighsVarType::kInteger) num_integer++;
if (num_integer < 50) {
printf(" and solution [");
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
if (integrality[iCol] != HighsVarType::kInteger) continue;
double value = data_out->mip_solution[iCol];
if (std::abs(value) < 1e-5) {
printf("0");
} else if (std::abs(value - 1) < 1e-5) {
printf("1");
} else {
bool printed = false;
for (HighsInt k = 2; k < 10; k++) {
if (std::abs(value - k) < 1e-5) {
printf("%1d", int(k));
printed = true;
}
}
if (printed) continue;
for (HighsInt k = 10; k < 999; k++) {
if (std::abs(value - k) < 1e-5) {
printf(" %d ", int(k));
printed = true;
}
}
if (printed) continue;
printf("*");
}
}
printf("]\n");
} else {
printf("\n");
}
fflush(stdout);
}
};
HighsCallbackFunctionType userInterruptCallback =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) {
// Extract local_callback_data from user_callback_data unless it
// is nullptr
if (callback_type == kCallbackMipImprovingSolution) {
// Use local_callback_data to maintain the objective value from
// the previous callback
assert(user_callback_data);
// Extract the double value pointed to from void* user_callback_data
const double local_callback_data = *(double*)user_callback_data;
if (dev_run)
printf(
"userCallback(type %2d; data %11.4g): %s with objective %g and "
"solution[0] = %g\n",
callback_type, local_callback_data, message.c_str(),
data_out->objective_function_value, data_out->mip_solution[0]);
REQUIRE(local_callback_data >= data_out->objective_function_value);
// Update the double value pointed to from void* user_callback_data
*(double*)user_callback_data = data_out->objective_function_value;
} else {
const int local_callback_data =
user_callback_data ? static_cast<int>(reinterpret_cast<intptr_t>(
user_callback_data))
: kUserCallbackNoData;
if (user_callback_data) {
REQUIRE(local_callback_data == kUserCallbackData);
} else {
REQUIRE(local_callback_data == kUserCallbackNoData);
}
if (callback_type == kCallbackLogging) {
if (dev_run) printf("Callback: %s", message.c_str());
// printf("userInterruptCallback(type %2d; data %2d): %s",
// callback_type, local_callback_data,
// message.c_str());
} else if (callback_type == kCallbackSimplexInterrupt) {
if (dev_run)
printf(
"userInterruptCallback(type %2d; data %2d): %s with iteration "
"count = "
"%d\n",
callback_type, local_callback_data, message.c_str(),
int(data_out->simplex_iteration_count));
data_in->user_interrupt = data_out->simplex_iteration_count >
adlittle_simplex_iteration_limit;
} else if (callback_type == kCallbackIpmInterrupt) {
if (dev_run)
printf(
"userInterruptCallback(type %2d; data %2d): %s with iteration "
"count = "
"%d\n",
callback_type, local_callback_data, message.c_str(),
int(data_out->ipm_iteration_count));
data_in->user_interrupt =
data_out->ipm_iteration_count > adlittle_ipm_iteration_limit;
} else if (callback_type == kCallbackMipInterrupt) {
if (dev_run)
printf(
"userInterruptCallback(type %2d; data %2d): %s with Bounds "
"(%11.4g, %11.4g); Gap = %11.4g; Objective = "
"%g\n",
callback_type, local_callback_data, message.c_str(),
data_out->mip_dual_bound, data_out->mip_primal_bound,
data_out->mip_gap, data_out->objective_function_value);
data_in->user_interrupt =
data_out->objective_function_value < egout_objective_target;
}
}
};
HighsCallbackFunctionType userMipCutPoolCallback =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) {
if (dev_run) {
printf("userMipCutPoolCallback: dim(%2d, %2d, %2d)\n",
int(data_out->cutpool_num_col), int(data_out->cutpool_num_cut),
int(data_out->cutpool_value.size()));
for (HighsInt iCut = 0; iCut < data_out->cutpool_num_cut; iCut++) {
printf("Cut %d\n", int(iCut));
for (HighsInt iEl = data_out->cutpool_start[iCut];
iEl < data_out->cutpool_start[iCut + 1]; iEl++) {
printf(" %2d %11.5g\n", int(data_out->cutpool_index[iEl]),
data_out->cutpool_value[iEl]);
}
}
}
};
HighsCallbackFunctionType userkMipUserSolution =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) {
UserMipSolution callback_data =
*(static_cast<UserMipSolution*>(user_callback_data));
if (data_out->external_solution_query_origin ==
callback_data.require_external_solution_query_origin) {
if (data_out->mip_primal_bound >
callback_data.optimal_objective_value) {
// If current objective value is not optimal, pass the
// optimal solution as a user solution
if (dev_run)
printf(
"userkMipUserSolution: origin = %d; %g = mip_primal_bound > "
"optimal_objective_value = %g\n",
int(data_out->external_solution_query_origin),
data_out->mip_primal_bound,
callback_data.optimal_objective_value);
data_in->user_has_solution = true;
data_in->user_solution = callback_data.optimal_solution;
}
}
};
HighsCallbackFunctionType userkMipUserSetSolution =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) {
const auto& callback_data =
*(static_cast<UserMipSolution*>(user_callback_data));
if (data_out->external_solution_query_origin ==
callback_data.require_external_solution_query_origin) {
if (dev_run)
printf(
"userkMipUserSetSolution: origin = %d; %g = mip_primal_bound > "
"optimal_objective_value = %g\n",
int(data_out->external_solution_query_origin),
data_out->mip_primal_bound,
callback_data.optimal_objective_value);
data_in->setSolution(callback_data.optimal_solution.size(),
callback_data.optimal_solution.data());
}
};
HighsCallbackFunctionType userkMipUserSetPartialSolution =
[](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
void* user_callback_data) {
const auto& callback_data =
*(static_cast<UserMipSolution*>(user_callback_data));
if (data_out->external_solution_query_origin ==
callback_data.require_external_solution_query_origin) {
if (dev_run)
printf(
"userkMipUserSetPartialSolution: origin = %d; %g = "
"mip_primal_bound > "
"optimal_objective_value = %g\n",
int(data_out->external_solution_query_origin),
data_out->mip_primal_bound,
callback_data.optimal_objective_value);
// get every other index
std::vector<HighsInt> index;
std::vector<double> value;
for (HighsInt i = 0;
i < static_cast<HighsInt>(callback_data.optimal_solution.size());
i++) {
if (i % 2 == 0) {
index.push_back(i);
value.push_back(callback_data.optimal_solution[i]);
}
}
data_in->setSolution(index.size(), index.data(), value.data());
data_in->repairSolution();
}
};
std::function<void(int, const std::string&, const HighsCallbackOutput*,
HighsCallbackInput*, void*)>
userDataCallback = [](int callback_type, const std::string& message,
const HighsCallbackOutput* data_out,
HighsCallbackInput* data_in,
void* user_callback_data) {
assert(callback_type == kCallbackMipInterrupt ||
callback_type == kCallbackMipLogging ||
callback_type == kCallbackMipImprovingSolution);
if (dev_run)
printf(
"userDataCallback: Node count = %" PRId64
"; LP total iterations = %" PRId64
"; Time = %6.2f; "
"Bounds (%11.4g, %11.4g); Gap = %11.4g; Objective = %11.4g: %s\n",
data_out->mip_node_count, data_out->mip_total_lp_iterations,
data_out->running_time, data_out->mip_dual_bound,
data_out->mip_primal_bound, data_out->mip_gap,
data_out->objective_function_value, message.c_str());
};
TEST_CASE("my-callback-logging", "[highs_callback]") {
bool output_flag = true; // Still runs quietly
bool log_to_console = false;
HighsInt log_dev_level = kHighsLogDevLevelInfo;
HighsLogOptions log_options;
log_options.clear();
log_options.log_stream = stdout;
log_options.output_flag = &output_flag;
log_options.log_to_console = &log_to_console;
log_options.log_dev_level = &log_dev_level;
log_options.user_callback = myLogCallback;
log_options.user_callback_active = true;
highsLogDev(log_options, HighsLogType::kInfo, "Hi %s!", "HiGHS");
if (dev_run) printf("Log callback yields \"%s\"\n", printed_log);
REQUIRE(strcmp(printed_log, "Hi HiGHS!") == 0);
// Check that nothing is printed if the type is VERBOSE when
// log_dev_level is kHighsLogDevLevelInfo;
*printed_log = '\0';
highsLogDev(log_options, HighsLogType::kVerbose, "Hi %s!", "HiGHS");
REQUIRE(*printed_log == '\0');
{
char long_message[sizeof(printed_log)];
memset(long_message, 'H', sizeof(long_message));
long_message[sizeof(long_message) - 2] = '\0';
long_message[sizeof(long_message) - 1] = '\n';
highsLogDev(log_options, HighsLogType::kInfo, long_message);
if (dev_run) printf("Log callback yields \"%s\"\n", printed_log);
REQUIRE(strncmp(printed_log, "HHHH", 4) == 0);
REQUIRE(strlen(printed_log) <= sizeof(printed_log));
}
highsLogUser(log_options, HighsLogType::kInfo, "Hello %s!\n", "HiGHS");
REQUIRE(strlen(printed_log) > 9);
REQUIRE(strcmp(printed_log, "Hello HiGHS!\n") == 0);
{
char long_message[sizeof(printed_log)];
memset(long_message, 'H', sizeof(long_message));
long_message[sizeof(long_message) - 2] = '\0';
long_message[sizeof(long_message) - 1] = '\n';
highsLogUser(log_options, HighsLogType::kWarning, long_message);
if (dev_run) printf("Log callback yields \"%s\"\n", printed_log);
REQUIRE(strstr(printed_log, "HHHH") != nullptr);
REQUIRE(strlen(printed_log) <= sizeof(printed_log));
}
}
TEST_CASE("highs-callback-logging", "[highs_callback]") {
// Uses userInterruptCallback to start logging lines with
// "userInterruptCallback(kUserCallbackData): " since
// Highs::setCallback has second argument p_user_callback_data
std::string filename = std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
int user_callback_data = kUserCallbackData;
void* p_user_callback_data =
reinterpret_cast<void*>(static_cast<intptr_t>(user_callback_data));
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setCallback(userInterruptCallback, p_user_callback_data);
highs.startCallback(kCallbackLogging);
highs.readModel(filename);
highs.run();
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-solution-basis-logging", "[highs_callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
int user_callback_data = kUserCallbackData;
void* p_user_callback_data =
reinterpret_cast<void*>(static_cast<intptr_t>(user_callback_data));
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.readModel(filename);
highs.run();
highs.setCallback(userInterruptCallback, p_user_callback_data);
highs.startCallback(kCallbackLogging);
if (dev_run) highs.writeSolution("", kSolutionStylePretty);
if (dev_run) highs.writeBasis("");
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-simplex-interrupt", "[highs_callback]") {
std::string filename =
std::string(HIGHS_DIR) + "/check/instances/adlittle.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setCallback(userInterruptCallback);
highs.startCallback(kCallbackSimplexInterrupt);
highs.readModel(filename);
HighsStatus status = highs.run();
REQUIRE(status == HighsStatus::kWarning);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kInterrupt);
REQUIRE(highs.getInfo().simplex_iteration_count >
adlittle_simplex_iteration_limit);
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-ipm-interrupt", "[highs_callback]") {
std::string filename =
std::string(HIGHS_DIR) + "/check/instances/adlittle.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setCallback(userInterruptCallback);
highs.startCallback(kCallbackIpmInterrupt);
highs.readModel(filename);
highs.setOptionValue("solver", kIpxString);
REQUIRE(highs.run() == HighsStatus::kWarning);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kInterrupt);
REQUIRE(highs.getInfo().ipm_iteration_count ==
adlittle_ipm_iteration_limit + 1);
highs.readModel(filename);
#ifdef HIPO
REQUIRE(highs.setOptionValue("solver", kHipoString) == HighsStatus::kOk);
;
REQUIRE(highs.run() == HighsStatus::kWarning);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kInterrupt);
REQUIRE(highs.getInfo().ipm_iteration_count ==
adlittle_ipm_iteration_limit + 1);
#endif
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-mip-interrupt", "[highs_callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/egout.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setOptionValue("presolve", kHighsOffString);
highs.setCallback(userInterruptCallback);
highs.startCallback(kCallbackMipInterrupt);
highs.readModel(filename);
HighsStatus status = highs.run();
REQUIRE(status == HighsStatus::kWarning);
REQUIRE(highs.getModelStatus() == HighsModelStatus::kInterrupt);
REQUIRE(highs.getInfo().objective_function_value >= egout_optimal_objective);
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-mip-improving", "[highs_callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/egout.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setOptionValue("presolve", kHighsOffString);
double user_callback_data = kHighsInf;
void* p_user_callback_data = (void*)(&user_callback_data);
highs.setCallback(userInterruptCallback, p_user_callback_data);
highs.startCallback(kCallbackMipImprovingSolution);
highs.readModel(filename);
highs.run();
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-mip-data", "[highs_callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/egout.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setOptionValue("presolve", kHighsOffString);
highs.setCallback(userDataCallback);
highs.startCallback(kCallbackMipImprovingSolution);
highs.startCallback(kCallbackMipLogging);
highs.readModel(filename);
highs.run();
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-mip-solution", "[highs_callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/egout.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setOptionValue("presolve", kHighsOffString);
highs.readModel(filename);
// To print the values of the integer variables in the callback,
// need the number of columns and the integrality. Set this up in a
// struct to be passed via user_callback_data
HighsLp lp = highs.getLp();
MipData user_callback_data;
user_callback_data.num_col = int(lp.num_col_);
user_callback_data.integrality = lp.integrality_.data();
void* p_user_callback_data = &user_callback_data;
highs.setCallback(userMipSolutionCallback, p_user_callback_data);
highs.startCallback(kCallbackMipSolution);
highs.run();
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-mip-cut-pool", "[highs_callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/flugpl.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.readModel(filename);
highs.setCallback(userMipCutPoolCallback);
highs.startCallback(kCallbackMipGetCutPool);
highs.run();
highs.resetGlobalScheduler(true);
}
static void runMipUserSolutionTest(
HighsCallbackFunctionType callback_function) {
const std::vector<std::string> model = {"p0548", "flugpl", "gt2", "egout",
"sp150x300d"};
const std::vector<HighsInt> require_origin = {0, 1, 2, 3, 4}; //, 4, 5, 6};
assert(model.size() == require_origin.size());
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setOptionValue("mip_rel_gap", 0);
HighsInt from_model = 0;
HighsInt to_model = HighsInt(model.size());
for (HighsInt iModel = from_model; iModel < to_model; iModel++) {
const std::string filename =
std::string(HIGHS_DIR) + "/check/instances/" + model[iModel] + ".mps";
highs.readModel(filename);
highs.run();
std::vector<double> optimal_solution = highs.getSolution().col_value;
double objective_function_value0 = highs.getInfo().objective_function_value;
highs.clearSolver();
UserMipSolution user_callback_data;
user_callback_data.optimal_objective_value = objective_function_value0;
user_callback_data.optimal_solution = optimal_solution;
user_callback_data.require_external_solution_query_origin =
require_origin[iModel];
void* p_user_callback_data = (void*)(&user_callback_data);
highs.setCallback(callback_function, p_user_callback_data);
highs.startCallback(kCallbackMipUserSolution);
highs.run();
highs.stopCallback(kCallbackMipUserSolution);
double objective_function_value1 = highs.getInfo().objective_function_value;
double objective_diff =
std::fabs(objective_function_value1 - objective_function_value0) /
std::max(1.0, std::fabs(objective_function_value0));
REQUIRE(objective_diff < 1e-12);
}
highs.resetGlobalScheduler(true);
}
TEST_CASE("highs-callback-mip-user-solution", "[highs-callback]") {
runMipUserSolutionTest(userkMipUserSolution);
}
TEST_CASE("highs-callback-mip-user-set-solution", "[highs-callback]") {
runMipUserSolutionTest(userkMipUserSetSolution);
}
TEST_CASE("highs-callback-mip-user-set-partial-solution", "[highs-callback]") {
runMipUserSolutionTest(userkMipUserSetPartialSolution);
}
// HighsCCallbackType
static void cstyle_userCallback(const int callback_type, const char* message,
const HighsCallbackDataOut* data_out,
HighsCallbackDataIn* data_in,
void* user_callback_data) {
HighsCallbackType cbType = static_cast<HighsCallbackType>(callback_type);
HighsCallbackOutput* cbOut =
static_cast<HighsCallbackOutput*>(data_out->cbdata);
assert(user_callback_data != nullptr);
double local_callback_data = *static_cast<double*>(user_callback_data);
if (dev_run) {
switch (cbType) {
case HighsCallbackType::kCallbackLogging:
printf("userCallback(%11.4g): %s\n", local_callback_data, message);
break;
case HighsCallbackType::kCallbackMipImprovingSolution:
printf("userCallback(%11.4g): improving solution with objective = %g\n",
local_callback_data, cbOut->objective_function_value);
printf("userCallback(%11.4g): improving solution with value[0] = %g\n",
local_callback_data, cbOut->mip_solution[0]);
break;
case HighsCallbackType::kCallbackMipLogging:
printf("userCallback(%11.4g): MIP logging\n", local_callback_data);
break;
case HighsCallbackType::kCallbackMipInterrupt:
printf("userCallback(%11.4g): MIP interrupt\n", local_callback_data);
break;
default:
break;
}
}
if (cbType == HighsCallbackType::kCallbackMipLogging ||
cbType == HighsCallbackType::kCallbackMipInterrupt) {
data_in->user_interrupt = true;
}
}
// test that the c callback also works in c++
TEST_CASE("highs-callback-mip-user-solution-c", "[highs-callback]") {
std::string filename = std::string(HIGHS_DIR) + "/check/instances/egout.mps";
Highs highs;
highs.setOptionValue("output_flag", dev_run);
highs.setOptionValue("presolve", kHighsOffString);
highs.readModel(filename);
double my_callback_data = 5.5;
highs.setCallback(cstyle_userCallback, static_cast<void*>(&my_callback_data));
highs.startCallback(kCallbackMipSolution);
highs.run();
highs.resetGlobalScheduler(true);
}