Commit 346a70f7 authored by Kento HASEGAWA's avatar Kento HASEGAWA

Add a random seed to the solver arguments

parent edb15677
import argparse import argparse
import os import os
import random
import subprocess import subprocess
proc = None proc = None
...@@ -22,10 +23,8 @@ def solve(params): ...@@ -22,10 +23,8 @@ def solve(params):
# 必要な変数があるか確認 # 必要な変数があるか確認
assert('problem' in params) assert('problem' in params)
assert('timeout' in params)
problem = params['problem'] problem = params['problem']
timeout = params['timeout']
basedir = os.path.abspath(os.path.dirname(__file__)) basedir = os.path.abspath(os.path.dirname(__file__))
...@@ -33,7 +32,9 @@ def solve(params): ...@@ -33,7 +32,9 @@ def solve(params):
if os.path.exists(solution_filepath): if os.path.exists(solution_filepath):
os.remove(solution_filepath) os.remove(solution_filepath)
cmds = f'{basedir}/solver_soft/sim -o {solution_filepath}'.split() seed = random.randint(0, 2147483647) # seed: uint32_t <= 2147483647
cmds = f'{basedir}/solver_soft/sim -o {solution_filepath} -s {seed}'.split()
proc = subprocess.Popen( proc = subprocess.Popen(
cmds, cmds,
...@@ -43,20 +44,15 @@ def solve(params): ...@@ -43,20 +44,15 @@ def solve(params):
) )
try: try:
# outs, errs = proc.communicate()
proc.communicate(problem.encode()) proc.communicate(problem.encode())
status = 'done' status = 'done'
except Exception as ex: except Exception as ex:
status = 'failed' status = 'failed'
finally: finally:
returncode = proc.returncode returncode = proc.returncode
# outs = outs.decode()
# errs = errs.decode()
# print(outs)
# print(errs)
solution = '' solution = ''
if returncode == 0: # 10 when SAT if returncode == 0:
status = 'done' status = 'done'
if os.path.exists(solution_filepath): if os.path.exists(solution_filepath):
with open(solution_filepath, 'r') as fp: with open(solution_filepath, 'r') as fp:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment