-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (43 loc) · 1.13 KB
/
main.cpp
File metadata and controls
49 lines (43 loc) · 1.13 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
#include <stdio.h>
#include <stdlib.h>
#include "QPBO.h"
typedef int REAL;
QPBO<REAL>* read_qubo_from_file(const char* filename){
QPBO<REAL>* q;
int num_vars, num_unary, num_pair;
FILE *fp;
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s\n", "error: can't read file.");
return NULL;
}
fscanf(fp, "%d %d %d", &num_vars, &num_unary, &num_pair);
q = new QPBO<REAL>(num_vars, num_pair);
q->AddNode(num_vars);
for(int i = 0; i < num_unary; ++i){
int vi;
REAL v;
fscanf(fp, "%d %d", &vi, &v);
q->AddUnaryTerm(vi, 0, v);
}
for(int i = 0; i < num_pair; ++i){
int vi, vj;
REAL v;
fscanf(fp, "%d %d %d", &vi, &vj, &v);
q->AddPairwiseTerm(vi, vj, 0, 0, 0, v);
}
return q;
}
int main(int argc, char* argv[]){
if(argc < 2){
printf("Usage: ./main qubo_file\n");
return 0;
}
QPBO<REAL>* q = read_qubo_from_file(argv[1]);
q->Solve();
q->ComputeWeakPersistencies();
for(int i = 0; i < q->GetNodeNum(); ++i){
printf("%d\n", q->GetLabel(i));
}
delete q;
return 0;
}