Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
schedgen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Pour rappel, le service sera inaccessible ce lundi 05/05/25 midi pour raison de mise à jour.
Show more breadcrumbs
veriT
schedgen
Commits
85e5cc91
Commit
85e5cc91
authored
3 years ago
by
Hans-Jörg
Browse files
Options
Downloads
Patches
Plain Diff
Refactor simulation to use dedicated class
parent
814d5216
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
schedgen/opt/simulate.py
+42
-0
42 additions, 0 deletions
schedgen/opt/simulate.py
schedgen/schedgen-optimize.py
+20
-26
20 additions, 26 deletions
schedgen/schedgen-optimize.py
schedgen/schedgen-simulate.py
+3
-28
3 additions, 28 deletions
schedgen/schedgen-simulate.py
with
65 additions
and
54 deletions
schedgen/opt/simulate.py
0 → 100755
+
42
−
0
View file @
85e5cc91
#!/usr/bin/env python3
import
numpy
as
np
def
runtime
(
schedule
,
frame
,
timeout
):
result
=
simulate
(
schedule
,
frame
,
timeout
=
timeout
)
total
=
len
(
result
)
result
=
result
.
loc
[
result
<
float
(
"
inf
"
)]
return
(
len
(
result
),
total
,
result
.
sum
())
def
simulate
(
schedule
,
frame
,
timeout
=
None
,
mu
=
0
,
sigma
=
0
,
seed
=
None
):
exps
=
frame
.
copy
()
rng
=
np
.
random
.
default_rng
(
seed
)
sc
=
"
solved
"
# Find a unique name
while
sc
in
exps
.
columns
:
sc
=
sc
+
"
_
"
exps
[
sc
]
=
float
(
"
inf
"
)
time
=
0.0
for
strategy_time
,
strategy
in
schedule
:
jitter
=
rng
.
normal
(
mu
,
sigma
,
exps
.
shape
[
0
])
solved
=
(
exps
[
strategy
]
+
jitter
).
loc
[
(
exps
[
strategy
]
+
jitter
)
<=
strategy_time
]
solving_time
=
solved
.
clip
(
0.0
)
+
time
solving_time
.
name
=
sc
time
=
time
+
strategy_time
update_idx
=
exps
.
loc
[
exps
[
sc
]
==
float
(
"
inf
"
)].
index
.
intersection
(
solved
.
index
)
exps
.
update
(
solving_time
.
loc
[
update_idx
])
if
timeout
:
exps
[
sc
].
loc
[
exps
[
sc
]
>
timeout
]
=
float
(
"
inf
"
)
return
exps
[
sc
]
This diff is collapsed.
Click to expand it.
schedgen/schedgen-optimize.py
+
20
−
26
View file @
85e5cc91
...
...
@@ -9,6 +9,7 @@ from schedgen.opt.schedule import (
read_from_file
,
)
from
schedgen.opt.order
import
OptimizeOrder
from
schedgen.opt.simulate
import
runtime
from
schedgen.opt.helper
import
message
,
file_or_dir_path
,
new_file_path
,
file_path
from
schedgen.parsers.gridtpt
import
GridTPT
from
schedgen.parsers.csvresult
import
CSVResult
...
...
@@ -137,19 +138,15 @@ args_parser.add_argument(
)
def
writeScript
(
outFile
,
logics
,
schedule
,
seconds
=
False
):
def
writeScript
(
outFile
,
logics
,
schedule
,
timeout
,
seconds
=
False
):
message
(
f
"
Writing schedule to
{
outFile
}
.
"
,
logics
)
with
open
(
outFile
,
"
w
"
)
as
af
:
if
len
(
logics
)
==
1
:
af
.
write
(
f
"
{
logics
[
0
]
}
)
\n
"
)
else
:
af
.
write
(
f
"
{
logics
}
)
\n
"
)
optimizer
=
OptimizeOrder
(
r
.
frame
)
(
_
,
time
,
solved
)
=
optimizer
.
runtime
(
schedule
)
num_solved
=
solved
.
sum
()
af
.
write
(
f
"
# Prediction:
{
num_solved
}
/
{
solved
.
count
()
}
in
{
time
:
.
2
f
}
s
\n
"
)
(
solved
,
out_of
,
in_time
)
=
runtime
(
schedule
,
r
.
frame
,
timeout
)
af
.
write
(
f
"
# Prediction:
{
solved
}
/
{
out_of
}
in
{
in_time
:
.
2
f
}
s
\n
"
)
for
i
in
range
(
len
(
schedule
)
-
1
):
(
t
,
e
)
=
schedule
[
i
]
if
seconds
:
...
...
@@ -171,9 +168,9 @@ def writeCSV(outFile, logics, schedule):
af
.
write
(
f
"
{
t
:
.
3
f
}
;
{
e
}
\n
"
)
def
writeSchedule
(
outFile
,
logics
,
full
,
schedule
,
seconds
=
False
):
def
writeSchedule
(
outFile
,
logics
,
full
,
schedule
,
timeout
,
seconds
=
False
):
if
full
:
writeScript
(
outFile
,
logics
,
schedule
,
seconds
)
writeScript
(
outFile
,
logics
,
schedule
,
timeout
,
seconds
)
else
:
writeCSV
(
outFile
,
logics
,
schedule
)
...
...
@@ -295,12 +292,12 @@ if __name__ == "__main__":
longest
=
time_slices
[
-
1
]
message
(
f
"
For
{
t
:
.
2
f
}
s
\t
'
{
best_opt
}
'"
,
logics
)
order_optimizer
=
OptimizeOrder
(
exps
)
_
,
best_time
,
best_solves
=
order_optimizer
.
runtime
([(
longest
,
best_opt
)])
best_count
=
best_solves
.
sum
()
(
best_count
,
_
,
best_time
)
=
runtime
(
[(
longest
,
best_opt
)],
r
.
frame
,
timeout
)
message
(
f
"
This solves
{
best_count
}
in
{
best_time
}
s.
"
,
logics
)
for
e
in
exps
:
_
,
time
,
solves
=
order_optimizer
.
runtime
([(
longest
,
e
)])
new_count
=
solves
.
sum
()
(
new_count
,
_
,
time
)
=
runtime
([(
longest
,
e
)],
r
.
frame
,
timeout
)
if
new_count
>
best_count
:
message
(
"
Something went wrong: optimizer returned a better schedule.
"
,
...
...
@@ -313,7 +310,6 @@ if __name__ == "__main__":
message
(
"
The best schedule is:
"
,
logics
)
message
(
f
"
Run
\t
'
{
best_opt
}
'"
,
logics
)
message
(
f
"
This solves
{
best_count
}
in
{
best_time
}
s.
"
,
logics
)
after_solved
=
best_solves
after_count
=
best_count
after_total_time
=
best_time
best_schedule
=
[(
t
,
best_opt
)]
...
...
@@ -324,14 +320,11 @@ if __name__ == "__main__":
order_optimizer
=
OptimizeOrder
(
exps
)
(
before_wait
,
before_total_time
,
before_solved
,
)
=
order_optimizer
.
runtime
(
schedule
)
before_count
=
before_solved
.
value_counts
().
loc
[
True
]
(
before_count
,
total_count
,
before_total_time
)
=
runtime
(
schedule
,
r
.
frame
,
timeout
)
message
(
f
"
Current schedule solves
{
before_count
}
/
{
before_solved
.
count
()
}
in
{
before_total_time
:
.
2
f
}
s.
"
,
f
"
Current schedule solves
{
before_count
}
/
{
total_
count
}
in
{
before_total_time
:
.
2
f
}
s.
"
,
logics
,
)
...
...
@@ -349,12 +342,11 @@ if __name__ == "__main__":
message
(
"
\n
Tweaked schedule:
"
,
logics
)
for
(
t
,
e
)
in
best_schedule
:
message
(
f
"
For
{
t
:
.
2
f
}
s
\t
'
{
e
}
'"
,
logics
)
after_
wait
,
after_
total_
time
,
after_
solved
=
order_optimizer
.
runtime
(
best_schedule
(
after_
count
,
total_
count
,
after_
total_time
)
=
runtime
(
best_schedule
,
r
.
frame
,
timeout
)
after_count
=
after_solved
.
value_counts
().
loc
[
True
]
message
(
f
"
This schedule solves
{
after_count
}
/
{
after_solved
.
count
()
}
in
{
after_total_time
:
.
2
f
}
s.
"
,
f
"
This schedule solves
{
after_count
}
/
{
total_
count
}
in
{
after_total_time
:
.
2
f
}
s.
"
,
logics
,
)
...
...
@@ -365,6 +357,8 @@ if __name__ == "__main__":
full_schedule
=
best_schedule
if
args
.
result
:
writeSchedule
(
args
.
result
,
logics
,
args
.
full
,
full_schedule
,
args
.
seconds_out
)
writeSchedule
(
args
.
result
,
logics
,
args
.
full
,
full_schedule
,
timeout
,
args
.
seconds_out
)
message
(
"
All done.
"
,
logics
)
This diff is collapsed.
Click to expand it.
schedgen/schedgen-simulate.py
+
3
−
28
View file @
85e5cc91
...
...
@@ -6,6 +6,7 @@ import numpy as np
from
datetime
import
datetime
from
schedgen.opt.schedule
import
read_from_file
from
schedgen.opt.helper
import
message
,
file_or_dir_path
,
new_file_path
,
file_path
from
schedgen.opt.simulate
import
simulate
from
schedgen.parsers.gridtpt
import
GridTPT
from
schedgen.parsers.csvresult
import
CSVResult
...
...
@@ -161,35 +162,9 @@ if __name__ == "__main__":
pre_schedule
=
None
pre_schedule
=
read_from_file
(
args
.
schedule
)
sc
=
"
solved
"
# Find a unique name
while
sc
in
exps
.
columns
:
sc
=
sc
+
"
_
"
exps
[
sc
]
=
float
(
"
inf
"
)
time
=
0.0
rng
=
np
.
random
.
default_rng
(
args
.
seed
)
# Some pandas magic to do the simulation
for
strategy_time
,
strategy
in
pre_schedule
:
jitter
=
rng
.
normal
(
args
.
mu
,
args
.
sigma
,
exps
.
shape
[
0
])
solved
=
(
exps
[
strategy
]
+
jitter
).
loc
[
(
exps
[
strategy
]
+
jitter
)
<=
strategy_time
]
solving_time
=
solved
.
clip
(
0.0
)
+
time
solving_time
.
name
=
sc
time
=
time
+
strategy_time
update_idx
=
exps
.
loc
[
exps
[
sc
]
==
float
(
"
inf
"
)].
index
.
intersection
(
solved
.
index
)
exps
.
update
(
solving_time
.
loc
[
update_idx
])
if
timeout
:
exps
[
sc
].
loc
[
exps
[
sc
]
>
timeout
]
=
float
(
"
inf
"
)
result
=
simulate
(
pre_schedule
,
exps
,
timeout
,
args
.
mu
,
args
.
sigma
,
args
.
seed
)
message
(
"
Writing output.
"
,
logics
)
writeResult
(
args
,
exps
[
sc
]
)
writeResult
(
args
,
result
)
message
(
"
All done.
"
,
logics
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment