BestSubsetSolution

class BestSubsetSolution(numberOfVariables: Int, numberOfObjectives: Int, numberOfTopics: Int, topicLabels: Array<String>, forcedCardinality: Int?) : DefaultBinarySolution

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() and objectives() lists.

  • All randomness comes from the JMetalRandom singleton to preserve determinism when seeded.

Parameters

numberOfVariables

the number of variables (always 1 for this problem)

numberOfObjectives

the number of objectives

numberOfTopics

number of topics (size of the binary mask)

topicLabels

human‑readable labels for topics; mirrored to copies

forcedCardinality

if non‑null, initialize with exactly this many bits set; otherwise random non‑empty

Constructors

Link copied to clipboard
constructor(numberOfVariables: Int, numberOfObjectives: Int, numberOfTopics: Int, topicLabels: Array<String>, forcedCardinality: Int?)

Properties

Link copied to clipboard

Cached per‑system subset sums for incremental/delta evaluation.

Link copied to clipboard

Last evaluated mask snapshot (reused to avoid allocations).

Link copied to clipboard

Whether the last mutation was a fixed‑K swap.

Link copied to clipboard

Index swapped in by the last fixed‑K mutation (if any).

Link copied to clipboard

Index swapped out by the last fixed‑K mutation (if any).

Link copied to clipboard

Count of selected topics (bitset cardinality).

Link copied to clipboard

External mirror for writers (-Top CSV, etc.).

Functions

Link copied to clipboard
open override fun attributes(): MutableMap<Any, Any>
Link copied to clipboard

Clears operator flags (swap info used by fixed‑K operators).

Link copied to clipboard
open override fun constraints(): DoubleArray
Link copied to clipboard
open override fun copy(): BestSubsetSolution

Deep copy preserving:

Link copied to clipboard
fun createNewBitSet(numBits: Int, genes: Array<Boolean>? = null): BinarySet

Creates a new BinarySet with numBits bits and, if provided, sets bits from genes. Marks caches dirty so callers can install the returned bitset into variables()[0].

Link copied to clipboard

Returns a reusable buffer to persist the last evaluated mask without reallocations.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Friendly cardinality accessor (as Double) used by writers/streams.

Link copied to clipboard
fun BinarySolution.getCardinality(): Double

Returns the subset cardinality stored in the underlying BestSubsetSolution.

Link copied to clipboard

Returns the correlation objective stored in objectives()[1].

Link copied to clipboard
fun BinarySolution.getCorrelation(): Double

Returns the correlation objective stored in the underlying BestSubsetSolution.

Link copied to clipboard
fun getVariableValueString(variableIndex: Int): String

Returns the string form of the variable bits without separators (e.g., "101001…"). Cached and rebuilt only when mutated.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns an unpadded Base64 of the current mask, computed directly from BinarySet and cached. Recomputed only when the genotype is marked dirty.

Link copied to clipboard
Link copied to clipboard
open override fun objectives(): DoubleArray
Link copied to clipboard

Clears delta‑evaluation caches (subset sums and last evaluated mask).

Link copied to clipboard

Returns the current topic mask as a primitive BooleanArray. This is faster for numeric loops than boxing/unboxing via Array.

Link copied to clipboard
fun setBitValue(bitIndex: Int, value: Boolean)

Sets a single bit in the underlying BinarySet and marks caches dirty.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun totalNumberOfBits(): Int
Link copied to clipboard
open override fun variables(): MutableList<BinarySet>