add frequency plot + fix error in one of the plots + make output bigger
This commit is contained in:
parent
87dfce723b
commit
8d5b9e2c2d
2 changed files with 44 additions and 17 deletions
|
|
@ -2,12 +2,12 @@ def make_plot_ships_script(priority:str, strategy:str, max_waits:list[float], ge
|
|||
return (f"""
|
||||
### priority={priority}, strategy={strategy} ###
|
||||
|
||||
set terminal svg
|
||||
set terminal svg size 1200 900
|
||||
|
||||
# plot 1. x-axis: ships, y-axis: queuing duration of ship
|
||||
|
||||
set out 'plot_ships_{strategy}_{priority}.svg'
|
||||
set title "Queueing duration"
|
||||
set title "Queueing duration (strategy={strategy}, priority={priority})"
|
||||
set xlabel "Ship #"
|
||||
set ylabel "Seconds"
|
||||
#unset xlabel
|
||||
|
|
@ -28,7 +28,7 @@ set xrange [0:{gen_num}]
|
|||
set style fill solid
|
||||
|
||||
plot 'output_{strategy}_{priority}.csv' \\\n """ + ", \\\n '' ".join([
|
||||
f"using 1:{i+1} title '{max_wait}' w boxes ls {i+1}"
|
||||
f"using 1:{i+2} title '{max_wait}' w boxes ls {i+1}"
|
||||
for i, max_wait in enumerate(max_waits)
|
||||
]))
|
||||
|
||||
|
|
@ -38,6 +38,7 @@ def make_plot_box_script(priority:str, strategy:str, max_waits:list[float], gen_
|
|||
# plot 2. x-axis: max-wait parameter, y-axis: queueing durations of ships
|
||||
|
||||
set out 'plot_box_{strategy}_{priority}.svg'
|
||||
set title "Queueing duration (strategy={strategy}, priority={priority})"
|
||||
set style fill solid 0.25 border -1
|
||||
set style boxplot outliers pointtype 7
|
||||
set style data boxplot
|
||||
|
|
@ -53,4 +54,33 @@ set xtics (""" + ', '.join([ f"'{max_wait}' {i}"
|
|||
plot 'output_{strategy}_{priority}.csv' \\\n """ + ", \\\n '' ".join([
|
||||
f"using ({i}):{i+2} title '{max_wait}'"
|
||||
for i, max_wait in enumerate(max_waits)
|
||||
]))
|
||||
]))
|
||||
|
||||
def make_plot_frequency_script(priority:str, strategy:str, max_waits:list[float], gen_num:int):
|
||||
return (f"""
|
||||
|
||||
# plot 3. x-axis: queueing duration interval, y-axis: number of ships
|
||||
|
||||
bin_width = 5*60;
|
||||
|
||||
set out 'plot_freq_{strategy}_{priority}.svg'
|
||||
set title "Frequency of queueing durations (strategy={strategy}, priority={priority})"
|
||||
set boxwidth (bin_width) absolute
|
||||
set style fill solid 1.0 noborder
|
||||
|
||||
set key title "Max Wait"
|
||||
set key bottom center out
|
||||
# set key horizontal
|
||||
|
||||
set xtics auto
|
||||
set xrange [0:]
|
||||
set xlabel "Queueing duration (interval)"
|
||||
set ylabel "Number of ships"
|
||||
|
||||
bin_number(x) = floor(x/bin_width)
|
||||
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
|
||||
|
||||
plot 'output_{strategy}_{priority}.csv' \\\n """ + ", \\\n '' ".join([
|
||||
f"using (rounded(${i+2})):(1) title '{max_wait}' smooth frequency with boxes"
|
||||
for i, max_wait in list(enumerate(max_waits))
|
||||
]))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
|
||||
from pypdevs.simulator import Simulator
|
||||
from plot_template import make_plot_ships_script, make_plot_box_script
|
||||
from plot_template import make_plot_ships_script, make_plot_box_script, make_plot_frequency_script
|
||||
|
||||
# from system_solution import * # Teacher's solution
|
||||
from system import *
|
||||
|
|
@ -42,6 +42,7 @@ outdir = "assignment_output"
|
|||
|
||||
plots_ships = []
|
||||
plots_box = []
|
||||
plots_freq = []
|
||||
|
||||
os.makedirs(outdir, exist_ok=True)
|
||||
|
||||
|
|
@ -88,18 +89,13 @@ for priority in priorities:
|
|||
raise Exception("There was an IndexError, meaning that fewer ships have made it to the sink than expected.\nYour model is not (yet) correct.") from e
|
||||
|
||||
# Generate gnuplot code:
|
||||
plots_ships.append(make_plot_ships_script(
|
||||
priority=priorities[priority],
|
||||
strategy=strategies[strategy],
|
||||
max_waits=max_wait_durations,
|
||||
gen_num=gen_num,
|
||||
))
|
||||
plots_box.append(make_plot_box_script(
|
||||
priority=priorities[priority],
|
||||
strategy=strategies[strategy],
|
||||
max_waits=max_wait_durations,
|
||||
gen_num=gen_num,
|
||||
))
|
||||
for f, col in [(make_plot_ships_script, plots_ships), (make_plot_box_script, plots_box), (make_plot_frequency_script, plots_freq)]:
|
||||
col.append(f(
|
||||
priority=priorities[priority],
|
||||
strategy=strategies[strategy],
|
||||
max_waits=max_wait_durations,
|
||||
gen_num=gen_num,
|
||||
))
|
||||
|
||||
# Finally, write out a single gnuplot script that plots everything
|
||||
with open(f'{outdir}/plot.gnuplot', 'w') as f:
|
||||
|
|
@ -107,3 +103,4 @@ with open(f'{outdir}/plot.gnuplot', 'w') as f:
|
|||
f.write('\n\n'.join(plots_ships))
|
||||
# then do the box plots
|
||||
f.write('\n\n'.join(plots_box))
|
||||
f.write('\n\n'.join(plots_freq))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue