-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
89 lines (76 loc) · 2.12 KB
/
main.cpp
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
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include "AlphaExpansion.h"
#include <vector>
////////////////////////////////////////////////////////////////////////////////
/**
* argv[0] nodes/edges folder path
*
*/
int main(int argc, char *argv[])
{
using namespace std;
string folder_path(argv[1]);
cout << "Looking for data files in " << folder_path << endl;
auto nodes_file = folder_path + "/nodes.txt";
cout << nodes_file << endl;
//get nodes
ifstream infile2(nodes_file);
int a,b,c,d,e,f ;
vector<vector<int>> probabilites;
while (infile2 >> a >> b >> c >> d >> e >> f)
{
vector<int> local_proba;
local_proba.push_back(-a);
local_proba.push_back(-b);
local_proba.push_back(-c);
local_proba.push_back(-d);
local_proba.push_back(-e);
local_proba.push_back(-f);
probabilites.push_back(local_proba);
}
auto edge_file = folder_path + "/edges.txt";
cout << edge_file << endl;
//get edges
vector<vector<int>> edges;
ifstream infile4(edge_file);
int a2,b2 ;
while (infile4 >> a2 >> b2)
{
vector<int> local_edge;
local_edge.push_back(a2);
local_edge.push_back(b2);
edges.push_back(local_edge);
}
auto label_file = folder_path + "/labels.txt";
//Will pretend our graph is general, and set up a neighborhood system
// which actually is a grid. Also uses spatially varying terms
cout << "Start alpha expansion" << endl;
pair<int,vector<int>> results = applyAlphaExpansion(probabilites, edges);
vector<int> result = get<1>(results);
ofstream o(label_file);
for(int i = 0; i<result.size();i++){
o<<result[i]+1<<"\n";
}
printf("Alpha expansion done.\n");
flush(o);
// check if second argument exists
if (argc > 2)
{
string flag(argv[2]);
bool check_coherence = (flag == "--check");
if (check_coherence)
{
// Call python code to check if the results are good
system("python check_labels.py");
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////