...
 
Commits (10)
......@@ -4,9 +4,12 @@
/conf*.json
/test.py
/problems/*
/problems-gen/*
!/problems/.gitkeep
/solutions/*
/solutions-gen/*
!/solutions/.gitkeep
/sds_trace_data.dat
# Byte-compiled / optimized / DLL files
......
Subproject commit a40846560bf682e7a6165ae50216c7bb49dccd26
Subproject commit 5535fc645b2138f1641b633fd17e7756bed5600a
......@@ -93,7 +93,11 @@ class Host(object):
def store_solution(self, solution):
if 'part_id' in solution:
request_id = solution['request_id']
if solution['status'] != 'done':
if request_id in self.request:
self.request[request_id].store_failed(solution)
return {'status': 'ignored'}
problem_key = solution['problem']
......@@ -102,14 +106,14 @@ class Host(object):
self.request[request_id].store_response(solution)
if problem_key in self.problems:
res = self.problems[problem_key].put_partial_solution(solution)
parts_valid = self.problems[problem_key].put_partial_solution(solution)
else:
res = False
parts_valid = False
print(solution['solution'])
print(solution['line_map'], solution['block_map'])
if res:
if parts_valid and self.request[request_id].is_receive_completed:
merge_problem = self.problems[problem_key].partial_merge_problem
# print(merge_problem)
merge_problem['request_id'] = solution['request_id']
......@@ -207,6 +211,9 @@ class Host(object):
return {}
elif cmd == 'cancel':
self.worker_manager.request_cancel(params)
_requests = self.problem_to_request[params['problem']]
for r in _requests:
self.request[r].cancel()
return {'status': 'canceled'}
elif cmd == 'worker/reset':
self.worker_manager.reset_worker(params['address'])
......@@ -364,7 +371,6 @@ class Worker(object):
class Request(object):
def __init__(self, worker_manager, data, worker, timeout=10000, merge_solvers=list()):
# self.worker_manager = worker_manager
self.data = data
self.timeout = timeout
......@@ -382,9 +388,11 @@ class Request(object):
if self.solver.partial_mode:
self.part_nums = len(data['group_problems'])
self.solved = [0 for v in range(self.part_nums + 1)]
# self.received = [0 for v in range(self.part_nums)]
else:
self.part_nums = 1
self.solved = [0]
# self.received = []
self.is_processed = False
......@@ -396,6 +404,14 @@ class Request(object):
data['merge_solvers'] = self.merge_solvers
return data
# @property
# def is_receive_completed(self):
# return all([v>0 for v in self.received])
@property
def is_receive_completed(self):
return all([v!=0 for v in self.solved[:-1]])
def get_id(self):
return self.request_id
......@@ -407,10 +423,25 @@ class Request(object):
if self.start_time is None:
self.start_time = time.time()
def cancel(self):
if self.solved[-1] == 0:
self.solved[-1] = -1
def store_failed(self, data):
self.response.append(data)
if 'part_id' in data:
idx = data['part_id']
self.solved[idx] = -1
if all([v!=0 for v in self.solved[:-1]]) and any([v<0 for v in self.solved[:-1]]):
self.solved[-1] = -1
self.done_time = time.time()
else:
self.solved[-1] = -1
self.done_time = time.time()
def store_response(self, data):
# worker = data['worker']
# self.response[worker].append(data)
# self.response[worker] = data
self.response.append(data)
print(data)
if 'part_id' in data:
......@@ -420,8 +451,9 @@ class Request(object):
self.solved[idx] = 1
else:
self.solved[idx] = -1
if all([v!=0 for v in self.solved]) and any([v<0 for v in self.solved]):
if all([v!=0 for v in self.solved[:-1]]) and any([v<0 for v in self.solved[:-1]]):
self.solved[-1] = -1
self.done_time = time.time()
else:
if data['status'] == 'done':
self.solved[-1] = 1
......@@ -443,10 +475,15 @@ class Request(object):
elif self.solved[-1] == -1:
if self.start_time is None:
self.start_time = time.time()
counter = sum([v!=0 for v in self.solved])
fail_counter = sum([v<0 for v in self.solved])
if self.done_time is None:
status = f'canceled ({counter}<!{fail_counter}>/{len(self.solved)} done)'
else:
elapsed_time = self.done_time - self.start_time
et_minutes = int(elapsed_time // 60)
et_seconds = int(elapsed_time % 60)
status = f'failed [{et_minutes}:{et_seconds:02}]'
status = f'failed ({counter}<!{fail_counter}>/{len(self.solved)} done) [{et_minutes}:{et_seconds:02}]'
else:
if self.solver.status == 'Not connected':
status = 'Not connected'
......@@ -455,7 +492,11 @@ class Request(object):
if len(self.solved) == 1:
status_mes = 'Running'
elif len(self.solved) > 1:
counter = sum([v>0 for v in self.solved])
counter = sum([v!=0 for v in self.solved])
fail_counter = sum([v<0 for v in self.solved])
if fail_counter > 0:
status_mes = f'{counter}<!{fail_counter}>/{len(self.solved)}'
else:
status_mes = f'{counter}/{len(self.solved)}'
if self.start_time is None:
......
Subproject commit 9f879d73c144da91c1fdb1ec7a5f514b2aaa481c
Subproject commit 8bab511f44f1a6cac261e31fe74caecbd16713da
Subproject commit c5899bf5318b356d841981f18b1794c41d173e9e
Subproject commit f1f703eb80c922560f8168e6cb856a11079d4916
Subproject commit 849bed357f03a753050aafbf429ed406bd354195
Subproject commit 7be869e7f22527c8496c6ac96b4801a2a5c5c4c7
Subproject commit efe5a32e55fb0436a22753f8e3e49cf25fb93c23
Subproject commit a1f4bafd374681503b490180a89e24da2341a948
......@@ -31,7 +31,7 @@
{% set tr_class = tr_class + ' submit-solution' if k == problem.best_solution else '' %}
{% set tr_class = tr_class + ' valid-solution' if v.is_valid_solution() else '' %}
<tr class="solution-detail-row {{tr_class}}" data-solution-id="{{k}}" data-problem="{{problem.name}}">
<td>{{v.timestamp_str}}</td>
<td>{{v.timestamp_str}} ({{v.request_id}})</td>
<td>{{v.worker}}</td>
<td>
{% if v.is_valid_solution() %}
......
......@@ -355,8 +355,11 @@ class Problem(object):
self.solutions[solution_id] = solution
if solution.status == 'done':
outdir = f"{self.solution_path}/{self.name}"
if not os.path.exists(outdir):
os.mkdir(outdir)
problem_path = self.path
solution_path = f'{self.solution_path}/{self.name}/tmp-{solution.request_id}-{solution.worker}.txt'
solution_path = f'{outdir}/tmp-{solution.request_id}-{solution.worker}.txt'
with open(solution_path, 'w') as fp:
fp.write(solution.solution)
......@@ -387,7 +390,6 @@ class Problem(object):
with open(outpath, 'w') as fp:
json.dump(self.get_dict(), fp, indent=4)
# print([len(v)>0 for v in self.partial_solutions])
if all([len(v)>0 for v in self.partial_solutions]):
return True
else:
......