Browse Source

update: search group seed

legacy
Dnomd343 2 years ago
parent
commit
e7fb997fbe
  1. 76
      src/klotski_core/group/build_cases.cc
  2. 4
      src/klotski_core/group/group.h
  3. 18
      src/klotski_core/group/seeds.cc

76
src/klotski_core/group/build_cases.cc

@ -47,12 +47,16 @@ std::vector<CommonCode> Group::all_cases(const TypeId &type_id) {
return all_cases; return all_cases;
} }
absl::flat_hash_map<uint64_t, uint64_t> expansion(const RawCode &entry) { //absl::flat_hash_map<uint64_t, uint64_t> expansion(const RawCode &entry) {
//
//}
std::vector<RawCode> Group::group_cases(const RawCode &raw_code) {
std::queue<uint64_t> cache; std::queue<uint64_t> cache;
absl::flat_hash_map<uint64_t, uint64_t> cases; // <code, mask> absl::flat_hash_map<uint64_t, uint64_t> cases; // <code, mask>
cases.reserve(Group::group_max_size(entry)); cases.reserve(Group::group_max_size(raw_code));
cases.emplace(entry.unwrap(), 0); // without mask cases.emplace(raw_code.unwrap(), 0); // without mask
cache.emplace(entry.unwrap()); cache.emplace(raw_code.unwrap());
auto core = Core( auto core = Core(
[&cache, &cases](auto &&code, auto &&mask) { // callback function [&cache, &cases](auto &&code, auto &&mask) { // callback function
@ -69,11 +73,7 @@ absl::flat_hash_map<uint64_t, uint64_t> expansion(const RawCode &entry) {
core.next_cases(cache.front(), cases.find(cache.front())->second); core.next_cases(cache.front(), cases.find(cache.front())->second);
cache.pop(); // case dequeue cache.pop(); // case dequeue
} }
return cases;
}
std::vector<RawCode> Group::group_cases(const RawCode &raw_code) {
auto cases = expansion(raw_code);
auto result = std::vector<RawCode>(); auto result = std::vector<RawCode>();
result.reserve(cases.size()); result.reserve(cases.size());
for (auto &&tmp : cases) { // export group cases for (auto &&tmp : cases) { // export group cases
@ -86,27 +86,65 @@ std::vector<RawCode> Group::group_cases(const CommonCode &common_code) {
return group_cases(RawCode::from_common_code(common_code)); return group_cases(RawCode::from_common_code(common_code));
} }
CommonCode Group::group_seed(const RawCode &raw_code) {
// TODO: refactor build_group -> using GROUP_SEEDS // auto t = expansion(raw_code);
std::vector<CommonCode> Group::build_group(uint32_t type_id, uint32_t group_id) { //
// auto k = t.begin();
//
// auto cmp = [](const std::pair<uint64_t, uint64_t> &p1, const std::pair<uint64_t, uint64_t> &p2) {
// return RawCode::unsafe_create(p1.first).to_common_code() < RawCode::unsafe_create(p2.first).to_common_code();
// };
//
// return std::min_element(t.begin(), t.end(), cmp)->first;
auto offset = TYPE_ID_OFFSET[type_id];
std::cout << "size: " << TYPE_ID_GROUP_NUM[type_id] << std::endl; auto cases = group_cases(raw_code);
std::vector<CommonCode> group(cases.begin(), cases.end());
auto k = GROUP_SEEDS_INDEX[offset + group_id]; return *std::min_element(group.begin(), group.end());
std::cout << "tmp index: " << k << std::endl;
auto r = k + offset; // std::vector<CommonCode> group;
//
// for (auto &&tmp : expansion(raw_code)) {
// group.emplace_back(RawCode::unsafe_create(tmp.first).to_common_code());
// }
//
// return *std::min_element(group.begin(), group.end());
}
CommonCode Group::group_seed(const CommonCode &common_code) {
std::cout << "real index: " << r << std::endl; return group_seed(common_code.to_raw_code());
}
// TODO: refactor build_group -> using GROUP_SEEDS
std::vector<RawCode> Group::build_group(const GroupId &group_id) {
// auto offset = TYPE_ID_OFFSET[type_id];
//
// std::cout << "size: " << TYPE_ID_GROUP_NUM[type_id] << std::endl;
//
// auto k = GROUP_SEEDS_INDEX[offset + group_id];
//
// std::cout << "tmp index: " << k << std::endl;
//
// auto r = k + offset;
//
// std::cout << "real index: " << r << std::endl;
//
// auto seed = CommonCode(GROUP_SEEDS[r]);
//
// std::cout << "seed: " << seed << std::endl;
//
// std::cout << RawCode(seed) << std::endl;
auto seed = CommonCode(GROUP_SEEDS[r]); auto seed = group_seed(group_id);
std::cout << "seed: " << seed << std::endl; return group_cases(seed);
std::cout << RawCode(seed) << std::endl;
// uint32_t group_num = 0; // uint32_t group_num = 0;
// auto all_cases = Group::all_cases(type_id); // load all cases of type_id // auto all_cases = Group::all_cases(type_id); // load all cases of type_id

4
src/klotski_core/group/group.h

@ -79,9 +79,9 @@ class Group {
public: public:
/// ----------------------------------- group seeds ----------------------------------- /// ----------------------------------- group seeds -----------------------------------
static CommonCode group_seed(const GroupId &group_id);
static CommonCode group_seed(const RawCode &raw_code); static CommonCode group_seed(const RawCode &raw_code);
static CommonCode group_seed(const CommonCode &common_code); static CommonCode group_seed(const CommonCode &common_code);
static CommonCode group_seed(uint32_t type_id, uint32_t group_id);
/// Get all seeds in the specified type id. /// Get all seeds in the specified type id.
static std::vector<CommonCode> group_seeds(const TypeId &type_id); static std::vector<CommonCode> group_seeds(const TypeId &type_id);
@ -99,7 +99,7 @@ public:
static std::vector<std::vector<CommonCode>> build_groups(const TypeId &type_id); static std::vector<std::vector<CommonCode>> build_groups(const TypeId &type_id);
/// Calculate the specified group using type_id and group_id. /// Calculate the specified group using type_id and group_id.
static std::vector<CommonCode> build_group(uint32_t type_id, uint32_t group_id); static std::vector<RawCode> build_group(const GroupId &group_id);
/// ----------------------------------- group info ------------------------------------ /// ----------------------------------- group info ------------------------------------

18
src/klotski_core/group/seeds.cc

@ -8,15 +8,17 @@ namespace klotski {
CommonCode Group::group_seed(uint32_t type_id, uint32_t group_id) { CommonCode Group::group_seed(const GroupId &group_id) {
// TODO: check value // TODO: check value
auto type_id = group_id.type_id();
auto offset = TYPE_ID_OFFSET[type_id]; auto offset = TYPE_ID_OFFSET[type_id];
std::cout << "size: " << TYPE_ID_GROUP_NUM[type_id] << std::endl; std::cout << "size: " << TYPE_ID_GROUP_NUM[type_id] << std::endl;
auto k = GROUP_SEEDS_INDEX[offset + group_id]; auto k = GROUP_SEEDS_INDEX[offset + group_id.unwrap()];
std::cout << "tmp index: " << k << std::endl; std::cout << "tmp index: " << k << std::endl;
@ -38,18 +40,6 @@ std::vector<CommonCode> Group::group_seeds(const TypeId &type_id) {
return {offset, offset + TYPE_ID_GROUP_NUM[type_id.unwrap()]}; return {offset, offset + TYPE_ID_GROUP_NUM[type_id.unwrap()]};
} }
CommonCode Group::group_seed(const RawCode &raw_code) {
return CommonCode(0);
}
CommonCode Group::group_seed(const CommonCode &common_code) {
return CommonCode(0);
}
} // namespace klotski } // namespace klotski

Loading…
Cancel
Save