MOEA Framework 2.12
API Specification

org.moeaframework.core.variable
Class Subset

java.lang.Object
  extended by org.moeaframework.core.variable.Subset
All Implemented Interfaces:
Serializable, Variable

public class Subset
extends Object
implements Variable

Decision variable for fixed-size subsets. Use a BinaryVariable for variable-size subsets.

See Also:
Serialized Form

Constructor Summary
Subset(int k, int n)
          Constructs a new decision variable for representing subsets of size k from a set of size n.
 
Method Summary
 Subset copy()
          Returns an independent copy of this decision variable.
 boolean equals(Object obj)
           
 void fromArray(int[] members)
          Populates this subset from an array.
 int get(int index)
          Gets the member of this subset at the given index.
 int getK()
          Returns the fixed size of this subset.
 int getN()
          The size of the original set.
 Set<Integer> getSet()
          Returns the membership in this subset as an unmodifiable set.
 int hashCode()
           
 void randomize()
          Randomly assign the value of this variable.
 int randomNonmember()
          Randomly pick a value that is not contained in this subset.
 void set(int index, int value)
          Assigns the member of this subset at the given index.
 int[] toArray()
          Returns the membership in this subset as an array.
 void validate()
          Checks if this subset is valid, throwing an exception if not.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Subset

public Subset(int k,
              int n)
Constructs a new decision variable for representing subsets of size k from a set of size n.

Parameters:
k - the fixed size of the subset
n - the size of the original set (i.e., the number of candidate members)
Method Detail

getK

public int getK()
Returns the fixed size of this subset.

Returns:
the fixed size of this subset

getN

public int getN()
The size of the original set.

Returns:
the size of the original set

get

public int get(int index)
Gets the member of this subset at the given index.

Parameters:
index - the index
Returns:
the member of this subset at the given index

validate

public void validate()
Checks if this subset is valid, throwing an exception if not.

Throws:
FrameworkException - if this subset is not valid

set

public void set(int index,
                int value)
Assigns the member of this subset at the given index.

Parameters:
index - the index
value - the new member

getSet

public Set<Integer> getSet()
Returns the membership in this subset as an unmodifiable set.

Returns:
the membership in this subset.

toArray

public int[] toArray()
Returns the membership in this subset as an array.

Returns:
the membership in this subset

fromArray

public void fromArray(int[] members)
Populates this subset from an array.

Parameters:
members - the array containing the subset members

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

copy

public Subset copy()
Description copied from interface: Variable
Returns an independent copy of this decision variable. It is required that x.copy() is completely independent from x. This means any method invoked on x.copy() in no way alters the state of x and vice versa. It is typically the case that x.copy().getClass() == x.getClass() and x.copy().equals(x).

Specified by:
copy in interface Variable
Returns:
an independent copy of this decision variable

randomize

public void randomize()
Description copied from interface: Variable
Randomly assign the value of this variable. In general, the randomization should follow a uniform distribution.

Specified by:
randomize in interface Variable

randomNonmember

public int randomNonmember()
Randomly pick a value that is not contained in this subset.


MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!