mamut_routing_tools.campaign.select¶
Pick the subset that spans the feature space, subject to coverage quotas.
Two things have to be true of a benchmark that claims diversity, and they pull against each other:
Spread -- no two instances should be near-duplicates in feature space, and the extremes should be represented. That is a max-min (farthest-point) criterion on the z-scored descriptors.
Coverage -- every level of every design axis must appear often enough to be analysable. Seven demand distributions are useless if one of them shows up twice. Max-min alone will not deliver that: it chases outliers, and a whole level can sit in the middle of the cloud and never get picked.
So the greedy runs under residual-feasibility guards. Before each pick it asks, per quota, whether the remaining budget can still cover the outstanding minimums; when a quota becomes binding, the pick is restricted to candidates that reduce its deficit. A swap pass then improves the spread without letting any quota slip.
QuotaInfeasibleError
¶
Bases: ValueError
The pool cannot satisfy the quotas within the requested budget.
Quota
dataclass
¶
Quota(
name: str,
key: Callable[[EvaluatedCandidate], Hashable],
minimum: Mapping[Hashable, int] = (),
maximum: Mapping[Hashable, int] | None = None,
per_level_maximum: int | None = None,
)
A coverage requirement over one design axis.
key maps a candidate to the level it occupies (its demand type, its
city, its size bucket). minimum is how many of each level the selection
must end up with; maximum caps a level -- {city: 1} style caps are
written with :meth:per_level_maximum.
select_maxmin
¶
select_maxmin(
candidates: Sequence[EvaluatedCandidate],
k: int,
quotas: Sequence[Quota] = (),
*,
swap_passes: int = 2,
) -> list[EvaluatedCandidate]
k candidates spread over feature space and honouring every quota.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/campaign/select.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
diversity_report
¶
diversity_report(
selected: Sequence[EvaluatedCandidate],
pool: Sequence[EvaluatedCandidate],
quotas: Sequence[Quota] = (),
) -> dict[str, Any]
Coverage, spread and confounding of a selected set, as publishable data.
feature_correlation is the part worth reading first. If two descriptors
are strongly correlated across the selected set, the benchmark cannot
separate their effects on a solver, however wide its spread looks.
Source code in MAMUT-routing-tools/src/mamut_routing_tools/campaign/select.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |