From 5aee3fb37b0a4b9d5967ef72b62b47e6007c2643 Mon Sep 17 00:00:00 2001 From: johann dreo Date: Mon, 16 Dec 2019 15:25:35 +0100 Subject: [PATCH] fix: number of dimensions --- sho/bit.py | 5 +++-- sho/num.py | 5 +++-- snp.py | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sho/bit.py b/sho/bit.py index 02cd5a4..28cced3 100644 --- a/sho/bit.py +++ b/sho/bit.py @@ -8,11 +8,12 @@ from . import x,y,pb # Objective functions ######################################################################## -def cover_sum(sol, domain_width, sensor_range): +def cover_sum(sol, domain_width, sensor_range, dim): """Compute the coverage quality of the given array of bits.""" assert(0 < sensor_range <= math.sqrt(2)) assert(0 < domain_width) - assert(len(sol)>0) + assert(dim > 0) + assert(len(sol) >= dim) domain = np.zeros((domain_width,domain_width)) sensors = to_sensors(sol) cov = pb.coverage(domain, sensors, sensor_range*domain_width) diff --git a/sho/num.py b/sho/num.py index dcdbffd..af14bd2 100644 --- a/sho/num.py +++ b/sho/num.py @@ -21,11 +21,12 @@ def to_sensors(sol): return sensors -def cover_sum(sol, domain_width, sensor_range): +def cover_sum(sol, domain_width, sensor_range, dim): """Compute the coverage quality of the given vector.""" assert(0 < sensor_range <= domain_width * math.sqrt(2)) assert(0 < domain_width) - assert(len(sol)>0) + assert(dim > 0) + assert(len(sol) >= dim) domain = np.zeros((domain_width,domain_width)) sensors = to_sensors(sol) cov = pb.coverage(domain, sensors, sensor_range*domain_width) diff --git a/snp.py b/snp.py index 2011f61..f7eb322 100644 --- a/snp.py +++ b/snp.py @@ -93,7 +93,8 @@ if __name__=="__main__": val,sol = algo.greedy( make.func(num.cover_sum, domain_width = the.domain_width, - sensor_range = the.sensor_range), + sensor_range = the.sensor_range, + dim = d * the.nb_sensors), make.init(num.rand, dim = d * the.nb_sensors, scale = the.domain_width), @@ -108,7 +109,8 @@ if __name__=="__main__": val,sol = algo.greedy( make.func(bit.cover_sum, domain_width = the.domain_width, - sensor_range = the.sensor_range), + sensor_range = the.sensor_range, + dim = d * the.nb_sensors), make.init(bit.rand, domain_width = the.domain_width, nb_sensors = the.nb_sensors),