Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 76 additions & 50 deletions cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,91 @@
#include "biplanarSAT.h"
#include "biplanarTester.h"

#include <fstream>
#include <chrono>
#include <string>
#include <limits>

using namespace std;

static bool loadGraphFromFile(const string& path, vector<Edge>& edges, int& n) {
ifstream in(path);
if (!in.is_open()) {
cerr << "Could not open file: " << path << ". Please check that it exists and is readable." << endl;
return false;
}
int u, v;
n = 0;
while (in >> u >> v) {
edges.emplace_back(u, v);
n = max(n, max(u, v) + 1);
}
if (edges.empty()) {
cerr << "File contained no edges or invalid format." << endl;
return false;
}
in.close();
return true;
}

int main() {
/////////////////////////
// Backtracking vs SAT //
/////////////////////////
int n; vector<Edge> edges;
cout << "Would you like to run biplanar tester (y/n)? ";
char choice;
if (!(cin >> choice)) return 0;
cin.ignore(numeric_limits<streamsize>::max(), '\n');

int a = 5, b = 4;
n = a * b;
edges = strongProductEdge(pathGraphEdge(a), a, completeGraphEdge(b), b);
removeVertexEdges(edges, 0);
if (choice == 'y' || choice == 'Y') {
cout << "Path to file: ";
string path;
getline(cin, path);

auto start = chrono::high_resolution_clock::now();
testBiplanarity(&edges, n);
auto end = chrono::high_resolution_clock::now();
chrono::duration<double> elapsed = end - start;
cout << "Took: " << elapsed.count() << " seconds.\n";
int n; vector<Edge> edges;
if (!path.empty()) {
if (!loadGraphFromFile(path, edges, n)) return 1;
} else {
cout << "No path provided. Running default test graph (5x4 strong product minus vertex 0)." << endl;
int a = 5, b = 4;
n = a * b;
edges = strongProductEdge(pathGraphEdge(a), a, completeGraphEdge(b), b);
removeVertexEdges(edges, 0);
}

start = chrono::high_resolution_clock::now();
if (isBiplanarSAT(edges, n)) {
cout << "biplanar" << endl;
auto start = chrono::high_resolution_clock::now();
testBiplanarity(&edges, n);
auto end = chrono::high_resolution_clock::now();
chrono::duration<double> elapsed = end - start;
cout << "Took: " << elapsed.count() << " seconds.\n";
return 0;
}
end = chrono::high_resolution_clock::now();
chrono::duration<double> elapsed2 = end - start;
cout << "Took: " << elapsed2.count() << " seconds.\n";

// n = 8;
// edges = completeGraphEdge(n);

// auto start = chrono::high_resolution_clock::now();
// testBiplanarity(&edges, n);
// auto end = chrono::high_resolution_clock::now();
// chrono::duration<double> elapsed = end - start;
// cout << "Took: " << elapsed.count() << " seconds.\n";
cout << "Would you like to run the candidate builder (y/n)? ";
char build;
if (!(cin >> build)) return 0;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
if (build != 'y' && build != 'Y') return 0;

// start = chrono::high_resolution_clock::now();
// if (isBiplanarSAT(edges, n)) {
// cout << "biplanar" << endl;
// }
// end = chrono::high_resolution_clock::now();
// chrono::duration<double> elapsed2 = end - start;
// cout << "Took: " << elapsed2.count() << " seconds.\n";
int low, high, attempts;
cout << "Enter lower number of vertices: ";
if (!(cin >> low)) return 0;
cout << "Enter higher number of vertices: ";
if (!(cin >> high)) return 0;
cout << "Enter number of candidates to build (attempts) per vertex count: ";
if (!(cin >> attempts)) return 0;
if (low > high || attempts <= 0 || low <= 0 || high <= 0) {
cerr << "Invalid numeric input. Ensure 0 < lower <= higher and attempts > 0." << endl;
return 1;
}

//////////////////////
// Candidate finder //
//////////////////////
// (numVertLow, numVertHigh, numAttempts, bool independenceNumbe, bool chromaticNumber)
// computeCandidateGraphs(20, 80, 100000, true, true);
cout << "Enable independence-number heuristic? (y/n): ";
char indChoice; if (!(cin >> indChoice)) return 0;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Enable chromatic-number search? (y/n): ";
char chrChoice; if (!(cin >> chrChoice)) return 0;
cin.ignore(numeric_limits<streamsize>::max(), '\n');

////////////////////////
// Blow-up of biwheel //
////////////////////////
// int m = 5;
// n = m+2; // spokes: 5,6
// edges = wheelGraphEdge(n, 2);
// printEdges(edges);
// cout << endl;
// edges = blowup(edges, n);
// printEdges(edges);
bool ind = (indChoice == 'y' || indChoice == 'Y');
bool chr = (chrChoice == 'y' || chrChoice == 'Y');

computeCandidateGraphs(low, high, attempts, ind, chr);
return 0;
}

Loading