Best Subset Solution
Concrete binary solution for the “best subset” problem, backed by jMetal’s BinarySet.
Highlights:
Construction helpers for fixed cardinality
K
or a random non‑empty mask.Readable accessors used across the project (
retrieveTopicStatus
,numberOfSelectedTopics
, …).Mirror field topicStatus kept for downstream writers (e.g.,
-Top
CSV).Delta‑evaluation scaffolding:
lastEvaluatedMask, cachedSumsBySystem (subset‑sum cache)
lastSwapOutIndex, lastSwapInIndex, lastMutationWasFixedKSwap (operator hooks)
Performance:
Cached genotype key (bitstring) with dirty tracking to avoid repeated builds.
Cached Base64 of the mask computed directly from BinarySet (no
BooleanArray
roundtrips).Reusable boolean buffer for lastEvaluatedMask to avoid per‑eval allocations.
Notes:
jMetal 6.x API uses
variables()
andobjectives()
lists.All randomness comes from the JMetalRandom singleton to preserve determinism when seeded.
Parameters
the number of variables (always 1 for this problem)
the number of objectives
number of topics (size of the binary mask)
human‑readable labels for topics; mirrored to copies
if non‑null, initialize with exactly this many bits set; otherwise random non‑empty
Constructors
Properties
Cached per‑system subset sums for incremental/delta evaluation.
Last evaluated mask snapshot (reused to avoid allocations).
Whether the last mutation was a fixed‑K swap.
Index swapped in by the last fixed‑K mutation (if any).
Index swapped out by the last fixed‑K mutation (if any).
Count of selected topics (bitset cardinality).
External mirror for writers (-Top
CSV, etc.).
Functions
Clears operator flags (swap info used by fixed‑K operators).
Deep copy preserving:
Returns a reusable buffer to persist the last evaluated mask without reallocations.
Friendly cardinality accessor (as Double
) used by writers/streams.
Returns the subset cardinality stored in the underlying BestSubsetSolution.
Returns the correlation objective stored in objectives()[1]
.
Returns the correlation objective stored in the underlying BestSubsetSolution.
Returns the string form of the variable bits without separators (e.g., "101001…"). Cached and rebuilt only when mutated.
Returns an unpadded Base64 of the current mask, computed directly from BinarySet and cached. Recomputed only when the genotype is marked dirty.
Clears delta‑evaluation caches (subset sums and last evaluated mask).
Returns the current topic mask as a primitive BooleanArray. This is faster for numeric loops than boxing/unboxing via Array.
Sets a single bit in the underlying BinarySet and marks caches dirty.