-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve_qubo.c
More file actions
75 lines (65 loc) · 1.81 KB
/
Copy pathsolve_qubo.c
File metadata and controls
75 lines (65 loc) · 1.81 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
#include <stdio.h>
#include "mqlib_c_api.h"
static int solve_with_heuristic(const char *heuristic, const char *hhdata_dir) {
const double linear[3] = {5.0, 3.0, 1.0};
const int32_t quadratic_i[2] = {0, 1};
const int32_t quadratic_j[2] = {1, 2};
const double quadratic_value[2] = {-6.0, -1.0};
int32_t solution[3] = {0, 0, 0};
char selected_heuristic[64];
double history_values[32];
double history_times[32];
MQLibCQUBOInput input = {
MQLIB_C_ABI_VERSION,
3,
linear,
2,
quadratic_i,
quadratic_j,
quadratic_value,
MQLIB_C_INDEX_BASE_ZERO,
heuristic,
0.01,
1234,
hhdata_dir
};
MQLibCQUBOResult result = {
MQLIB_C_ABI_VERSION,
0.0,
0.0,
solution,
3,
selected_heuristic,
(int32_t)sizeof(selected_heuristic),
history_values,
history_times,
32,
0
};
const int status = mqlib_solve_qubo(&input, &result);
if (status != MQLIB_STATUS_OK) {
fprintf(stderr, "MQLib failed: %s\n", mqlib_c_status_message(status));
return status;
}
printf(
"%s objective %.15g solution %d %d %d runtime %.6f seconds\n",
result.selected_heuristic,
result.objective_value,
result.solution[0],
result.solution[1],
result.solution[2],
result.runtime_seconds
);
return MQLIB_STATUS_OK;
}
int main(int argc, char **argv) {
int status = solve_with_heuristic("ALKHAMIS1998", NULL);
if (status != MQLIB_STATUS_OK) {
return status;
}
if (argc < 2) {
fprintf(stderr, "Pass the path to MQLib's hhdata directory to run the hyperheuristic example.\n");
return 2;
}
return solve_with_heuristic(NULL, argv[1]);
}