Commit 88acb958 authored by Julien Lin's avatar Julien Lin
Browse files

refactor code

parent df749e75
......@@ -14,6 +14,7 @@ d = 2
# Interface
########################################################################
def get_args_parser():
can = argparse.ArgumentParser()
......@@ -292,9 +293,9 @@ def run_algorithm(the, iters_func):
iters_func,
)
sensors = num.to_sensors(sol)
return val,sensors
return val, sol, sensors
def main(args=None):
can = get_args_parser()
......@@ -333,13 +334,21 @@ def main(args=None):
with open(the.solver + ".csv", "w") as fd:
fd.write("# {} {}\n".format(the.solver, the.domain_width))
val, sensors = run_algorithm(the, iters_func)
val, sol, sensors = run_algorithm(the, iters_func)
# Fancy output.
print("\n{} : {}".format(val, sensors))
shape = (the.domain_width, the.domain_width)
should_plot = False
if should_plot:
plot_sol(the, history, sensors, shape)
return val, len(history), sol, sensors
def plot_sol(the, history, sensors, shape):
fig = plt.figure()
if the.nb_sensors == 1 and the.domain_width <= 50:
......@@ -350,19 +359,12 @@ def main(args=None):
num.cover_sum,
domain_width=the.domain_width,
sensor_range=the.sensor_range,
dim=d * the.nb_sensors
dim=d * the.nb_sensors,
)
plot.surface(ax1, shape, f)
plot.path(ax1, shape, history)
else:
ax2 = fig.add_subplot(121)
ax3 = fig.add_subplot(122)
values = np.array([epoch[0] for epoch in history])
values = values >= the.quality_threshold
proba = values
ax3.step(np.arange(len(history)), proba)
domain = np.zeros(shape)
domain = pb.coverage(domain, sensors, the.sensor_range * the.domain_width)
......@@ -374,4 +376,4 @@ def main(args=None):
if __name__ == "__main__":
main()
\ No newline at end of file
main()
Supports Markdown
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