# macop.solutions.discrete — macop v1.0.5 documentation

# macop.solutions.discrete

Discrete solution classes implementations

Classes

`BinarySolution`(data, size) | Binary integer solution class
`CombinatoryIntegerSolution`(data, size) | Combinatory integer solution class
`IntegerSolution`(data, size) | Integer solution class

class `macop.solutions.discrete.``BinarySolution`(data, size)

  Binary integer solution class

  - store solution as a binary array (example: [0, 1, 0, 1, 1])

  - associated size is the size of the array

  - mainly use for selecting or not an element in a list of valuable objects

  `data`

    {ndarray} – array of binary values

  `size`

    {int} – size of binary array values

  `score`

    {float} – fitness score value

  static `random`(size, validator=None)

    Intialize binary array with use of validator to generate valid random solution

    Parameters

      - size – {int} – expected solution size to generate

      - validator – {function} – specific function which validates or not a solution (if None, not validation is applied)

    Returns

      {BinarySolution} – new generated binary solution

    Example:

        >>> from macop.solutions.discrete import BinarySolution
        >>> validator = lambda solution: True if sum(solution._data) > 5 else False
        >>> solution = BinarySolution.random(10, validator)
        >>> sum(solution._data) > 5
        True

class `macop.solutions.discrete.``CombinatoryIntegerSolution`(data, size)

  Combinatory integer solution class

  - store solution as a binary array (example: [0, 1, 0, 1, 1])

  - associated size is the size of the array

  - mainly use for selecting or not an element in a list of valuable objects

  `data`

    {ndarray} – array of integer values

  `size`

    {int} – size of integer array values

  `score`

    {float} – fitness score value

  static `random`(size, validator=None)

    Intialize combinatory integer array with use of validator to generate valid random solution

    Parameters

      - size – {int} – expected solution size to generate

      - validator – {function} – specific function which validates or not a solution (if None, not validation is applied)

    Returns

      {CombinatoryIntegerSolution} – new generated combinatory integer solution

    Example:

        >>> from macop.solutions.discrete import CombinatoryIntegerSolution
        >>> validator = lambda solution: True if sum(solution._data) > 5 else False
        >>> solution = CombinatoryIntegerSolution.random(5, validator)
        >>> sum(solution._data) > 5
        True

class `macop.solutions.discrete.``IntegerSolution`(data, size)

  Integer solution class

  `data`

    {ndarray} – array of binary values

  `size`

    {int} – size of binary array values

  `score`

    {float} – fitness score value

  static `random`(size, validator=None)

    Intialize integer array with use of validator to generate valid random solution

    Parameters

      - size – {int} – expected solution size to generate

      - validator – {function} – specific function which validates or not a solution (if None, not validation is applied)

    Returns

      {IntegerSolution} – new generated integer solution

    Example:

        >>> from macop.solutions.discrete import IntegerSolution
        >>> import numpy as np
        >>> np.random.seed(42)
        >>> validator = lambda solution: True if sum(solution._data) > 5 else False
        >>> solution = IntegerSolution.random(5, validator)
        >>> sum(solution._data) > 10
        True