...
 
Commits (9)
/*.txt
solver_soft/sim
### https://raw.github.com/github/gitignore/9d7ff09c7d38dce9ef03e7ea4dc908a622546757/C.gitignore
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
### https://raw.github.com/github/gitignore/9d7ff09c7d38dce9ef03e7ea4dc908a622546757/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
import argparse
import os
import random
import subprocess
import uuid
proc = None
stop_flag = False
def stop():
global proc
global stop_flag
stop_flag = True
if not proc is None:
proc.terminate()
print('stopped')
def solve(params):
global proc
global stop_flag
stop_flag = False
# 必要な変数があるか確認
assert('problem' in params)
problem = params['problem']
basedir = os.path.abspath(os.path.dirname(__file__))
aid = str(uuid.uuid4())
solution_filepath = f'{basedir}/A{aid}.txt'
if os.path.exists(solution_filepath):
os.remove(solution_filepath)
seed = random.randint(0, 2147483647) # seed: uint32_t <= 2147483647
cmds = f'{basedir}/solver_soft/sim -o {solution_filepath} -s {seed}'.split()
proc = subprocess.Popen(
cmds,
stdin=subprocess.PIPE,
# stderr=subprocess.PIPE,
# stdout=subprocess.PIPE
)
try:
proc.communicate(problem.encode())
status = 'done'
except Exception as ex:
status = 'failed'
finally:
returncode = proc.returncode
solution = ''
if returncode == 0:
status = 'done'
if os.path.exists(solution_filepath):
with open(solution_filepath, 'r') as fp:
solution = fp.read()
else:
status = 'failed'
else:
status = 'failed'
return {
'status': status,
'solution': solution
}
def main(args):
with open(args['problem'], 'r') as fp:
problem = fp.read()
params = {
'problem': problem,
'timeout': args['timeout']
}
ret = solve(params)
print(ret)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Wrapper Script for ADC2019 Solver')
parser.add_argument('problem', type=str, help='File path to the problem file')
parser.add_argument('-t', '--timeout', type=int, default=10, help='Timeout for the process of the solver')
args = vars(parser.parse_args())
main(args)
import argparse
import os
import random
import subprocess
import uuid
proc = None
stop_flag = False
def stop():
global proc
global stop_flag
stop_flag = True
if not proc is None:
proc.terminate()
print('stopped')
def solve(params):
global proc
global stop_flag
stop_flag = False
# 必要な変数があるか確認
assert('problem' in params)
problem = params['problem']
basedir = os.path.abspath(os.path.dirname(__file__))
pid = str(uuid.uuid4())
problem_filepath = f'{basedir}/P{pid}.txt'
with open(problem_filepath, 'w') as fp:
fp.write(problem)
aid = str(uuid.uuid4())
solution_filepath = f'{basedir}/A{aid}.txt'
if os.path.exists(solution_filepath):
os.remove(solution_filepath)
seed = random.randint(0, 2147483647) # seed: uint32_t <= 2147483647
cmds = f'python3 {basedir}/scripts/main.py -p {problem_filepath} -s {seed} -o {solution_filepath}'.split()
proc = subprocess.Popen(
cmds,
stdin=subprocess.PIPE,
# stderr=subprocess.PIPE,
# stdout=subprocess.PIPE
)
try:
proc.communicate(problem.encode())
status = 'done'
except Exception as ex:
status = 'failed'
finally:
returncode = proc.returncode
solution = ''
if returncode == 0:
status = 'done'
if os.path.exists(solution_filepath):
with open(solution_filepath, 'r') as fp:
solution = fp.read()
else:
status = 'failed'
else:
status = 'failed'
return {
'status': status,
'solution': solution
}
def main(args):
with open(args['problem'], 'r') as fp:
problem = fp.read()
params = {
'problem': problem,
'timeout': args['timeout']
}
ret = solve(params)
print(ret)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Wrapper Script for ADC2019 Solver')
parser.add_argument('problem', type=str, help='File path to the problem file')
parser.add_argument('-t', '--timeout', type=int, default=10, help='Timeout for the process of the solver')
args = vars(parser.parse_args())
main(args)
import numpy as np import numpy as np
from argparse import ArgumentParser from argparse import ArgumentParser
import sys
import time import time
import mySolverModule import mySolverModule
...@@ -91,7 +92,7 @@ def main(args): ...@@ -91,7 +92,7 @@ def main(args):
if mmio.read(0x10) == 0: if mmio.read(0x10) == 0:
print('Fail routing m(_ _)m') print('Fail routing m(_ _)m')
return # End function sys.exit(1)
W_ext = np.zeros((1,), dtype=np.int16) W_ext = np.zeros((1,), dtype=np.int16)
H_ext = np.zeros((1,), dtype=np.int16) H_ext = np.zeros((1,), dtype=np.int16)
...@@ -105,9 +106,11 @@ def main(args): ...@@ -105,9 +106,11 @@ def main(args):
if W_ext[0] > info['W'][0] or H_ext[0] > info['H'][0]: if W_ext[0] > info['W'][0] or H_ext[0] > info['H'][0]:
print('Fail satisfying constraint T_T') print('Fail satisfying constraint T_T')
sys.exit(1)
else: else:
print('Satisfy constraint ^_^') print('Satisfy constraint ^_^')
if args['output'] is not None: mySolverModule.output_to_file(args['output'], W_ext[0], H_ext[0], info['blocks'][0], info['line_num'][0], info['block_info'], result) if args['output'] is not None: mySolverModule.output_to_file(args['output'], W_ext[0], H_ext[0], info['blocks'][0], info['line_num'][0], info['block_info'], result)
sys.exit(0)
if __name__ == '__main__': if __name__ == '__main__':
......