diff --git a/.gitignore b/.gitignore
index f3b14b2032fa6fc563276fa1dc680a69c29b9c0d..84bdf4533fff168b643d6575b6a2dc6c7248fba3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
# Project-specific files
/conf*.json
+/test.py
/problems/*
!/problems/.gitkeep
/solutions/*
diff --git a/templates/part_problems.html b/templates/part_problems.html
index 361b0ecde4db69bb00c69e727c31311a5cdaf310..3de937c8420a1905546f5a21818498727ea3613e 100644
--- a/templates/part_problems.html
+++ b/templates/part_problems.html
@@ -2,18 +2,30 @@
File Name |
- Size |
- #Blocks |
- Status |
+
+ Size
+ #B/#L/#G
+ |
+
+ Status |
{% for k, v in problems.items() %}
{{v.name}} |
- {{v.size_str}} |
- {{v.block_num}} |
- {{v.status}} |
+
+ {{v.size_str}}
+ {{v.block_num}} /
+ {{v.line_numbers | length - 1}} /
+ {{v.block_groups | length}}
+ |
+
+ {{v.status}} |
{% endfor %}
diff --git a/utils/data.py b/utils/data.py
index 418ace7d4cedd79b5f130def809de3d9b1fd7fd1..1ffec028b171009130b14d14dd4eda80f416a114 100644
--- a/utils/data.py
+++ b/utils/data.py
@@ -1,13 +1,14 @@
import datetime
import json
import os
+import queue
import re
import time
import uuid
class Problem(object):
- def __init__(self, problem_path, solution_path):
+ def __init__(self, problem_path, solution_path=None):
self.path = problem_path
self.name = ''
@@ -19,12 +20,44 @@ class Problem(object):
self.solutions = dict()
self.solution_path = solution_path
self.best_solution = None
+ self.line_numbers = list()
+ self.connection = tuple()
+ self.block_groups = list()
self._load_problem(problem_path)
@property
def size_str(self):
return f'{self.size[0]}X{self.size[1]}'
+
+ @property
+ def problem_text(self):
+
+ def intplus(v):
+ if v.isdecimal():
+ return int(v)
+ else:
+ return v
+
+ _text = ''
+
+ _text += f'SIZE {self.size_str}\n'
+ _text += f'BLOCK_NUM {self.block_num}\n'
+ _text += '\n'
+
+ for bi, block in self.blocks.items():
+ _text += f'BLOCK#{bi} {block["w"]}X{block["h"]}\n'
+ for cr in block['cells']:
+ for cci, cc in enumerate(cr):
+ if cci > 0:
+ _text += ','
+ if isinstance(cc, int) and cc > 0:
+ cc = self.line_numbers.index(cc)
+ _text += f'{cc}'
+ _text += '\n'
+ _text += '\n'
+
+ return _text
@property
def status(self):
@@ -64,6 +97,11 @@ class Problem(object):
else:
return v
+ line_number_list = [0]
+
+ block_to_line = dict()
+ line_to_block = dict()
+
li = 0
while li < len(q_lines):
_l = q_lines[li]
@@ -87,7 +125,25 @@ class Problem(object):
for _h in range(bh):
li += 1
_l = q_lines[li].strip()
- blocks[bi]['cells'].append([intplus(v.strip()) for v in _l.split(',')])
+ _block_row = []
+ for v in _l.split(','):
+ _line_num = intplus(v.strip())
+ if isinstance(_line_num, int) and _line_num > 0:
+ # Line number conversion
+ if not _line_num in line_number_list:
+ line_number_list.append(_line_num)
+ # _line_num = line_number_list.index(_line_num)
+
+ # Make connection list
+ if not bi in block_to_line:
+ block_to_line[bi] = list()
+ block_to_line[bi].append(_line_num)
+ if not _line_num in line_to_block:
+ line_to_block[_line_num] = list()
+ line_to_block[_line_num].append(bi)
+ _block_row.append(_line_num)
+ blocks[bi]['cells'].append(_block_row)
+ # blocks[bi]['cells'].append([intplus(v.strip()) for v in _l.split(',')])
li += 1
@@ -98,8 +154,58 @@ class Problem(object):
self.blocks = blocks
self.name = name
self.problem = q_text
+ self.line_numbers = line_number_list
+ self.connection = (line_to_block, block_to_line)
# self.status = 'Ready'
+ self._analyze_block_groups()
+
+ def _analyze_block_groups(self):
+
+ traversed_block = list()
+
+ line_to_block = self.connection[0]
+ block_to_line = self.connection[1]
+
+ block_groups = list()
+
+ for b in block_to_line.keys():
+
+ if b in traversed_block:
+ continue
+
+ traverse_block_queue = queue.Queue()
+ traverse_block_queue.put(b)
+
+ target_group_blocks = list()
+
+ while not traverse_block_queue.empty():
+
+ target_block = traverse_block_queue.get()
+ target_block_lines = block_to_line[target_block]
+
+ if target_block in traversed_block:
+ continue
+
+ traversed_block.append(target_block)
+ target_group_blocks.append(target_block)
+
+ for line in target_block_lines:
+ corresponding_blocks = line_to_block[line]
+ if corresponding_blocks[0] == target_block:
+ next_block = corresponding_blocks[1]
+ else:
+ next_block = corresponding_blocks[0]
+
+ if next_block in traversed_block:
+ continue
+ else:
+ traverse_block_queue.put(next_block)
+
+ block_groups.append(target_group_blocks)
+
+ self.block_groups = block_groups
+
def get_dict(self):
return {
'name': self.name,