boyer_myrvold_planarity_test: Apparent quadratic time complexity for prism graphs

オープン
#247 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
performance

調査の方向性

issue の prism-graph harness を使ってタイミングを再現します。boyer_myrvold_planar_test.hpp と、参照されている libs/graph/example/simple_planarity_test.cpp から開始してください。順序付けされたエッジとシャッフルされたエッジを比較し、スケーリングの違いを調べるために planarity-test path を確認します。プリズムグラフで二次増加が見られなくなり、その挙動が回帰テストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

algorithm performance priority: low

The Boyer-Myrvold planarity test for prism graphs appears to run in quadratic time complexity:

#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp>
#include <boost/timer/timer.hpp>

using namespace std;
using namespace boost;

// Follows libs/graph/example/simple_planarity_test.cpp.
using ugraph = adjacency_list<vecS, vecS, undirectedS,
                              property<vertex_index_t, int>>;

ugraph construct_wheel_graph(size_t k) {
	const size_t num_vertices = 2 * k;
	ugraph G(num_vertices);

	auto add_cycle = [&](int from, int to) {
		for (int i = from; i < to; ++i) {
			add_edge(i, i + 1, G);
		}
		add_edge(to, from, G);
	};

	// Add inner and outer cycle.
	add_cycle(0, k - 1);
	add_cycle(k, 2 * k - 1);

	// Add spokes.
	for (int i = 0; i < k; ++i) {
		add_edge(i, k + i, G);
	}

	return G;
}

// Testing harness.
void run_test() {
	for (int k = 16; k < 35 * 1000; k *= 2) {
		ugraph G = construct_wheel_graph(k);
		cout << "V=" << num_vertices(G) << "\t";
		cout << "E=" << num_edges(G) << "\t" << flush;

		timer::auto_cpu_timer tm(3, "%w seconds\n");
		if (boyer_myrvold_planarity_test(G)) {
			cout << "planar\t";
		} else {
			cout << "not planar\t";
		}
	}
}

int main(int argc, char** argv) {
	run_test();
}

Compile with -O2 -DNDEBUG -lboost_timer. Possible output:

V=32    E=48    planar  0.000 seconds
V=64    E=96    planar  0.000 seconds
V=128   E=192   planar  0.001 seconds
V=256   E=384   planar  0.001 seconds
V=512   E=768   planar  0.003 seconds
V=1024  E=1536  planar  0.008 seconds
V=2048  E=3072  planar  0.028 seconds
V=4096  E=6144  planar  0.096 seconds
V=8192  E=12288 planar  0.366 seconds
V=16384 E=24576 planar  1.536 seconds
V=32768 E=49152 planar  5.606 seconds
V=65536 E=98304 planar  23.151 seconds

The algorithm speeds up significantly (apparently, to linear time complexity) if the edges are first shuffled, or even if the spokes are added to the graph before the cycles.

Tested on Linux; the issue occurs both in 1.75.0 and in the repo version. I'm using GCC 10.2.0.

主要言語
C++
スター
402
フォーク
251
平均マージ
1日 9時間
マージ済み PR(30日)
38

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/graph のほかの issue

boostorg/graph の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。