jkunlin il y a 8 ans
Parent
commit
40a4a173ec
6 fichiers modifiés avec 464 ajouts et 0 suppressions
  1. 1 0
      .gitignore
  2. 22 0
      stat/Makefile
  3. 20 0
      stat/filename.sh
  4. 289 0
      stat/latex_table.cpp
  5. 35 0
      stat/latex_table.sh
  6. 97 0
      stat/win.cpp

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 dimacs2txt
 dimacs2metis
 test_dimacs
+subgraph

+ 22 - 0
stat/Makefile

@@ -0,0 +1,22 @@
+CC = g++
+CFLAGS = --std=c++11 -DNDEBU -O3
+target = fast-wclq
+all : latex_table win
+
+latex_table : latex_table.cpp
+	$(CC) $(CFLAGS) latex_table.cpp -o latex_table
+
+win : win.cpp
+	$(CC) $(CFLAGS) win.cpp -o win
+
+clean:
+	- rm latex_table
+	- rm win
+
+run:
+	- rm bold_table.tex
+	- rm arch.result
+	- rm sort.tex
+	./latex_table.sh
+	./win arch.result
+	cat bold_table.tex | sort -k1 > sort.tex

+ 20 - 0
stat/filename.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# bio col fb inf int rec ret sci soc tec web
+#~/massive-graphs/${dir}/focus/*.dim; do
+
+SOURCE_DIR="./fastwclq/63e68_ran/63e68_1_1"
+
+find "$SOURCE_DIR" -maxdepth 1 -mindepth 1| while read dir
+do
+	find "$dir" -maxdepth 1 -mindepth 1 | while read file
+	do
+		new_basename=$(basename "$file")
+		new_basename=${new_basename%%\.*}
+		new_file=$(dirname "$file")/"$new_basename"
+		if [ "$file" != "$new_file" ]
+		then
+			mv "$file" "$new_file"
+		fi
+	done
+done

+ 289 - 0
stat/latex_table.cpp

@@ -0,0 +1,289 @@
+// =====================================================================================
+//
+//       Filename:  latex_table.cpp
+//
+//    Description:  
+//
+//        Version:  1.0
+//        Created:  2018年 02月 19日 星期一 16:42:17 CST
+//       Revision:  none
+//       Compiler:  g++
+//
+//         Author:  Jinkun Lin, jkunlin@gmail.com
+//   Organization:  School of EECS, Peking University
+//
+// =====================================================================================
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <vector>
+#include <algorithm>
+#include <limits>
+using namespace std;
+
+string basename(string name) {
+	size_t begin = name.find_last_of('/');
+	return name.substr(begin + 1, name.size() - begin);
+}
+
+int main(int argc, char const *argv[]) {
+	int solver_count = argc - 1;
+
+	// =====================================================================================
+	//      read data from file
+	// =====================================================================================
+	vector<vector<int>> size_matrix (solver_count);
+	vector<vector<double>> time_matrix (solver_count);
+	vector<vector<char>> exact_matrix (solver_count);
+
+	for (int i = 0; i < solver_count; ++i) {
+		ifstream in_file(argv[i + 1]);
+		if (!in_file) {
+			std::cout << argv[i + 1] << '\t' <<  i + 1 <<  " file error" << std::endl;
+			return 1;
+		}
+		int seed, size;
+		double solver_time;
+		char exact;
+		while (in_file >> seed >> size >> solver_time >> exact) {
+			size_matrix[i].push_back(size);
+			time_matrix[i].push_back(solver_time);
+			exact_matrix[i].push_back(exact);
+		}
+		in_file.close();
+	}
+
+	// =====================================================================================
+	//       caculate data
+	// =====================================================================================
+	vector<int> max_size (solver_count);
+	vector<double> avg_size (solver_count);
+	vector<double> avg_time (solver_count);
+	vector<int> is_exact (solver_count, 0);
+
+	int g_max_size = 0;
+	double g_max_avg_size = 0;
+	double g_min_avg_t = std::numeric_limits<double>::max();
+
+	for (int i = 0; i < solver_count; ++i) {
+		int okay_count = 0;
+
+		int m_s = size_matrix[i][0];
+		double avg_s = size_matrix[i][0];
+		double avg_t = time_matrix[i][0];
+
+		if (size_matrix[i][0] != 0) {
+			okay_count++;
+		}
+
+		for (size_t j = 1; j < size_matrix[i].size(); ++j) {
+			if (m_s < size_matrix[i][j]) {
+				m_s = size_matrix[i][j];
+			}
+			avg_s += size_matrix[i][j];
+
+			if (size_matrix[i][j] != 0) {
+				okay_count++;
+			}
+		}
+
+		for (size_t j = 1; j < time_matrix[i].size(); ++j) {
+			avg_t += time_matrix[i][j];
+		}
+
+		for (size_t j = 0; j < exact_matrix[i].size(); ++j) {
+			if (exact_matrix[i][j] == 'x') {
+				is_exact[i] = 1;
+			}
+		}
+
+
+		max_size[i] = m_s;
+		if (okay_count != 0) {
+			avg_size[i] = round(avg_s / okay_count * 100) / 100;
+			avg_time[i] = round(avg_t / okay_count * 100) / 100;
+		}
+		else {
+			avg_size[i] = 0;
+			avg_time[i] = 0;
+		}
+
+		if (okay_count == 0) {
+			continue;
+		}
+
+		if (g_max_size < max_size[i]) {
+			g_max_size = max_size[i];
+		}
+		if (g_max_avg_size < avg_size[i]) {
+			g_max_avg_size = avg_size[i];
+		}
+		if (g_min_avg_t > avg_time[i]) {
+			g_min_avg_t = avg_time[i];
+		}
+	}
+	
+	// =====================================================================================
+	//       generate latex table
+	// =====================================================================================
+	ofstream out_latex("bold_table.tex", ios::app);
+	if (!out_latex) {
+		std::cout << "out file error" << std::endl;
+		return 1;
+	}
+	auto bf_write = [&](double d, bool is_bf) {
+		if (is_bf) {
+			out_latex << "\\textbf{" << d << "}";
+		}
+		else {
+			out_latex << d;
+		}
+	};
+	auto bf_write_time = [&](double d, bool is_bf) {
+		if (is_bf) {
+			if (d < 0.01) {
+				out_latex << "\\boldmath{$<$}\\textbf{0.01}";
+			}
+			else {
+				out_latex << "\\textbf{" << d << "}";
+			}
+		}
+		else {
+			if (d < 0.01) {
+				out_latex << "$<$0.01";
+			}
+			else {
+				out_latex << d;
+			}
+		}
+	};
+
+	out_latex << basename(argv[1]) << " & ";
+	int s_win_count = 0;
+	int avg_s_win_count = 0;
+	int avg_t_win_count = 0;
+	for (int i = 0; i < solver_count; ++i) {
+		if (max_size[i] == g_max_size) {
+			s_win_count++;
+		}
+		if (avg_size[i] == g_max_avg_size) {
+			avg_s_win_count++;
+		}
+		if (avg_time[i] == g_min_avg_t) {
+			avg_t_win_count++;
+		}
+	}
+
+	for (int i = 0; i < solver_count; ++i) {
+		if (max_size[i] == 0) {
+			out_latex << "N/A" << " & " << "N/A";
+			if (i == solver_count - 1) {
+				out_latex << " \\\\" << std::endl;
+			}
+			else {
+				out_latex << " & ";
+			}
+			continue;
+		}
+		// size
+		if (max_size[i] != avg_size[i]) { // max size equals to avg size
+			if (s_win_count != solver_count) {
+				bf_write(max_size[i], max_size[i] == g_max_size);
+			}
+			else {
+				bf_write(max_size[i], false);
+			}
+
+			out_latex << "(";
+			if (avg_s_win_count != solver_count) {
+				bf_write(avg_size[i], avg_size[i] == g_max_avg_size);
+			}
+			else {
+				bf_write(avg_size[i], false);
+			}
+			out_latex << ")";
+		}
+		else { // max size dosen't equal to avg size
+			if (s_win_count != solver_count || avg_s_win_count != solver_count) {
+				bf_write(max_size[i], max_size[i] == g_max_size || avg_size[i] == g_max_avg_size);
+			}
+			else {
+				bf_write(max_size[i], false);
+			}
+		}
+
+		if (is_exact[i]) {
+			out_latex << "$^*$";
+		}
+
+		out_latex << " & ";
+
+		// time
+		if (s_win_count == solver_count && avg_s_win_count == solver_count &&
+				avg_t_win_count != solver_count) {
+			bf_write_time(avg_time[i], avg_time[i] == g_min_avg_t);
+		}
+		else {
+			bf_write_time(avg_time[i], false);
+		}
+
+		if (i == solver_count - 1) {
+			out_latex << " \\\\" << std::endl;
+		}
+		else {
+			out_latex << " & ";
+		}
+	}
+	out_latex.close();
+
+	// =====================================================================================
+	//       generate compare file
+	// =====================================================================================
+	vector<bool> win (solver_count, false);
+	// if (s_win_count != solver_count || avg_s_win_count != solver_count) {
+		for (int i = 0; i < solver_count; ++i) {
+			if (max_size[i] == g_max_size && avg_size[i] == g_max_avg_size) {
+			// if (max_size[i] == g_max_size) {
+				win[i] = true;
+			}
+		}
+	// }
+	ofstream out_arch("arch.result", ios::app);
+	if (!out_arch) {
+		std::cout << "arch file error" << std::endl;
+		return 1;
+	}
+
+	// win
+	out_arch << (win[0] ? 1 : 0);
+	for (int i = 1; i < solver_count; ++i) {
+		out_arch << '\t' << (win[i] ? 1 : 0);
+	}
+	out_arch << std::endl;
+
+	// time
+	out_arch << avg_time[0];
+	for (int i = 1; i < solver_count; ++i) {
+		out_arch << '\t' <<  avg_time[i];
+	}
+	out_arch << std::endl;
+
+	// okay solver
+	out_arch << (max_size[0] != 0 ? 1 : 0);
+	for (int i = 1; i < solver_count; ++i) {
+		out_arch << '\t' << (max_size[i] != 0 ? 1 : 0);
+	}
+	out_arch << endl;
+
+	// exact
+	out_arch << (is_exact[0] != 0 ? 1 : 0);
+	for (int i = 1; i < solver_count; ++i) {
+		out_arch << '\t' << (is_exact[i] != 0 ? 1 : 0);
+	}
+	out_arch << endl;
+	
+
+	out_arch.close();
+
+	return 0;
+}

+ 35 - 0
stat/latex_table.sh

@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# bio col fb inf int rec ret sci soc tec web
+#~/massive-graphs/${dir}/focus/*.dim; do
+
+# Cutoff=100
+# Solver_DIR1="./fastwclq/169cd"
+# Solver_DIR2="./wlmc/noproof_""$Cutoff""s_format"
+# Solver_DIR3="./lscc/include_""$Cutoff""s_format"
+# Solver_DIR4="./fanyi/include_""$Cutoff""s_format"
+# Solver_DIR5="./hao-jinkao/rets1_""$Cutoff""s_format"
+# Solver_DIR6="./hao-jinkao/rets2_""$Cutoff""s_format"
+
+Solver_DIR1="./fastwclq/63e68_ran/63e68_1_0"
+Solver_DIR2="./fastwclq/63e68_ran/63e68_0"
+# Solver_DIR3="./fastwclq/63e68_ran/63e68_1_0"
+# Solver_DIR4="./fastwclq/63e68_ran/63e68_0"
+find "$Solver_DIR1" -maxdepth 1 -mindepth 1| while read dir
+do
+	sub_dir=$(basename "$dir")
+
+	if [ "$sub_dir" == "converted" ]
+	then
+		continue;
+	fi
+
+	find "$dir" -maxdepth 1 -mindepth 1 | while read file
+	do
+		filename=$(basename "$file")
+		./latex_table "$Solver_DIR1"/"$sub_dir"/"$filename" "$Solver_DIR2"/"$sub_dir"/"$filename" \
+			# "$Solver_DIR3"/"$sub_dir"/"$filename" "$Solver_DIR4"/"$sub_dir"/"$filename" \
+			# "$Solver_DIR5"/"$sub_dir"/"$filename" "$Solver_DIR6"/"$sub_dir"/"$filename"
+	done
+
+done

+ 97 - 0
stat/win.cpp

@@ -0,0 +1,97 @@
+// =====================================================================================
+//
+//       Filename:  win.cpp
+//
+//    Description:  
+//
+//        Version:  1.0
+//        Created:  2018年 02月 19日 星期一 20:59:06 CST
+//       Revision:  none
+//       Compiler:  g++
+//
+//         Author:  Jinkun Lin, jkunlin@gmail.com
+//   Organization:  School of EECS, Peking University
+//
+// =====================================================================================
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <vector>
+#include <string>
+#include <algorithm>
+using namespace std;
+
+int main(int argc, char const *argv[]) {
+	if (argc != 2) {
+		std::cout << "usage: " << std::endl;
+		return 1;
+	}
+
+	ifstream in_file(argv[1]);
+	if (!in_file) {
+		std::cout << "file error" << std::endl;
+		return 1;
+	}
+
+	string line;
+	istringstream is;
+	int solver_count = 0;
+	int is_win;
+
+	getline(in_file, line);
+	is.str(line);
+	while (is >> is_win) {
+		solver_count++;
+	}
+
+	vector<int> win_count (solver_count, 0);
+	vector<int> okay_count (solver_count, 0);
+	vector<double> solver_time (solver_count, 0);
+	vector<int> exact_count (solver_count, 0);
+	
+	do {
+		// win count
+		is.clear(); is.str(line);
+		for (int i = 0; is >> is_win; ++i) {
+			win_count[i] += is_win;
+		}
+
+		// time summary
+		getline(in_file, line);
+		is.clear(); is.str(line);
+		double t;
+		for (int i = 0; is >> t; ++i) {
+			solver_time[i] += t;
+		}
+
+		// okay count
+		getline(in_file, line);
+		is.clear(); is.str(line);
+		int okay;
+		for (int i = 0; is >> okay; ++i) {
+			okay_count[i] += okay;
+		}
+
+		// exact count
+		getline(in_file, line);
+		is.clear(); is.str(line);
+		int exact;
+		for (int i = 0; is >> exact; ++i) {
+			exact_count[i] += exact;
+		}
+
+	} while (getline(in_file, line));
+
+	std::cout << win_count[0] << " & " << round(solver_time[0] / okay_count[0] * 100) / 100;
+	for (int i = 1; i < solver_count; ++i) {
+		std::cout << " & " <<  win_count[i] << " & " << round(solver_time[i] / okay_count[i] * 100) / 100;
+	}
+	std::cout << std::endl;
+
+	std::cout << exact_count[0];
+	for (int i = 1; i < solver_count; ++i) {
+		std::cout << " & " << exact_count[i];
+	}
+	std::cout << std::endl;
+	return 0;
+}