elif shadow_type == "min": new_case.shadow = (repr_values == new_case.min_color()).astype(np.bool) elif shadow_type == "mesh": new_case.shadow = keep_mesh_array(repr_values) elif shadow_type == "ones": new_case.shadow = np.ones(repr_values.shape, dtype=np.bool) elif shadow_type == "problem_max": new_case.shadow = (repr_values == color).astype(np.bool) return new_case @classmethod def problem(cls, p: Problem, shadow_type: str) -> Problem: if shadow_type == "problem_max": max_color = (sum([c.color_count() for c in p.train_x_list])).argmax() # print(max_color) q: Problem = p.copy() q.train_x_list = [cls.case(c, shadow_type, max_color) for c in p.train_x_list] q.test_x_list = [cls.case(c, shadow_type, max_color) for c in p.test_x_list] else: q: Problem = p.copy() q.train_x_list = [cls.case(c, shadow_type) for c in p.train_x_list] q.test_x_list = [cls.case(c, shadow_type) for c in p.test_x_list] return q if __name__ == "__main__": pp = Problem.load(263, "eval") qq = Shadow.problem(pp, "problem_max") rr = Fractal.problem(qq) print(rr.eval_distance())
y_list = cls.case_create_flag(c_x, c_y, flag_color) c_ax: AbstractCase = AbstractCase(c_x) c_ax.y_list = y_list train_list.append(c_ax) for c_x in p.test_x_list: c_ax: AbstractCase = AbstractCase(c_x) test_list.append(c_ax) cls.auto_solve(train_list, test_list) q: Problem = p.copy() q.train_x_list = [ cls.case_fit(c, ca) for c, ca in zip(p.train_x_list, train_list) ] q.test_x_list = [ cls.case_fit(c, ca) for c, ca in zip(p.test_x_list, test_list) ] return q if __name__ == "__main__": pp = Problem.load(254, "eval") qq = MapConnect.problem(pp, allow_diagonal=True) rr = AutoKeep.problem(qq) print(rr.eval_distance()) pp = Problem.load(252, "eval") qq = MapColor.problem(pp) qq.history.append("color") rr = AutoKeep.problem(qq) print(rr)
return new_case @classmethod def problem(cls, p: Problem, allow_diagonal: bool = False, boundary_none: bool = False) -> Problem: q: Problem = p.copy() q.train_x_list = [ cls.case(c, allow_diagonal, boundary_none) for c in p.train_x_list ] q.test_x_list = [ cls.case(c, allow_diagonal, boundary_none) for c in p.test_x_list ] return q if __name__ == "__main__": xx = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]]) print(MapInterior.array(xx, False)) print(MapInterior.array(xx, True)) xx = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 0], [0, 0, 1]]) print(MapInterior.array(xx, False)) print(MapInterior.array(xx, True)) from src.operator.solver.dynamic.color.auto_paste_a import AutoPasteA pp = Problem.load(186) qq = MapInterior.problem(pp) rr = AutoPasteA.problem(qq) print(rr.eval_distance())
for i in range(res_arr.shape[0]): for j in range(res_arr.shape[1]): m = non_mesh_list[res_arr[i, j]] m_add = m.deepcopy() m_add.x0 = i * matter_shape[0] m_add.y0 = j * matter_shape[1] new_case.matter_list.append(m_add) return new_case @classmethod def problem(cls, p: Problem) -> Problem: q: Problem = p.copy() q.train_x_list = [cls.case(c) for c in p.train_x_list] q.test_x_list = [cls.case(c) for c in p.test_x_list] return q if __name__ == "__main__": x0_ = np.array([0, 0]) x1_ = np.array([1, 1]) y0_ = np.array([0, 2]) y1_ = np.array([1, 3]) c_ = np.array([4, 5]) res_arr_ = align_xy(x0_, y0_, x1_, y1_, c_) print(res_arr_) pp = Problem.load(158, "eval") qq = MapConnect.problem(pp, allow_diagonal=True) rr = Align.problem(qq) print(rr)
x_list = [ np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0]], dtype=np.int), np.array([[1, 0, 0], [0, 1, 0], [0, 2, 0]], dtype=np.int) ] y_list = [ np.array([[5, 5, 5], [5, 1, 5], [5, 2, 5]], dtype=np.int), np.array([[1, 5, 5], [5, 1, 5], [5, 2, 5]], dtype=np.int) ] import time t0 = time.time() print(find_replace_rule_33_one_all(x_list[0], y_list[0], 0)) print(time.time() - t0) t0 = time.time() rule_easy = find_replace_rule_33_all(x_list, y_list) print(time.time() - t0) print(rule_easy) print(fit_replace_rule_33_one_all(x_list[0], rule_easy, 0)) print(fit_replace_rule_33_one_all(x_list[1], rule_easy, 0)) pp = Problem.load(94) qq = FitRuleOne33All.problem(pp) print(qq) pp = Problem.load(265) qq = FitRuleOne33All.problem(pp) print(qq) pp = Problem.load(330) qq = FitRuleOne33All.problem(pp) print(qq)
Matter(new_values, background_color=c.background_color, new=True) ] return new_case @classmethod def problem(cls, p: Problem, full: bool = False) -> Problem: assert p.is_rot_symmetry q: Problem = p.copy() q.train_x_list = [cls.case(c, full) for c in p.train_x_list] q.test_x_list = [cls.case(c, full) for c in p.test_x_list] return q if __name__ == "__main__": import time pp = Problem.load(19) pp.is_rot_symmetry = True t0 = time.time() qq = AutoFillRotSymmetry.problem(pp) print(time.time() - t0) print(qq) pp = Problem.load(26) pp.is_rot_symmetry = True t0 = time.time() qq = AutoFillRotSymmetry.problem(pp) print(time.time() - t0) print(qq) pp = Problem.load(360) pp.is_rot_symmetry = True t0 = time.time() qq = AutoFillRotSymmetry.problem(pp)
import time x = np.array([[1, 2, 3], [4, 2, 3], [1, 0, 3]]) t0 = time.time() print(is_line_symmetry_row(x, 0)) print(time.time() - t0) t0 = time.time() print(is_line_symmetry_col(x, 0)) print(time.time() - t0) t0 = time.time() print(fill_symmetry_row(x, 0, 1, True)) print(time.time() - t0) x = np.array([[1, 2, 3], [4, 2, 3], [0, 0, 0], [0, 0, 0]]) print(is_line_symmetry_row(x, 0)) print(is_line_symmetry_col(x, 0)) print(fill_symmetry_row(x, 0, 1, False)) y = x.transpose() print(y) print(fill_symmetry_col(y, 0, 1, False)) pp = Problem.load(391, "eval") pp.is_line_symmetry_row = True pp.is_line_symmetry_col = True pp.color_delete = 9 for cc in pp.train_x_list: cc.color_delete = 9 for cc in pp.test_x_list: cc.color_delete = 9 print(pp) qq = AutoFillLineSymmetryDelete.problem(pp) print(qq) print(qq.eval_distance())
new_matter.set_values(duplicate_array(m.values, m.a, m.b)) new_matter.x0 = 0 new_matter.y0 = 0 return new_matter, m.a, m.b @classmethod def case(cls, c: Case) -> Case: assert len(c.matter_list) == 1 new_case: Case = c.copy() new_matter, m_row, m_col = cls.matter(c.matter_list[0], c.shape[0], c.shape[1]) new_case.matter_list = [new_matter] new_case.shape = c.shape[0] * m_row, c.shape[1] * m_col return new_case @classmethod def problem(cls, p: Problem) -> Problem: q: Problem = p.copy() q.train_x_list = [cls.case(c) for c in p.train_x_list] q.test_x_list = [cls.case(c) for c in p.test_x_list] return q if __name__ == "__main__": x = np.array([[1, 2], [3, 4]]) print(duplicate_array(x, 2, 3)) pp = Problem.load(251, "eval") qq = NColor.problem(pp) rr = DuplicateTransformer.problem(qq) print(rr)
for c_x, c_y in zip(p.train_x_list, p.train_y_list): x_arr = c_x.repr_values() y_arr = c_y.repr_values() new_y_arr, x0, x1, y0, y1, c = fusion_arr_train(x_arr, y_arr) # print(new_y_arr) # print(new_y_arr, x0, x1, y0, y1, c) q.train_x_list.append(cls.case_x(c_x, x0, x1, y0, y1)) q.train_y_list.append(cls.case_y(c_y, new_y_arr, x0, x1, y0, y1)) c_list.append(c) for c_x in p.test_x_list: x_arr = c_x.repr_values() c_suggest = c_list[0] x0, x1, y0, y1, c = fusion_arr_test(x_arr, c_suggest) q.test_x_list.append(cls.case_x(c_x, x0, x1, y0, y1)) # pre_solve again is_pattern.set_is_pattern(q) is_periodic.set_is_periodic_row(q) is_periodic.set_is_periodic_col(q) is_symmetry.set_is_line_symmetry_row(q) is_symmetry.set_is_line_symmetry_col(q) return q if __name__ == "__main__": pp = Problem.load(383, "eval") qq = Fusion.problem(pp) print(qq) print(qq.is_line_symmetry_row, qq.is_line_symmetry_col)
q: Problem = p.copy() flag, m_row, m_col = is_multiple(p) if flag: q.train_x_list = [ cls.case_m(c, m_row, m_col) for c in p.train_x_list ] q.test_x_list = [ cls.case_m(c, m_row, m_col) for c in p.test_x_list ] return q flag, n_row, n_col = is_constant(p) if flag: q.train_x_list = [ cls.case_n(c, n_row, n_col) for c in p.train_x_list ] q.test_x_list = [ cls.case_n(c, n_row, n_col) for c in p.test_x_list ] return q raise AssertionError if __name__ == "__main__": x = np.array([[1, 2], [3, 4]]) print(zoom_array(x, 2, 3)) pp = Problem.load(222) qq = ZoomSolver.problem(pp) print(qq)
@classmethod def matter(cls, m: Matter) -> bool: if m.is_filled_rectangle() and min(m.shape) >= 3: return True else: return False @classmethod def case(cls, c: Case) -> Case: m: Matter new_case = c.copy() new_case.matter_list = [m for m in c.matter_list if cls.matter(m)] assert len(new_case.matter_list) > 0 return new_case @classmethod def problem(cls, p: Problem) -> Problem: q: Problem = p.copy() q.train_x_list = [cls.case(c) for c in p.train_x_list] q.test_x_list = [cls.case(c) for c in p.test_x_list] return q if __name__ == "__main__": pp = Problem.load(11, "eval") qq = MapColorConnect.problem(pp, allow_diagonal=True) rr = RectangleKeeper.problem(qq) ss = CollectMax.problem(rr) print(ss)
rule_33 = find_replace_rule_33_all(x_arr_list, y_arr_list, p.background_color) q: Problem q = p.copy() q.train_x_list = [] q.test_x_list = [] c_x: Case c_x_new: Case for c_x in p.train_x_list: c_x_new = c_x.copy() new_values = fit_replace_rule_33_one_all(c_x.repr_values(), rule_33, p.background_color) c_x_new.matter_list = [Matter(new_values, background_color=p.background_color, new=True)] q.train_x_list.append(c_x_new) for c_x in p.test_x_list: c_x_new = c_x.copy() new_values = fit_replace_rule_33_one_all(c_x.repr_values(), rule_33, p.background_color) c_x_new.matter_list = [Matter(new_values, background_color=p.background_color, new=True)] q.test_x_list.append(c_x_new) return q if __name__ == "__main__": pp = Problem.load(378, "eval") print(pp.eval_distance()) qq = fit_replace_rule_33(pp) print(qq.eval_distance()) print(qq)
return new_case @classmethod def problem(cls, p: Problem, allow_diagonal: bool = False, boundary_none: bool = True) -> Problem: q: Problem = p.copy() q.train_x_list = [ cls.case(c, allow_diagonal, boundary_none) for c in p.train_x_list ] q.test_x_list = [ cls.case(c, allow_diagonal, boundary_none) for c in p.test_x_list ] return q if __name__ == "__main__": xx = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]]) print(MapInteriorPierce.array(xx, False)) print(MapInteriorPierce.array(xx, True)) xx = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 0], [0, 0, 1]]) print(MapInteriorPierce.array(xx, False)) print(MapInteriorPierce.array(xx, True)) from src.operator.solver.dynamic.color.auto_paste_a import AutoPasteA pp = Problem.load(119) qq = MapInteriorPierce.problem(pp) rr = AutoPasteA.problem(qq) print(rr.eval_distance())
return q @classmethod def problem(cls, p: Problem) -> Problem: t = 1 q = cls.problem_one(p) while t < 100: q = cls.problem_one(p) if p.__repr__() == q.__repr__(): break t += 1 return q if __name__ == "__main__": pp = Problem.load(177, "eval") print(pp) qq = DecisionTreeDirect.problem(pp) print(qq) rr = DecisionTreeDirect.problem(qq) print(rr) pp = Problem.load(179, "eval") qq = DecisionTreeDirect.problem(pp) print(qq) pp = Problem.load(185, "eval") qq = DecisionTreeDirect.problem(pp) print(qq) pp = Problem.load(192, "eval") qq = DecisionTreeDirect.problem(pp) print(qq)
# is_division -> any if not flag_n: new_values = base_values[i0 * q_row:(i0 + 1) * q_row, j0 * q_col:(j0 + 1) * q_col].copy() # is_constant -> 4 corners else: if i0 == 0 and j0 == 0: new_values = base_values[:q_row, :q_col].copy() elif i0 == 0 and j0 == 1: new_values = base_values[:q_row, -q_col:].copy() elif i0 == 1 and j0 == 0: new_values = base_values[-q_row:, :q_col].copy() else: new_values = base_values[-q_row:, -q_col:].copy() c_x_new = c_x.copy() c_x_new.shape = q_row, q_col c_x_new.matter_list = [ Matter(new_values, background_color=c_x.background_color, new=True) ] q.test_x_list.append(c_x_new) return q if __name__ == "__main__": pp = Problem.load(66) qq = divide(pp) print(qq)
def hand_pick(p: Problem) -> List[Problem]: q0: Problem = p.copy() q0.train_x_list = [hand_pick_case(c, 0) for c in p.train_x_list] q0.test_x_list = [hand_pick_case(c, 0) for c in p.test_x_list] q1: Problem = p.copy() q1.train_x_list = [hand_pick_case(c, 1) for c in p.train_x_list] q1.test_x_list = [hand_pick_case(c, 1) for c in p.test_x_list] q2: Problem = p.copy() q2.train_x_list = [hand_pick_case(c, 2) for c in p.train_x_list] q2.test_x_list = [hand_pick_case(c, 2) for c in p.test_x_list] return [q0, q1, q2] if __name__ == "__main__": pp = Problem.load(178, "eval") qq = MapConnect.problem(pp, allow_diagonal=True) rr = AutoPick.problem(qq) print(rr) pp = Problem.load(235, "eval") qq = MapConnect.problem(pp, allow_diagonal=True) rr = AutoPick.problem(qq) print(rr) pp = Problem.load(312, "eval") qq = MapConnect.problem(pp, allow_diagonal=True) rr = AutoPick.problem(qq) print(rr) pp = Problem.load(327, "eval") qq = MapConnect.problem(pp, allow_diagonal=True) rr = AutoPick.problem(qq) print(rr)
m: Matter new_case.matter_list = [ cls.matter(m, hole_type) for m in c.matter_list ] return new_case @classmethod def problem(cls, p: Problem, hole_type: str) -> Problem: q: Problem = p.copy() q.train_x_list = [cls.case(c, hole_type) for c in p.train_x_list] q.test_x_list = [cls.case(c, hole_type) for c in p.test_x_list] return q if __name__ == "__main__": xx = np.ones((9, 9), dtype=int) yy1 = xx.copy() yy1[1:-1, 1:-1] = 0 print(yy1) yy2 = xx.copy() yy2[1:-1:2, 1:-1:2] = 0 print(yy2) yy3 = xx.copy() yy3[1:-1:2, 1:-1:2] = 0 yy3[2:-1:2, 2:-1:2] = 0 print(yy3) pp = Problem.load(84) qq = MapConnect.problem(pp, allow_diagonal=True) rr = RectangleHole.problem(qq, "mesh") print(rr)
@classmethod def case(cls, c: Case) -> Case: m: Matter new_case = c.copy() max_a = -1000000 for m in c.matter_list: if m.is_mesh: continue assert m.a is not None max_a = max(m.a, max_a) new_case.matter_list = [ m for m in c.matter_list if m.a == max_a or m.is_mesh ] return new_case @classmethod def problem(cls, p: Problem) -> Problem: q: Problem = p.copy() q.train_x_list = [cls.case(c) for c in p.train_x_list] q.test_x_list = [cls.case(c) for c in p.test_x_list] return q if __name__ == "__main__": pp = Problem.load(58) qq = SplitMesh.problem(pp) rr = NCell.problem(qq) ss = MaxKeeper.problem(rr) tt = PasteColor.problem(ss, full=True) print(tt)
model_3 = BaggingClassifier( base_estimator=DecisionTreeClassifier(min_samples_leaf=2), n_estimators=10).fit(X3, Y3) p3 = get_problem_from_model(task_json, model_3, 3) p3.history.append("tree_3") return p3 elif size == 5: X5, Y5 = gettaskxy(task_json, True, 5, bl_cols, isflip) model_5 = BaggingClassifier( base_estimator=DecisionTreeClassifier(min_samples_leaf=2), n_estimators=10).fit(X5, Y5) p5 = get_problem_from_model(task_json, model_5, 5) p5.history.append("tree_5") return p5 if __name__ == "__main__": import time t0 = time.time() pp = Problem.load(35, "eval") qq = transform_tree(pp, 3) print(qq) print(qq.eval_distance()) rr = transform_tree(qq, 3) print(rr) print(rr.eval_distance()) ss = transform_tree(rr, 3) print(ss) print(ss.eval_distance()) print(time.time() - t0)
return z_arr @classmethod def case(cls, c: Case) -> Case: new_case = c.copy() x_arr = trivial_reducer(c) # print(x_arr) new_values = cls.array(x_arr) new_case.matter_list = [ Matter(new_values, background_color=c.background_color, new=True) ] new_case.shape = new_values.shape return new_case @classmethod def problem(cls, p: Problem) -> Problem: assert not is_same(p) q: Problem = p.copy() q.train_x_list = [cls.case(c) for c in p.train_x_list] q.test_x_list = [cls.case(c) for c in p.test_x_list] return q if __name__ == "__main__": x = np.array([[1, 2, 1, 1], [3, 4, 2, 2], [3, 4, 2, 2]]) print(DropDuplicates.array(x)) pp = Problem.load(314, "eval") qq = DropDuplicates.problem(pp) print(qq)