Browse Source

remove: unnecessary code and files

master
Dnomd343 3 weeks ago
parent
commit
675927464d
  1. 2
      src/core/group/group.h
  2. 84
      src/core/group/internal/extend.cc
  3. 4
      src/core/group/internal/group.cc
  4. 71
      src/core/group/internal/load_factor.py
  5. 21365
      src/core/group/internal/load_factor.txt
  6. 65
      src/core/main.cc
  7. 19
      verify/compare.py
  8. 65
      verify/extract.py

2
src/core/group/group.h

@ -266,8 +266,6 @@ private:
/// Spawn all the unsorted codes of the current group.
std::vector<codec::RawCode> Group_extend(codec::RawCode raw_code, uint32_t reserve = 0);
double Group_load_factor(codec::RawCode raw_code, double coff);
class GroupCases {
public:
// ------------------------------------------------------------------------------------- //

84
src/core/group/internal/extend.cc

@ -1,4 +1,4 @@
#include <absl/container/flat_hash_map.h>
// #include <absl/container/flat_hash_map.h>
#include <parallel_hashmap/phmap.h>
@ -17,7 +17,6 @@ using klotski::cases::GroupUnion;
std::vector<RawCode> klotski::cases::Group_extend(RawCode raw_code, uint32_t reserve) {
std::vector<RawCode> codes;
// absl::flat_hash_map<uint64_t, uint64_t> cases; // <code, mask>
phmap::flat_hash_map<uint64_t, uint64_t> cases; // <code, mask>
// reserve = reserve ? reserve : GroupUnion::from_raw_code(raw_code).max_group_size();
// reserve = 25955;
@ -44,84 +43,3 @@ std::vector<RawCode> klotski::cases::Group_extend(RawCode raw_code, uint32_t res
// std::cout << cases.load_factor() << std::endl;
return codes;
}
double klotski::cases::Group_load_factor(RawCode raw_code, double coff) {
std::vector<RawCode> codes;
phmap::flat_hash_map<uint64_t, uint64_t> cases; // <code, mask>
const auto reserve = GroupUnion::from_raw_code(raw_code).max_group_size();
codes.reserve(reserve);
cases.reserve(static_cast<size_t>(coff * reserve));
auto core = MaskMover([&codes, &cases](RawCode code, uint64_t mask) {
if (const auto match = cases.find(code.unwrap()); match != cases.end()) {
match->second |= mask; // update mask
return;
}
cases.emplace(code, mask);
codes.emplace_back(code); // new case
});
uint64_t offset = 0;
codes.emplace_back(raw_code);
cases.emplace(raw_code, 0); // without mask
while (offset != codes.size()) {
auto curr = codes[offset++].unwrap();
core.next_cases(RawCode::unsafe_create(curr), cases.find(curr)->second);
}
// if (cases.size() != reserve) {
// std::cout << "reserve size error" << std::endl;
// std::abort();
// }
return cases.load_factor();
}
//RangesUnion Group::cases() const {
//
// // TODO: add white list for single-group unions
// // return GroupUnion::cases directly
//
// auto seed = CommonCode::unsafe_create(GROUP_SEED[flat_id()]);
//
// // std::cout << seed << std::endl;
//
// auto codes = Group_extend(seed.to_raw_code(), size());
//
// // std::cout << codes.size() << std::endl;
//
// // TODO: how to reserve
//
// RangesUnion data;
//
// for (auto raw_code : codes) {
// auto common_code = raw_code.to_common_code().unwrap();
// data[common_code >> 32].emplace_back(static_cast<uint32_t>(common_code));
// }
//
// // TODO: do sort process
//
// for (int head = 0; head < 16; ++head) {
// std::stable_sort(data[head].begin(), data[head].end());
// }
//
// return data;
//}
//Group Group::from_raw_code(codec::RawCode raw_code) {
//
// auto raw_codes = Group_extend(raw_code);
//
// auto common_codes = raw_codes | std::views::transform([](const RawCode r) {
// return r.to_common_code();
// }) | std::ranges::to<std::vector>(); // TODO: search min_element directly
//
// auto seed = std::min_element(common_codes.begin(), common_codes.end());
//
// std::cout << *seed << std::endl;
//
// // TODO: search type_id / group_id from map
// auto flat_id = std::find(GROUP_SEED.begin(), GROUP_SEED.end(), *seed) - GROUP_SEED.begin();
// std::cout << flat_id << std::endl;
//
// return Group::unsafe_create(0, 0); // TODO: only for compile
//}

4
src/core/group/internal/group.cc

@ -12,6 +12,10 @@ using klotski::cases::GROUP_DATA;
using klotski::cases::PATTERN_DATA;
RangesUnion Group::cases() const {
// TODO: add white list for single-group unions
// return GroupUnion::cases directly
auto seed = CommonCode::unsafe_create(PATTERN_DATA[flat_id()] >> 23);
// NOTE: convert as RawCode directly

71
src/core/group/internal/load_factor.py

@ -1,71 +0,0 @@
#!/usr/bin/env python3
import re
# (type_id, pattern_id): (load_factor_a, coff, load_factor_b)
type data_type = dict[tuple[int, int], tuple[float, float, float]]
def load_data(lines: list[str]) -> data_type:
result = {}
key, items = (), []
for line in lines:
if line.startswith('['):
match = re.match(r'^\[(\d+), (\d+)]$', line)
key = (int(match[1]), int(match[2]))
elif not line:
assert len(key) == 2
assert items[0][0] == 1.0
if len(items) == 1:
assert items[0][1] < 0.1 # skip low cases
else:
assert len(items) == 2
result[key] = items[0][1], items[1][0], items[1][1]
key, items = (), []
else:
match = re.match(r'^(\d\.\d{2}), (\d\.\d{6})$', line)
items.append((float(match[1]), float(match[2])))
return result
def analyse_data(data: data_type) -> None:
data = {x: y for x, y in data.items() if y[0] >= 0.5}
times = set([int(x * 1000 / y) / 1000 for x, _, y in data.values()])
print(sorted(times))
type_a, type_b, type_c = [], [], []
for group, (load_factor, coff, _) in data.items():
if load_factor <= 0.55:
type_a.append((group, load_factor, coff))
elif coff <= 1.3:
type_b.append((group, load_factor, coff))
else:
type_c.append((group, load_factor, coff))
type_c = sorted(type_c, key=lambda x: x[2])
for item in type_c:
print(item)
# ((117, 0), 0.571359, 1.54) -> 4680
# ((118, 0), 0.571298, 1.54) -> 37440
# ((133, 0), 0.570803, 1.54) -> 149632
# ((134, 0), 0.570558, 1.54) -> 299136
# ((63, 0), 0.568915, 1.55) -> 582
# ((136, 0), 0.565568, 1.55) -> 296520
# ((112, 0), 0.563973, 1.56) -> 36960
# ((113, 0), 0.563969, 1.56) -> 73920
# ((197, 0), 0.714286, 1.6) -> 5
# ((197, 1), 0.714286, 1.6) -> 5
# ((197, 2), 0.714286, 1.6) -> 5
# ((197, 3), 0.714286, 1.6) -> 5
# ((197, 4), 0.714286, 1.6) -> 5
# ((197, 5), 0.714286, 1.6) -> 5
if __name__ == '__main__':
raw = open('load_factor.txt').read().splitlines()
analyse_data(load_data(raw))

21365
src/core/group/internal/load_factor.txt

File diff suppressed because it is too large

65
src/core/main.cc

@ -49,65 +49,10 @@ int main() {
const auto start = std::chrono::system_clock::now();
const auto code = CommonCode::unsafe_create(0x1A9BF0C00).to_raw_code();
// const auto code = CommonCode::unsafe_create(0x1A9BF0C00).to_raw_code();
// const auto code = CommonCode::unsafe_create(0x4FEA13400).to_raw_code();
// FastCal fc {code};
auto test_0 = [](const CommonCode code) {
std::cout << std::format("[{}]\n", code.to_string());
std::cout << "--------" << std::endl;
};
auto test_1 = [](const RawCode code) {
FastCal fc {code};
if (const auto solve = fc.solve(); solve.has_value()) {
std::cout << std::format("{} ({})\n",
solve.value().to_common_code().to_string(), fc.backtrack(solve.value()).size());
}
std::cout << "--------" << std::endl;
for (auto furthest : fc.furthest()) {
std::cout << std::format("{} ({})\n",
furthest.to_common_code().to_string(), fc.backtrack(furthest).size());
}
std::cout << "--------" << std::endl;
};
auto test_2 = [](const RawCode code) {
FastCal fc {code};
for (auto solve : fc.solve_multi()) {
std::cout << std::format("{} ({})\n",
solve.to_common_code().to_string(), fc.backtrack(solve).size());
}
std::cout << "--------" << std::endl;
for (auto furthest : fc.furthest()) {
std::cout << std::format("{} ({})\n",
furthest.to_common_code().to_string(), fc.backtrack(furthest).size());
}
std::cout << "--------" << std::endl;
};
auto test_3 = [](const RawCode code) {
for (FastCal fc {code}; auto furthest : fc.furthest()) {
std::cout << std::format("{} ({})\n",
furthest.to_common_code().to_string(), fc.backtrack(furthest).size());
}
std::cout << "--------" << std::endl;
};
// 149 / 154 / 159 / 164 / 169 / 174
const auto codes = GroupUnion::unsafe_create(174).cases().codes();
for (size_t index = 0; index < codes.size(); ++index) {
auto common_code = codes[index];
auto raw_code = common_code.to_raw_code();
test_0(common_code);
test_1(raw_code);
test_2(raw_code);
test_3(raw_code);
if (index % 100 == 0) {
std::cerr << index << "/" << codes.size() << std::endl;
}
}
// std::cout << fc.solve().value() << std::endl;
// for (const auto x : fc.solve_multi()) {
@ -124,14 +69,6 @@ int main() {
// }
// std::cout << "layer num: " << fc.exports().size() << std::endl;
// for (int i = 0; i < 10000000; ++i) {
// MaskMover mover([](uint64_t code, uint64_t mask) {
// volatile auto tmp_1 = code;
// volatile auto tmp_2 = mask;
// });
// mover.next_cases(0x1A9BF0C00, 0);
// }
// ShortCode::speed_up(true);
//
// std::unordered_set<RawCode> data_r;

19
verify/compare.py

@ -1,19 +0,0 @@
#!/usr/bin/env python3
import json
data_legacy = json.loads(open('legacy.json').read())
data_next = json.loads(open('data.json').read())
assert len(data_legacy) == len(data_next)
if __name__ == '__main__':
for info in data_legacy:
code = f'{info['code']}00'
info_next = data_next[code]
assert info['min_solution_step'] == info_next['min_step']
assert info['farthest_step'] == info_next['max_step']
assert info['min_solution_case'] == sorted([x[:7] for x in info_next['solutions']])
assert info['farthest_case'] == sorted([x[:7] for x in info_next['furthest']])

65
verify/extract.py

@ -1,65 +0,0 @@
#!/usr/bin/env python3
import re
import json
def split_item(raw: str) -> list[tuple[str, int]]:
assert raw[0] == '\n'
matched = [re.match(r'^([\dA-F]{9}) \((\d+)\)$', x) for x in raw[1:].splitlines()]
return [(x[1], int(x[2]) - 1) for x in matched]
def load_file(file_name: str) -> dict[str, dict]:
raw = open(file_name).read()
assert raw[0] == '['
assert raw[-1] == '\n'
result = {}
for item in raw[1:-1].split('\n['):
item = item.split('--------')
assert len(item) == 7
assert item[-1] == ''
assert item[2] == item[4]
assert item[2] == item[5]
code = re.match(r'^([\dA-F]{9})]\n$', item[0])[1]
min_solutions = split_item(item[1])
assert len(min_solutions) in [0, 1]
solutions = split_item(item[3])
assert len(set([x[1] for x in solutions])) in [0, 1]
assert len(set([x[0] for x in solutions])) == len(solutions)
if not min_solutions:
min_step = -1
assert len(solutions) == 0
else:
min_step = solutions[0][1]
assert min_solutions[0] in solutions
furthest = split_item(item[2])
assert len(set([x[1] for x in furthest])) == 1
assert len(set([x[0] for x in furthest])) == len(furthest)
result[code] = {
'min_step': min_step,
'max_step': furthest[0][1],
'solutions': [x[0] for x in solutions],
'furthest': [x[0] for x in furthest],
}
return result
def load_all(files: list[str]) -> dict[str, dict]:
data = {}
[data.update(load_file(x)) for x in files]
data = {x: data[x] for x in sorted(data)}
return data
if __name__ == '__main__':
content = json.dumps(load_all([
'data_149.txt', 'data_154.txt', 'data_159.txt',
'data_164.txt', 'data_169.txt', 'data_174.txt'
]))
print(content)
Loading…
Cancel
Save