From c7b9e68a6ee95a812ce04678c8d814666b538d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20R=C3=BChling?= Date: Wed, 28 Aug 2024 21:06:26 +0200 Subject: [PATCH 1/5] added overview of language fragments --- doc/content/factformat.md | 2 +- doc/content/fragments.md | 52 +++++++++++++++++++ .../encodings/base/fclingo/formulas.lp | 1 - src/coomsuite/encodings/base/structure.lp | 5 +- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 doc/content/fragments.md diff --git a/doc/content/factformat.md b/doc/content/factformat.md index b8e3a21..10fada1 100644 --- a/doc/content/factformat.md +++ b/doc/content/factformat.md @@ -1,4 +1,4 @@ -# Fact format of instances +# Fact format of instances (outdated) The instances are generated automatically by parsing a COOM file. We describe here the ASP fact format used for the translation. We prefix every predicate by `coom_` to make distinguish the predicates here diff --git a/doc/content/fragments.md b/doc/content/fragments.md new file mode 100644 index 0000000..207597a --- /dev/null +++ b/doc/content/fragments.md @@ -0,0 +1,52 @@ +# COOM language fragments +As covered by our encodings + +## **COOM core** +### Configuration tree / Product hierarchy +- Root is `product` with features + - Every feature has cardinality 1 +- Only features allowed are `enumeration` + - which can have `attribute` + +### Constraints +- `behavior` + - `require` and `require` with single `condition` (both not nested) + - Binary comparison operators: `=`, `!=`, `<`, `<=`, `>`, `>=` + - Unary logical operators: `!`, `()` + - Binary logical operators: `||`, `&&` + - *Example*: `require ! (color = Red && size = XXL)` + - `combinations` + - only `allow` + - `forbid` not yet implemented + - table entries can be tuples + - wildcard `-*-` supported + +## COOM[P] +Everything from **COOM core** plus + +### Configuration tree / Product hierarchy +- Features can have cardinalities (`0..1 Basket basket`) + - No open cardinalities +- Features can also be `structure` + +### Constraints +- Constraints can be specified locally for a structure, eg. `behavior Bag {...}` +- This enables longer path expressions, eg. `carrier.bag.capacity.volume` + +## COOM[X] +Everything from **COOM[P]** plus + +### Configuration tree / Product hierarchy +- Features can be numeric, eg. `num .#/g 1-10000 totalWeight` + - no open ranges + - number of decimals and SI units have no effect + +### Constraints +- Aggregate functions (`count`, `sum`, `min`, `max`) +- Arithmetics + - Unary: `()`, `+`, `-` + - Binary: `+`, `-`, `*` + - no support yet for `/` and `^` + - fclingo only supports linear calculations (no multiplication of two variables) + + diff --git a/src/coomsuite/encodings/base/fclingo/formulas.lp b/src/coomsuite/encodings/base/fclingo/formulas.lp index 4d1d607..76ea963 100644 --- a/src/coomsuite/encodings/base/fclingo/formulas.lp +++ b/src/coomsuite/encodings/base/fclingo/formulas.lp @@ -22,5 +22,4 @@ defined(F) :- binary(F,X1,_,X2), &df{X1}, &df{X2}. % Only linear constraints are supported &sus{ XL*N } =: F :- binary(F,XL,"*",XR), number(XR,N). &sus{ XR*N } =: F :- binary(F,XL,"*",XR), number(XL,N). -% TODO: Is division possible in fclingo? % TODO: Add more arithmetics (division and power) diff --git a/src/coomsuite/encodings/base/structure.lp b/src/coomsuite/encodings/base/structure.lp index 88443c7..c36fc80 100644 --- a/src/coomsuite/encodings/base/structure.lp +++ b/src/coomsuite/encodings/base/structure.lp @@ -4,11 +4,12 @@ include("root"). % Generate include predicates for objects { include(X) : type(X,_) }. -% Always include minimal number of objects (no optimizations currently) +% Always include minimal number of objects +% Commented out because we wanted to include no optimizations currently % include(X) :- feature(C,_,T,Min,_), type(X,T), index(X,I), I < Min, % parent(X,P), include(P), type(P,C). -% Do not include an object if their parent is not included +% Do not include an object if its parent is not included :- include(X), parent(X,P), not include(P). % Indices in ascending order From 1326b40edbc0f47647270948fb29aca795dd03ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20R=C3=BChling?= Date: Wed, 28 Aug 2024 21:10:01 +0200 Subject: [PATCH 2/5] future work --- doc/content/fragments.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/content/fragments.md b/doc/content/fragments.md index 207597a..26e6c83 100644 --- a/doc/content/fragments.md +++ b/doc/content/fragments.md @@ -50,3 +50,7 @@ Everything from **COOM[P]** plus - fclingo only supports linear calculations (no multiplication of two variables) + +## Future work +- Open cardinalities +- Open numeric intervals From 4d39c31d4d78866f6cad44301dfcaf41466b52da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20R=C3=BChling?= Date: Fri, 29 Nov 2024 12:29:46 +0100 Subject: [PATCH 3/5] added description for --help --- src/coomsuite/utils/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coomsuite/utils/parser.py b/src/coomsuite/utils/parser.py index f8ff116..02b4ef5 100644 --- a/src/coomsuite/utils/parser.py +++ b/src/coomsuite/utils/parser.py @@ -29,8 +29,8 @@ def get_parser() -> ArgumentParser: prog="coomsuite", description=dedent( """\ - coomsuite - filldescription + The COOM suite is a package providing functionality + to parse and solve product configuration problems specified in COOM. """ ), ) From 310af011cc606bca7679367234f3a71533ac4dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20R=C3=BChling?= Date: Fri, 29 Nov 2024 13:48:40 +0100 Subject: [PATCH 4/5] refactored preprocessing encoding --- src/coomsuite/encodings/preprocess.lp | 299 +----------------- src/coomsuite/encodings/preprocess/defined.lp | 22 ++ .../encodings/preprocess/instantiate.lp | 124 ++++++++ src/coomsuite/encodings/preprocess/output.lp | 99 ++++++ src/coomsuite/encodings/preprocess/python.lp | 47 +++ 5 files changed, 296 insertions(+), 295 deletions(-) create mode 100644 src/coomsuite/encodings/preprocess/defined.lp create mode 100644 src/coomsuite/encodings/preprocess/instantiate.lp create mode 100644 src/coomsuite/encodings/preprocess/output.lp create mode 100644 src/coomsuite/encodings/preprocess/python.lp diff --git a/src/coomsuite/encodings/preprocess.lp b/src/coomsuite/encodings/preprocess.lp index 9e5acf4..791e256 100644 --- a/src/coomsuite/encodings/preprocess.lp +++ b/src/coomsuite/encodings/preprocess.lp @@ -1,295 +1,4 @@ -%%% Instantiate complete instance tree -% Root is always included -type_aux((),"product") :- coom_structure("product"). - -% Create auxiliary predicate for every feature -type_aux((F,(X,I)),T) :- coom_feature(Ctx,F,T,_,Max), type_aux(X,Ctx), I = 0..Max-1, T != "num". -type_aux((F,(X,I)),@join(Ctx,F)) :- coom_feature(Ctx,F,"num",_,Max), type_aux(X,Ctx), I = 0..Max-1. - -% Create auxiliary prediate for attribute variables -type_aux((A,(X,0)),A) :- type_aux(X,T), coom_enumeration(T), coom_attribute_value(T,_,A,_). - - -%%% Constraints -% Get formula context -formula_context(F,Ctx) :- coom_binary(F,_,_,_), coom_require(C,F), coom_context(C,Ctx). -formula_context(F,Ctx) :- coom_binary(F,_,_,_), coom_condition(C,F), coom_context(C,Ctx). -formula_context(F,Ctx) :- coom_binary(F,_,_,_), coom_imply(C,_,F), coom_context(C,Ctx). - -formula_context(F,Ctx) :- coom_unary(F,_,_), coom_require(C,F), coom_context(C,Ctx). -formula_context(F,Ctx) :- coom_unary(F,_,_), coom_condition(C,F), coom_context(C,Ctx). -formula_context(F,Ctx) :- coom_unary(F,_,_), coom_imply(C,_,F), coom_context(C,Ctx). - -formula_context(L,Ctx) :- coom_binary(L,_,_,_), coom_binary(F,L,_,_), formula_context(F,Ctx). -formula_context(R,Ctx) :- coom_binary(R,_,_,_), coom_binary(F,_,_,R), formula_context(F,Ctx). - -formula_context(L,Ctx) :- coom_unary(L,_,_), coom_binary(F,L,_,_), formula_context(F,Ctx). -formula_context(R,Ctx) :- coom_unary(R,_,_), coom_binary(F,_,_,R), formula_context(F,Ctx). - -formula_context(F',Ctx) :- coom_binary(F',_,_,_), coom_unary(F,_,F'), formula_context(F,Ctx). -formula_context(F',Ctx) :- coom_unary(F',_,_), coom_unary(F,_,F'), formula_context(F,Ctx). - -% Instantiate paths -path_start(X,P) :- coom_binary(F,P,_,_), coom_path(P,0,_), type_aux(X,Ctx), formula_context(F,Ctx). -path_start(X,P) :- coom_binary(F,_,_,P), coom_path(P,0,_), type_aux(X,Ctx), formula_context(F,Ctx). -path_start(X,P) :- coom_unary(F,_,P), coom_path(P,0,_), type_aux(X,Ctx), formula_context(F,Ctx). -path_start(X,P) :- coom_combinations(C,_,P), coom_path(P,0,_), type_aux(X,Ctx), coom_context(C,Ctx). -path_start(X,P) :- coom_function(Ctx,_,_,P), coom_path(P,0,_), type_aux(X,Ctx). -path_start(X,P) :- coom_imply(C,P,_), coom_path(P,0,_), type_aux(X,Ctx), coom_context(C,Ctx). - -% Determine all ground paths -path_to(X,P,0,X') :- coom_path(P,0,N), - path_start(X,P), type_aux(X',_), X' =(N,(X,_)). -path_to(X,P,I,X'') :- coom_path(P,I,N), - path_to(X,P,I-1,X'), type_aux(X'',_), X''=(N,(X',_)). - -path_to(X,P,@dotpath(X')) :- not coom_path(P,I+1,_), path_to(X,P,I,X'). - -% Constants and numbers -path_to(X,P,P) :- coom_binary(F,_,_,P), coom_constant(P), formula_context(F,T), type_aux(X,T). -path_to(X,P,P) :- coom_binary(F,P,_,_), coom_constant(P), formula_context(F,T), type_aux(X,T). -path_to(X,P,P) :- coom_binary(F,_,_,P), coom_number(P,_), formula_context(F,T), type_aux(X,T). -path_to(X,P,P) :- coom_binary(F,P,_,_), coom_number(P,_), formula_context(F,T), type_aux(X,T). - -% Instantiate binaries and unaries -binary(X,F,@binary(XL,Op,XR),XL,Op,XR) :- coom_binary(F,L,Op,R), - formula_context(F,C), - type_aux(X,C), path_to(X,L,XL), path_to(X,R,XR). - -unary(X,F,@unary(X',Op),Op,X') :- coom_unary(F,Op,F'), - formula_context(F,C), - type_aux(X,C), path_to(X,F',X'). - -ground_formula(X,F,G) :- binary(X,F,G,_,_,_). -ground_formula(X,F,G) :- unary(X,F,G,_,_). - -% Default binaries for arithmetics if one side is undefined -% TODO: Does this always give desired behavior? -ground_formula(X,F,XL) :- coom_binary(F,L,"+",R), - formula_context(F,C), - type_aux(X,C), path_to(X,L,XL), not path_to(X,R,_). - -ground_formula(X,F,XR) :- coom_binary(F,L,"+",R), - formula_context(F,C), - type_aux(X,C), not path_to(X,L,_), path_to(X,R,XR). - - -% Instantiate functions -function(X,F,T,P) :- coom_function(C,F,T,P), type_aux(X,C). - -% Auxiliary paths for formulas and functions -path_to(X,F,G) :- ground_formula(X,F,G). -path_to(X,F,@function(T,X,P)) :- function(X,F,T,P). - -% Auxiliary paths for cardinalities -path_to(X,N,@dotpath(X')) :- coom_feature(Ctx,N,_,_,_), type_aux(X,Ctx), type_aux(X',_), X' =(N,(X,_)). -path_to(X,A,@dotpath(X')) :- coom_attribute(T,A,_), type_aux(X,T), type_aux(X',_), X' =(A,(X,_)). - -% Instantiate conditional requirements -conditional_requirement(C,G,G') :- coom_context(C,Ctx), coom_condition(C,F), ground_formula(X,F,G), - type_aux(X,Ctx), coom_require(C,F'), ground_formula(X,F',G'). - -% Instantiate combination tables -table(C,X) :- coom_combinations(C,_,_), coom_context(C,Ctx), type_aux(X,Ctx). - -combinations_tuple((C,Ctx),Col,(X,())) :- table(C,Ctx), - coom_combinations(C,Col,P), not coom_combinations(C,Col+1,_), - path_to(Ctx,P,X). -combinations_tuple((C,Ctx),Col,(X',X)) :- combinations_tuple((C,Ctx),Col+1,X), - coom_combinations(C,Col,P), Col >= 0, - path_to(Ctx,P,X'). -combinations_tuple(C,CT) :- combinations_tuple(C,0,CT). - -tuple_order(C,CT,ID) :- combinations_tuple(C,CT), ID = #count{ CT': combinations_tuple(C,CT'), CT'= 0, + path_to(Ctx,P,X'). +combinations_tuple(C,CT) :- combinations_tuple(C,0,CT). + +tuple_order(C,CT,ID) :- combinations_tuple(C,CT), ID = #count{ CT': combinations_tuple(C,CT'), CT' Date: Fri, 29 Nov 2024 14:06:45 +0100 Subject: [PATCH 5/5] updated pylint params --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 32124d1..dde0fc0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,8 @@ line-length = 120 max-line-length = 120 [tool.pylint.design] -max-args = 10 +max-args = 6 +max-positional-arguments = 6 max-attributes = 8 max-bool-expr = 5 max-branches = 12