@@ -107,12 +107,50 @@ def test_gqr_exact_constrainted_case1(data_random):
107107
108108 # Get ranked sensors from GQR
109109 sensors_GQR = GQR ().fit (x .T , idx_constrained = forbidden_sensors ,n_sensors = total_sensors ,n_const_sensors = exact_n_const_sensors , constraint_option = 'exact_n_const_sensors' ).get_sensors ()[:total_sensors ]
110+ assert sensors_GQR .intersection (forbidden_sensors ) == 3
111+
110112
111- # try to compare these using the validation metrics
113+ def test_gqr_max_constrained_case1 (data_random ):
114+ ## In this case we want to place a total of 10 sensors
115+ # with a constrained region that is allowed to have a maximum of 3 sensors
116+ # but 4 of the first 10 are in the constrained region
117+ x = data_random
118+ # unconstrained sensors (optimal)
119+ sensors_QR = QR ().fit (x .T ).get_sensors ()
120+ # exact number of sensors allowed in the constrained region
121+ total_sensors = 10
122+ max_n_const_sensors = 3
123+ forbidden_sensors = [8 ,5 ,2 ,6 ]
124+ totally_forbidden_sensors = [x for x in forbidden_sensors if x in sensors_QR ][:max_n_const_sensors ]
125+ totally_forbidden_sensors = [y for y in forbidden_sensors if y not in totally_forbidden_sensors ]
126+ costs = np .zeros (x .shape [1 ])
127+ costs [totally_forbidden_sensors ] = 100
128+ # Get ranked sensors
129+ sensors = CCQR (sensor_costs = costs ).fit (x .T ).get_sensors ()[:total_sensors ]
112130
113- ## TODO
114- def test_gqr_max_constrained ():
115- pass
131+ # Forbidden sensors should not be included
132+ chosen_sensors = set (sensors [: (x .shape [1 ] - len (totally_forbidden_sensors ))])
133+ assert chosen_sensors .isdisjoint (set (totally_forbidden_sensors ))
134+
135+
136+ # Get ranked sensors from GQR
137+ sensors_GQR = GQR ().fit (x .T , idx_constrained = forbidden_sensors ,n_sensors = total_sensors ,n_const_sensors = max_n_const_sensors , constraint_option = 'max_n_const_sensors' ).get_sensors ()[:total_sensors ]
138+ assert sensors_GQR .intersection (forbidden_sensors ) == 3
139+
140+ def test_gqr_predetermined_case1 (data_random ):
141+ ## In this case we want to place a total of 10 sensors
142+ # 2 of the sensors are predetermined by the user
143+ x = data_random
144+ # unconstrained sensors (optimal)
145+ sensors_QR = QR ().fit (x .T ).get_sensors ()
146+ # Predtermined sensors
147+ total_sensors = 10
148+ n_sensors_pre = 2
149+ predetermined_sensors = [8 ,5 ]
150+
151+ # Predetermined sensors shopuld be included
152+ # Get ranked sensors from GQR
153+ sensors_GQR = GQR ().fit (x .T , idx_constrained = predetermined_sensors ,n_sensors = total_sensors ,n_const_sensors = n_sensors_pre , constraint_option = 'predetermined' ).get_sensors ()[:total_sensors ]
154+ assert sensors_GQR .intersection (predetermined_sensors ) == 2
155+
116156
117- def test_gqr_radii_constrained ():
118- pass
0 commit comments