Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2019-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
adc2019
adc2019-system
Commits
72e19f13
Commit
72e19f13
authored
Aug 21, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a queue to the solver worker
parent
fb0ef6af
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
10 deletions
+36
-10
solver.py
roles/solver.py
+36
-10
No files found.
roles/solver.py
View file @
72e19f13
...
@@ -6,6 +6,8 @@ import sys
...
@@ -6,6 +6,8 @@ import sys
import
time
import
time
import
threading
import
threading
from
collections
import
OrderedDict
class
Solver
(
object
):
class
Solver
(
object
):
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
...
@@ -15,7 +17,13 @@ class Solver(object):
...
@@ -15,7 +17,13 @@ class Solver(object):
self
.
address
=
config
[
'address'
]
self
.
address
=
config
[
'address'
]
self
.
name
=
config
[
'name'
]
self
.
name
=
config
[
'name'
]
self
.
solver
=
importlib
.
import_module
(
f
"solvers.{config['solver']}"
)
self
.
solver
=
importlib
.
import_module
(
f
"solvers.{config['solver']}"
)
self
.
thread
=
None
self
.
queue
=
OrderedDict
()
self
.
status
=
'Ready'
# self.thread = None
self
.
thread
=
threading
.
Thread
(
name
=
'solver'
,
target
=
self
.
solver_thread
,
daemon
=
True
)
self
.
thread
.
start
()
def
__del__
(
self
):
def
__del__
(
self
):
self
.
stop_solver
()
self
.
stop_solver
()
...
@@ -23,6 +31,18 @@ class Solver(object):
...
@@ -23,6 +31,18 @@ class Solver(object):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Solver"
return
"Solver"
def
solver_thread
(
self
):
while
True
:
if
len
(
self
.
queue
)
>
0
:
print
(
"I: Solver started"
)
self
.
status
=
'running'
_
,
params
=
self
.
queue
.
popitem
(
last
=
False
)
self
.
solve
(
params
)
else
:
self
.
status
=
'ready'
time
.
sleep
(
0.5
)
def
solve
(
self
,
params
):
def
solve
(
self
,
params
):
start_time
=
time
.
time
()
start_time
=
time
.
time
()
...
@@ -35,7 +55,7 @@ class Solver(object):
...
@@ -35,7 +55,7 @@ class Solver(object):
solution
[
'elapsed_time'
]
=
elapsed_time
solution
[
'elapsed_time'
]
=
elapsed_time
self
.
submit_solution
(
params
,
solution
)
self
.
submit_solution
(
params
,
solution
)
self
.
thread
=
None
#
self.thread = None
return
True
return
True
def
post
(
self
,
path
,
data
):
def
post
(
self
,
path
,
data
):
...
@@ -57,14 +77,18 @@ class Solver(object):
...
@@ -57,14 +77,18 @@ class Solver(object):
def
start_solver
(
self
,
params
):
def
start_solver
(
self
,
params
):
if
self
.
thread
is
None
:
# if self.thread is None:
print
(
"I: Solver started"
)
# print("I: Solver started")
# self.thread = StoppableThread(target=self.solve, args=(params, ))
# self.thread = threading.Thread(name='solver', target=self.solve, args=(params, ), daemon=True)
self
.
thread
=
threading
.
Thread
(
name
=
'solver'
,
target
=
self
.
solve
,
args
=
(
params
,
),
daemon
=
True
)
# self.thread.start()
self
.
thread
.
start
()
# return {'status': 'started'}
return
{
'status'
:
'started'
}
# else:
else
:
# return {'status': 'busy'}
return
{
'status'
:
'busy'
}
print
(
"I: Problem queued"
)
_id
=
params
[
'request_id'
]
self
.
queue
[
_id
]
=
params
return
{
'status'
:
'queued'
}
def
stop_solver
(
self
):
def
stop_solver
(
self
):
...
@@ -80,5 +104,7 @@ class Solver(object):
...
@@ -80,5 +104,7 @@ class Solver(object):
return
self
.
start_solver
(
params
)
return
self
.
start_solver
(
params
)
elif
cmd
==
'stop'
:
elif
cmd
==
'stop'
:
return
self
.
stop_solver
()
return
self
.
stop_solver
()
elif
cmd
==
'status'
:
return
self
.
status
else
:
else
:
return
None
return
None
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment