Configurator module#

Summary#

The Configurator module helps to easily create an online configurator experience from a logic any logic model.

Data types#

puan.modules.configurator.Any : Overriding puan.logic.plog.Any class to take extra parameter default.

puan.modules.configurator.Xor : Overriding puan.logic.plog.Xor class to take extra parameter default.

puan.modules.configurator.StingyConfigurator : A class for supporting a sequential configurator experience. The “stingy” configurator always tries to select the least possible number of selections in a solution, with respect to what’s been prioritized. Whenever an AtLeast proposition proposes multiple solutions that equal least number of selections, then a default may be added to avoid ambivalence.

Any#

class Any(*propositions, default: Optional[List[Union[str, Proposition]]] = None, variable: Optional[Union[str, variable]] = None)#

Bases: Any

Overriding plog.Any proposition with default attribute indicating which solution is default. If proposition is \(A\): \(a+b+c \ge 1\) and default is \(c\), then new proposition is

\(A\) : \(A'+c \ge 1\)
\(A'\) : \(a+b \ge 1\)

and prio is set to \(c > A'\).

Parameters
*propositionsan iterable of puan.Proposition instances or str
defaultmarks which of all sub propositions are default
variablevariable connected to this proposition

Methods

to_json()

Converts Any to JSON format.

from_json(data, class_map)

Creates Any from JSON format.

from_list(propositions[, variable, default])

Convert from list of propositions to an object of this proposition class.

static from_json(data: Dict[str, Any], class_map: List[Any]) Any#

Creates Any from JSON format.

Parameters
dataDict[str, Any]

JSON data

class_mapList[Any]

List of classes which maps to type

Returns
outAny
static from_list(propositions: list, variable: Optional[Union[str, variable]] = None, default: List[variable] = []) Any#

Convert from list of propositions to an object of this proposition class.

Returns
outAny

Examples

>>> model = Any.from_list([puan.variable("x"), puan.variable("y")], variable="a")
>>> type(model) == Any
True
to_json() Dict[str, Any]#

Converts Any to JSON format.

Returns
outDict[str, Any]

Xor#

class Xor(*propositions, default: Optional[List[Union[str, Proposition]]] = None, variable: Optional[Union[str, variable]] = None)#

Bases: Xor

Overriding plog.Xor proposition with default attribute indicating which solution is default. If proposition is \(A\): \(a+b+c \ge 1\) and default is \(c\), then new proposition is

\(A\) : \(A'+c \ge 1\)
\(A'\) : \(a+b \ge 1\)

and prio is set to \(c > A'\).

Parameters
*propositionsan iterable of puan.Proposition instances or str
defaultmarks which of all sub propositions are default
variablevariable connected to this proposition

Methods

to_json()

Returns proposition as a readable JSON.

from_list(propositions[, variable, default])

Convert from list of propositions to an object of this proposition class.

from_json

static from_json(data: dict, class_map: list) Xor#
static from_list(propositions: list, variable: Optional[Union[str, variable]] = None, default: List[variable] = []) Xor#

Convert from list of propositions to an object of this proposition class.

Returns
outXor

Examples

>>> model = Xor.from_list([puan.variable("x"), puan.variable("y")], variable="a")
>>> type(model) == Xor
True
to_json()#

Returns proposition as a readable JSON.

Returns
outDict[str, Any]

StingyConfigurator#

class StingyConfigurator(*propositions: List[Union[str, Proposition]], id: Optional[str] = None)#

Bases: All

A class for supporting a sequential configurator experience. The “stingy” configurator always tries to select the least possible number of selections in a solution, with respect to what’s been prioritized. Whenever an AtLeast proposition proposes multiple solutions that equal least number of selections, then a default may be added to avoid ambivalence.

Parameters
*propositionsan iterable of puan.Proposition instances or str
idid connected to this proposition

Methods

ge_polyhedron

This configurator model's polyhedron (see plog.AtLeast.to_ge_polyhedron).

default_prios

Default prio dictionary, based on defaults in either Xor's or Any's.

leafs()

Return propositions that are of type variable.

select(*prios[, solver, only_leafs])

Select items to prioritize and receive a solution.

add(proposition)

Add a new proposition to the model.

from_json()

Creates a StingyConfigurator from the JSON format.

to_json()

Converts a StingyConfigurator to the JSON format

add(proposition: AtLeast) StingyConfigurator#

Add a new proposition to the model.

Parameters
propositionpg.AtLeast

Proposition to be added

Returns
outStingyConfigurator
Raises
Exception

If already proposition with same id exists among this proposition’s sub propositions.

property default_prios: Dict[str, int]#

Default prio dictionary, based on defaults in either Xor’s or Any’s.

Returns
outDict[str, int]
from_json() StingyConfigurator#

Creates a StingyConfigurator from the JSON format.

Returns
outStingyConfigurator
property ge_polyhedron: puan.ndarray.ge_polyhedron_config#

This configurator model’s polyhedron (see plog.AtLeast.to_ge_polyhedron).

Returns
outpuan.ndarray.ge_polyhedron_config
leafs() List[variable]#

Return propositions that are of type variable.

Returns
outList[variable]
select(*prios: List[Dict[str, int]], solver: Optional[Callable] = None, only_leafs: bool = False) starmap#

Select items to prioritize and receive a solution.

Parameters
*priosList[Dict[str, int]]

a list of dicts where each entry’s value is a prio

solverCallable[[puan.ndarray.ge_polyhedron, Dict[str, int]], List[(np.ndarray, int, int)]] = None

A mixed integer linear programming solver function. Check plog.AtLeast.solve function for more information on the solver interface.

only_leafsbool

Controls if only leafs should be returned in the output, see leafs(). Default False.

Returns
outitertools.starmap
to_json() Dict[str, Any]#

Converts a StingyConfigurator to the JSON format