cpp-pd-code-simplify-interface 0.1.5__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/PKG-INFO +3 -2
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/README.md +2 -1
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp +0 -11
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/data/src/native_interface.cpp +21 -1
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp +0 -147
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/pyproject.toml +1 -1
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/build_backend/cpp_pd_code_simplify_interface_build_backend.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/__init__.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/__main__.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/main.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.5 → cpp_pd_code_simplify_interface-0.1.7}/cpp_pd_code_simplify_interface/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cpp-pd-code-simplify-interface
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: Python interface for cpp-pd-code-simplify with runtime C++ compilation.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Author: GGN_2015
|
|
@@ -56,7 +56,8 @@ The default `max_paths=-1` uses deterministic heuristic green-path sampling in
|
|
|
56
56
|
the C++ backend. Use `ban_heuristic=True` to request exhaustive green-path
|
|
57
57
|
enumeration for a manageable input. Use `reduction_round=K` to cap applied
|
|
58
58
|
mid-simplification rounds; the default `-1` runs until stable. Use
|
|
59
|
-
`verbose=True` to forward C++ progress logs to stderr.
|
|
59
|
+
`verbose=True` to forward timestamped C++ progress logs to stderr. Verbose log
|
|
60
|
+
lines use local wall-clock time in `YYYY-MM-DD HH:MM:SS` format.
|
|
60
61
|
|
|
61
62
|
Batch use:
|
|
62
63
|
|
|
@@ -36,7 +36,8 @@ The default `max_paths=-1` uses deterministic heuristic green-path sampling in
|
|
|
36
36
|
the C++ backend. Use `ban_heuristic=True` to request exhaustive green-path
|
|
37
37
|
enumeration for a manageable input. Use `reduction_round=K` to cap applied
|
|
38
38
|
mid-simplification rounds; the default `-1` runs until stable. Use
|
|
39
|
-
`verbose=True` to forward C++ progress logs to stderr.
|
|
39
|
+
`verbose=True` to forward timestamped C++ progress logs to stderr. Verbose log
|
|
40
|
+
lines use local wall-clock time in `YYYY-MM-DD HH:MM:SS` format.
|
|
40
41
|
|
|
41
42
|
Batch use:
|
|
42
43
|
|
|
@@ -87,13 +87,6 @@ struct RandomInflationResult {
|
|
|
87
87
|
int type_ii_moves = 0;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
struct ReidemeisterSimplificationResult {
|
|
91
|
-
PDCode code;
|
|
92
|
-
std::size_t crossingless_components = 0;
|
|
93
|
-
int type_i_moves = 0;
|
|
94
|
-
int type_ii_moves = 0;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
90
|
struct PDSimplificationResult {
|
|
98
91
|
PDCode code;
|
|
99
92
|
std::size_t crossingless_components = 0;
|
|
@@ -153,10 +146,6 @@ PDCODE_SIMPLIFY_API RandomInflationResult randomly_increase_crossings(
|
|
|
153
146
|
const PDCode& code,
|
|
154
147
|
const RandomInflationOptions& options = RandomInflationOptions{});
|
|
155
148
|
|
|
156
|
-
PDCODE_SIMPLIFY_API ReidemeisterSimplificationResult simplify_reidemeister_i_ii(
|
|
157
|
-
const PDCode& code,
|
|
158
|
-
std::size_t known_crossingless_components = 0);
|
|
159
|
-
|
|
160
149
|
PDCODE_SIMPLIFY_API PDSimplificationResult simplify_pd_code(
|
|
161
150
|
const PDCode& code,
|
|
162
151
|
std::size_t known_crossingless_components = 0);
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
#include <cstdlib>
|
|
4
4
|
#include <cstring>
|
|
5
|
+
#include <ctime>
|
|
5
6
|
#include <exception>
|
|
7
|
+
#include <iomanip>
|
|
6
8
|
#include <iostream>
|
|
7
9
|
#include <sstream>
|
|
8
10
|
#include <string>
|
|
@@ -10,6 +12,24 @@
|
|
|
10
12
|
|
|
11
13
|
namespace {
|
|
12
14
|
|
|
15
|
+
std::string local_timestamp() {
|
|
16
|
+
const std::time_t now = std::time(nullptr);
|
|
17
|
+
std::tm local{};
|
|
18
|
+
#if defined(_WIN32)
|
|
19
|
+
localtime_s(&local, &now);
|
|
20
|
+
#else
|
|
21
|
+
localtime_r(&now, &local);
|
|
22
|
+
#endif
|
|
23
|
+
std::ostringstream out;
|
|
24
|
+
out << std::put_time(&local, "%Y-%m-%d %H:%M:%S");
|
|
25
|
+
return out.str();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void print_progress_log(const std::string& message) {
|
|
29
|
+
std::cerr << "[pdcode-simplify " << local_timestamp() << "] "
|
|
30
|
+
<< message << '\n';
|
|
31
|
+
}
|
|
32
|
+
|
|
13
33
|
bool denotes_crossingless_unknot(const std::string& text) {
|
|
14
34
|
std::string compact;
|
|
15
35
|
for (char c : text) {
|
|
@@ -129,7 +149,7 @@ char* pdcode_simplify_run_json(
|
|
|
129
149
|
options.ban_heuristic = ban_heuristic != 0;
|
|
130
150
|
options.verbose = verbose != 0;
|
|
131
151
|
options.progress = [](const std::string& message) {
|
|
132
|
-
|
|
152
|
+
print_progress_log(message);
|
|
133
153
|
};
|
|
134
154
|
|
|
135
155
|
const pdcode_simplify::PDCode code = pdcode_simplify::parse_pd_code(text);
|
|
@@ -110,31 +110,6 @@ void replace_label(PDCode& code, int old_label, int new_label) {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
void erase_crossings(PDCode& code, int first, int second = -1) {
|
|
114
|
-
if (second >= 0 && first > second) {
|
|
115
|
-
std::swap(first, second);
|
|
116
|
-
}
|
|
117
|
-
if (second >= 0) {
|
|
118
|
-
code.erase(code.begin() + second);
|
|
119
|
-
}
|
|
120
|
-
code.erase(code.begin() + first);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
int label_occurrences_outside(const PDCode& code, int label, const std::set<int>& removed_crossings) {
|
|
124
|
-
int count = 0;
|
|
125
|
-
for (int crossing_index = 0; crossing_index < static_cast<int>(code.size()); ++crossing_index) {
|
|
126
|
-
if (removed_crossings.count(crossing_index) != 0) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
for (int strand = 0; strand < 4; ++strand) {
|
|
130
|
-
if (code[crossing_index][strand] == label) {
|
|
131
|
-
++count;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return count;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
113
|
int unique_label_count(const Crossing& crossing) {
|
|
139
114
|
return static_cast<int>(std::set<int>(crossing.begin(), crossing.end()).size());
|
|
140
115
|
}
|
|
@@ -2040,106 +2015,6 @@ bool apply_reverse_type_ii(PDCode& code, std::mt19937& rng) {
|
|
|
2040
2015
|
return false;
|
|
2041
2016
|
}
|
|
2042
2017
|
|
|
2043
|
-
bool apply_type_i_simplification(
|
|
2044
|
-
PDCode& code,
|
|
2045
|
-
std::size_t& crossingless_components,
|
|
2046
|
-
int& type_i_moves) {
|
|
2047
|
-
for (int crossing_index = 0; crossing_index < static_cast<int>(code.size()); ++crossing_index) {
|
|
2048
|
-
const Crossing crossing = code[crossing_index];
|
|
2049
|
-
for (int i = 0; i < 4; ++i) {
|
|
2050
|
-
if (crossing[i] != crossing[(i + 1) % 4]) {
|
|
2051
|
-
continue;
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
const ComponentAnalysis after_removal =
|
|
2055
|
-
analyze_components_after_removing_crossings(
|
|
2056
|
-
code, std::vector<int>{crossing_index}, crossingless_components);
|
|
2057
|
-
const int keep_label = crossing[(i + 2) % 4];
|
|
2058
|
-
const int merge_label = crossing[(i + 3) % 4];
|
|
2059
|
-
const std::set<int> removed{crossing_index};
|
|
2060
|
-
if (keep_label == merge_label) {
|
|
2061
|
-
if (label_occurrences_outside(code, keep_label, removed) != 0) {
|
|
2062
|
-
continue;
|
|
2063
|
-
}
|
|
2064
|
-
} else if (label_occurrences_outside(code, keep_label, removed) != 1 ||
|
|
2065
|
-
label_occurrences_outside(code, merge_label, removed) != 1) {
|
|
2066
|
-
continue;
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
crossingless_components = after_removal.crossingless_components;
|
|
2070
|
-
erase_crossings(code, crossing_index);
|
|
2071
|
-
replace_label(code, merge_label, keep_label);
|
|
2072
|
-
++type_i_moves;
|
|
2073
|
-
return true;
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
return false;
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
bool apply_type_ii_simplification(
|
|
2080
|
-
PDCode& code,
|
|
2081
|
-
std::size_t& crossingless_components,
|
|
2082
|
-
int& type_ii_moves) {
|
|
2083
|
-
if (code.size() < 2) {
|
|
2084
|
-
return false;
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
const LabelMap labels = build_label_map(code);
|
|
2088
|
-
for (int first_crossing = 0; first_crossing < static_cast<int>(code.size()); ++first_crossing) {
|
|
2089
|
-
for (int a = 0; a < 4; ++a) {
|
|
2090
|
-
const Endpoint first_mate =
|
|
2091
|
-
mate_endpoint(code, labels, Endpoint{first_crossing, a});
|
|
2092
|
-
const Endpoint second_mate =
|
|
2093
|
-
mate_endpoint(code, labels, Endpoint{first_crossing, (a + 1) % 4});
|
|
2094
|
-
const int second_crossing = first_mate.crossing;
|
|
2095
|
-
if (second_crossing == first_crossing || second_crossing != second_mate.crossing) {
|
|
2096
|
-
continue;
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
const int b = first_mate.strand;
|
|
2100
|
-
const int c = second_mate.strand;
|
|
2101
|
-
if (positive_mod(b - 1, 4) != c || (a + b) % 2 != 0) {
|
|
2102
|
-
continue;
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
|
-
const Crossing first = code[first_crossing];
|
|
2106
|
-
const Crossing second = code[second_crossing];
|
|
2107
|
-
const int keep_first = first[(a + 2) % 4];
|
|
2108
|
-
const int merge_first = second[(b + 2) % 4];
|
|
2109
|
-
const int keep_second = first[(a + 3) % 4];
|
|
2110
|
-
const int merge_second = second[(b + 1) % 4];
|
|
2111
|
-
const std::set<int> boundary_labels{
|
|
2112
|
-
keep_first,
|
|
2113
|
-
merge_first,
|
|
2114
|
-
keep_second,
|
|
2115
|
-
merge_second};
|
|
2116
|
-
const std::set<int> removed_crossings{first_crossing, second_crossing};
|
|
2117
|
-
if (boundary_labels.size() != 4 ||
|
|
2118
|
-
label_occurrences_outside(code, keep_first, removed_crossings) != 1 ||
|
|
2119
|
-
label_occurrences_outside(code, merge_first, removed_crossings) != 1 ||
|
|
2120
|
-
label_occurrences_outside(code, keep_second, removed_crossings) != 1 ||
|
|
2121
|
-
label_occurrences_outside(code, merge_second, removed_crossings) != 1) {
|
|
2122
|
-
continue;
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
const ComponentAnalysis after_removal =
|
|
2126
|
-
analyze_components_after_removing_crossings(
|
|
2127
|
-
code,
|
|
2128
|
-
std::vector<int>{first_crossing, second_crossing},
|
|
2129
|
-
crossingless_components);
|
|
2130
|
-
crossingless_components = after_removal.crossingless_components;
|
|
2131
|
-
|
|
2132
|
-
erase_crossings(code, first_crossing, second_crossing);
|
|
2133
|
-
replace_label(code, merge_first, keep_first);
|
|
2134
|
-
replace_label(code, merge_second, keep_second);
|
|
2135
|
-
++type_ii_moves;
|
|
2136
|
-
return true;
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
return false;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
2018
|
RandomInflationResult randomly_increase_crossings(
|
|
2144
2019
|
const PDCode& code,
|
|
2145
2020
|
const RandomInflationOptions& options) {
|
|
@@ -2172,28 +2047,6 @@ RandomInflationResult randomly_increase_crossings(
|
|
|
2172
2047
|
return result;
|
|
2173
2048
|
}
|
|
2174
2049
|
|
|
2175
|
-
ReidemeisterSimplificationResult simplify_reidemeister_i_ii(
|
|
2176
|
-
const PDCode& code,
|
|
2177
|
-
std::size_t known_crossingless_components) {
|
|
2178
|
-
ReidemeisterSimplificationResult result;
|
|
2179
|
-
result.code = code;
|
|
2180
|
-
result.crossingless_components = known_crossingless_components;
|
|
2181
|
-
|
|
2182
|
-
while (true) {
|
|
2183
|
-
if (apply_type_i_simplification(
|
|
2184
|
-
result.code, result.crossingless_components, result.type_i_moves)) {
|
|
2185
|
-
continue;
|
|
2186
|
-
}
|
|
2187
|
-
if (apply_type_ii_simplification(
|
|
2188
|
-
result.code, result.crossingless_components, result.type_ii_moves)) {
|
|
2189
|
-
continue;
|
|
2190
|
-
}
|
|
2191
|
-
break;
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
return result;
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
2050
|
PDSimplificationResult simplify_pd_code(
|
|
2198
2051
|
const PDCode& code,
|
|
2199
2052
|
std::size_t known_crossingless_components) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|