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:
AnyOverriding
plog.Anyproposition 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.Propositioninstances orstr - defaultmarks which of all sub propositions are default
- variablevariable connected to this proposition
- *propositionsan iterable of
Methods
to_json()Converts
Anyto JSON format.from_json(data, class_map)Creates
Anyfrom 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
Anyfrom JSON format.- Parameters
- dataDict[str, Any]
JSON data
- class_mapList[Any]
List of classes which maps to type
- Returns
- out
Any
- out
- 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
- out
Any
- out
Examples
>>> model = Any.from_list([puan.variable("x"), puan.variable("y")], variable="a") >>> type(model) == Any True
Xor#
- class Xor(*propositions, default: Optional[List[Union[str, Proposition]]] = None, variable: Optional[Union[str, variable]] = None)#
Bases:
XorOverriding
plog.Xorproposition 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.Propositioninstances orstr - defaultmarks which of all sub propositions are default
- variablevariable connected to this proposition
- *propositionsan iterable of
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_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
- out
Xor
- out
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:
AllA 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.Propositioninstances orstr - idid connected to this proposition
- *propositionsan iterable of
Methods
This configurator model's polyhedron (see
plog.AtLeast.to_ge_polyhedron).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.
Creates a
StingyConfiguratorfrom the JSON format.to_json()Converts a
StingyConfiguratorto the JSON format- add(proposition: AtLeast) StingyConfigurator#
Add a new proposition to the model.
- Parameters
- propositionpg.AtLeast
Proposition to be added
- Returns
- 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
StingyConfiguratorfrom the JSON format.- Returns
- property ge_polyhedron: puan.ndarray.ge_polyhedron_config#
This configurator model’s polyhedron (see
plog.AtLeast.to_ge_polyhedron).- Returns
- 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.solvefunction for more information on the solver interface.- only_leafs
bool Controls if only leafs should be returned in the output, see
leafs(). DefaultFalse.
- Returns
- out
itertools.starmap
- out
- to_json() Dict[str, Any]#
Converts a
StingyConfiguratorto the JSON format