:orphan: :py:mod:`calliope.select.constraints` ===================================== .. py:module:: calliope.select.constraints Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: calliope.select.constraints.Constraint calliope.select.constraints.ItemConstraint calliope.select.constraints.GlobalConstraint calliope.select.constraints.SetConstraint calliope.select.constraints.RangeConstraint calliope.select.constraints.EachGlobalConstraint calliope.select.constraints.FractionGlobalConstraint calliope.select.constraints.SumGlobalConstraint calliope.select.constraints.ItemDurationConstraint calliope.select.constraints.PlaylistDurationConstraint calliope.select.constraints.PlaylistDiskSpaceConstraint Functions ~~~~~~~~~ .. autoapisummary:: calliope.select.constraints.linear_score Attributes ~~~~~~~~~~ .. autoapisummary:: calliope.select.constraints.CONSTRAINTS_BY_NAME .. py:function:: linear_score(value, vmin, vmax) Objective function for `value` and target range [`vmin`, `vmax`] Returns 1.0 if vmin <= value <= vmax, decreasing linearly to 0.0 as value tends towards 0.0 and vmax*2. .. py:class:: Constraint Abstract base class. .. py:method:: __repr__() Return repr(self). .. py:class:: ItemConstraint(prop) Bases: :py:obj:`Constraint` Abstract base class. .. py:method:: __repr__() Return repr(self). .. py:method:: score_item(item) :abstractmethod: Score how well `item` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:method:: partition(collection) :abstractmethod: Divide 'collection' into one 'good' and one or more 'bad' groups. This is used to define the neighbourhood we search for a solution. .. py:class:: GlobalConstraint Bases: :py:obj:`Constraint` Abstract base class for global (whole playlist) constraints. .. py:method:: score_playlist(playlist) :abstractmethod: Score how well `playlist` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:class:: SetConstraint(prop, values) Bases: :py:obj:`ItemConstraint` Abstract base class. Simple set constraint, for properties with nominal (string) values. An item satisfies the constraint if its value matches one member of `values`. .. py:method:: __repr__() Return repr(self). .. py:method:: score_item(item) Score how well `item` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:method:: partition(collection) Divide 'collection' into one 'good' and one or more 'bad' groups. This is used to define the neighbourhood we search for a solution. .. py:class:: RangeConstraint(prop, vmin, vmax) Bases: :py:obj:`ItemConstraint` Abstract base class. Simple range constraint, for properties with numeric values. An item scores 1.0 if `vmin` <= `prop` <= `vmax`. The score decreases linearly towards 0.0 as `prop` approaches 0 or 2*`vmax`. t's common to specify a single value by specifying `vmin` = `vmax`. .. py:method:: __repr__() Return repr(self). .. py:method:: score_item(item) Score how well `item` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:method:: partition(collection) Divide 'collection' into one 'good' and one or more 'bad' groups. This is used to define the neighbourhood we search for a solution. .. py:class:: EachGlobalConstraint(item_constraint) Bases: :py:obj:`GlobalConstraint` Apply an item constraint to every item in the playlist. .. py:method:: __repr__() Return repr(self). .. py:method:: score_playlist(playlist) Score how well `playlist` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:method:: partition(collection) .. py:class:: FractionGlobalConstraint(item_constraint, fmin, fmax) Bases: :py:obj:`GlobalConstraint` Apply an item set constraint to some items in the playlist. .. py:method:: __repr__() Return repr(self). .. py:method:: score_playlist(playlist) Score how well `playlist` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:method:: partition(collection) .. py:class:: SumGlobalConstraint(prop, vmin, vmax) Bases: :py:obj:`GlobalConstraint`, :py:obj:`RangeConstraint` The sum of 'prop' for all songs should be between 'vmin' and 'vmax'. Simple range constraint, for properties with numeric values. An item scores 1.0 if `vmin` <= `prop` <= `vmax`. The score decreases linearly towards 0.0 as `prop` approaches 0 or 2*`vmax`. t's common to specify a single value by specifying `vmin` = `vmax`. .. py:method:: __repr__() Return repr(self). .. py:method:: score_playlist(playlist) Score how well `playlist` satisfies this constraint. The score must be between 0.0 (doesn't satisfy constraint) and 1.0 (satisfies it perfectly). .. py:method:: partition(collection) Divide 'collection' into one 'good' and one or more 'bad' groups. This is used to define the neighbourhood we search for a solution. .. py:class:: ItemDurationConstraint(vmin, vmax) Bases: :py:obj:`EachGlobalConstraint` Each song should have duration in range [min, max]. .. py:attribute:: PROP :value: 'duration' .. py:class:: PlaylistDurationConstraint(vmin, vmax) Bases: :py:obj:`SumGlobalConstraint` Playlist should be a specified number of seconds in duration. Simple range constraint, for properties with numeric values. An item scores 1.0 if `vmin` <= `prop` <= `vmax`. The score decreases linearly towards 0.0 as `prop` approaches 0 or 2*`vmax`. t's common to specify a single value by specifying `vmin` = `vmax`. .. py:attribute:: PROP :value: 'duration' .. py:class:: PlaylistDiskSpaceConstraint(vmin, vmax) Bases: :py:obj:`SumGlobalConstraint` Playlist items should total a specified number of bytes in size. Simple range constraint, for properties with numeric values. An item scores 1.0 if `vmin` <= `prop` <= `vmax`. The score decreases linearly towards 0.0 as `prop` approaches 0 or 2*`vmax`. t's common to specify a single value by specifying `vmin` = `vmax`. .. py:attribute:: PROP :value: 'album.size_mb' .. py:data:: CONSTRAINTS_BY_NAME