This repository was archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (59 loc) · 2.27 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
//
// CGraph - Convertor from DIMACS CNF to GraphML format
// https://www.sophisticatedways.net
// Copyright © 2018 Volodymyr Skladanivskyy. All rights reserved.
// Published under terms of MIT license.
//
#include <cstring>
#include <string>
#include <iostream>
#include "cnf.hpp"
#include "dimacs.hpp"
#include "graphml.hpp"
#include "fileutils.hpp"
using namespace bal;
int main(int argc, const char * argv[]) {
std::cout << "CGraph 1.1 - Convert DIMACS CNF to Grapf ML" << std::endl;
unsigned arg_index = 1;
bool weighted = false;
std::string input_file_name;
std::string output_file_name;
if (arg_index < argc && strlen(argv[arg_index]) == 2 && argv[arg_index][0] == '-' && argv[arg_index][1] == 'w') {
weighted = true;
arg_index++;
};
if (arg_index < argc) {
input_file_name = argv[arg_index];
arg_index++;
};
if (arg_index < argc) {
output_file_name = argv[arg_index];
arg_index++;
};
if (output_file_name.empty()) {
output_file_name = input_file_name + ".graphml";
};
if (!input_file_name.empty()) {
std::cout << "Input file: " << input_file_name << std::endl;
Cnf cnf;
read_from_file<Cnf, DimacsStreamReader>(cnf, input_file_name.c_str());
std::cout << "CNF: " << std::dec;
std::cout << cnf.variables_size() << " variables";
std::cout << ", " << cnf.clauses_size() << " clauses";
std::cout << ", " << cnf.literals_size() << " literals";
std::cout << std::endl;
std::cout << "Output file: " << output_file_name << std::endl;
if (weighted) {
write_to_file<Cnf, GraphMLWeightedStreamWriter>(cnf, output_file_name.c_str());
} else {
write_to_file<Cnf, GraphMLStreamWriter>(cnf, output_file_name.c_str());
};
} else {
std::cout << "Usage:" << std::endl;
std::cout << " cgraph [-w] <input file name> [<output file name>]" << std::endl;
std::cout << " <input file name> - input DIMACS CNF file name" << std::endl;
std::cout << " <output file name> - output Graph ML file name" << std::endl;
std::cout << " w - include edge weight and cardinality" << std::endl;
};
return 0;
}