From ededac3b9df3ea779e4ba27f15327cda386ed6a9 Mon Sep 17 00:00:00 2001 From: Susana Hahn Date: Fri, 22 Mar 2024 17:01:23 -0600 Subject: [PATCH 1/6] clinguin UI --- examples/asp/city-bike.lp | 2 +- src/coomsolver/encodings/ui.lp | 145 +++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/coomsolver/encodings/ui.lp diff --git a/examples/asp/city-bike.lp b/examples/asp/city-bike.lp index 37982ab..c7192ef 100644 --- a/examples/asp/city-bike.lp +++ b/examples/asp/city-bike.lp @@ -11,7 +11,7 @@ feature("Basket",position,"Position",1,1). feature("Basket",color,"Color",1,1). structure("Carrier"). -feature("Carrier",bag,"Bag",0,2). +feature("Carrier",bag,"Bag",2,2). structure("Bag"). feature("Bag",capacity,"Capacity",1,1). diff --git a/src/coomsolver/encodings/ui.lp b/src/coomsolver/encodings/ui.lp new file mode 100644 index 0000000..d6f57a6 --- /dev/null +++ b/src/coomsolver/encodings/ui.lp @@ -0,0 +1,145 @@ + +% Auxiliaries +sinstance(I):-_all(instance(I,S)), structure(S). +sinstance(I):-instance(I,S), structure(S), _clinguin_browsing. +einstance(I):-_all(instance(I,E)), enumeration(E). +einstance(I):-instance(I,E), enumeration(E), _clinguin_browsing. +ainstance(I):-_all(instance(I,N)), not enumeration(N), not structure(N). +ainstance(I):-instance(I,N), not enumeration(N), not structure(N), _clinguin_browsing. +eorainstance(I):-einstance(I). +eorainstance(I):-ainstance(I). +% For debugging +% attr(E,class,("border-1";"border";"border-dark")):- elem(E, container, _). + +% Window +elem(w, window, root). + +% Container per structre instance +elem(icontainer(()), container, w). + + % Title + elem(ititle(I), container, icontainer(I)) :- sinstance(I). + attr(ititle(I), order, 1) :- sinstance(I). + % attr(ititle(I), width, 50) :- sinstance(I). + attr(ititle(I), class, ("d-flex";"flex-row")) :- sinstance(I). + + elem(ititle_l(I), label, ititle(I)) :- sinstance(I). + attr(ititle_l((F,(P,C))), label,F) :- sinstance((F,(P,C))), instance((F,(P,C)),S). + attr(ititle_l(I), class, ("h4")) :- sinstance(I), instance(I,S). + + elem(ititle_t(I), label, ititle(I)) :- sinstance(I). + attr(ititle_t((F,(P,C))), label, @format("","({0})",S)) :- sinstance((F,(P,C))), instance((F,(P,C)),S). + attr(ititle_t(I), class, ("m-2";"fw-lighter")) :- sinstance(I), instance(I,S). + + % Enumerations + elem(ienumerations(I), container, icontainer(I)) :- sinstance(I). + attr(ienumerations(I), order, 2) :- sinstance(I). + attr(ienumerations(I), heigth, 50) :- sinstance(I). + attr(ienumerations(I), class, ("d-flex";"flex-row")) :- sinstance(I). + attr(ienumerations(P), class, ("m-4")) :- sinstance(P), einstance((F,(P,C))). + + % Container per enumeration instance + elem(eicontainer((F,(P,C))), container, ienumerations(P)) :- einstance((F,(P,C))). + attr(eicontainer(I), class, ("m-2";"p-2";"rounded")) :- einstance(I). + attr(eicontainer(I), class, ("d-flex";"flex-col")) :- einstance(I). + attr(eicontainer(I), class, ("bg-secondary";"bg-opacity-25")) :- einstance(I). + attr(eicontainer(I), background_color, "#D9D4F0") :- einstance(I). + + + % Container per enumeration for the title and one for each attribute + elem(eititle((F,(P,C))), container, eicontainer(P)) :- ainstance((F,(P,C))). + elem(eititle(I), container, eicontainer(I)) :- einstance(I). + attr(eititle(I), order, 1) :- einstance(I). + attr(eititle(I), order, 2) :- ainstance(I). + attr(eititle(I), class, ("d-flex";"flex-row")) :- eorainstance(I). + attr(eititle(I), class, ("align-self-end")) :- ainstance(I). + + elem(eititle_l(I), label, eititle(I)) :- eorainstance(I). + attr(eititle_l((F,(P,C))), label, F) :- eorainstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_l((F,(P,C))), class, "h6") :- einstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_l((F,(P,C))), class, ("fst-italic";"fw-light")) :- ainstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_l((F,(P,C))), order, 1) :- eorainstance((F,(P,C))), instance((F,(P,C)),S). + + elem(eititle_t(I), label, eititle(I)) :- einstance(I). + attr(eititle_t((F,(P,C))), label, @format("","({0})",S)) :- einstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_t((F,(P,C))), class, ("fw-lighter";"small")) :- einstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_t((F,(P,C))), order, 2) :- einstance((F,(P,C))), instance((F,(P,C)),S). + + + + + elem(eioption(I), container, eititle(I)) :- eorainstance(I). + attr(eioption(I), order, 3) :- eorainstance(I). + + elem(eioption_dd(I), dropdown_menu, eioption(I)) :- eorainstance(I). + attr(eioption_dd(I), selected, V) :- eorainstance(I), _all(val(I,V)), not _clinguin_browsing. + attr(eioption_dd(I), selected, V) :- eorainstance(I), val(I,V), _clinguin_browsing. + attr(eioption_dd(I), class, "disabled") :- eorainstance(I), _all(val(I,V)), not _clinguin_assume(val(I,V)). + + elem(eioption_ddi(I,V), dropdown_menu_item, eioption_dd(I)) :- eorainstance(I), _any(val(I,V)). + attr(eioption_ddi(I,V), label, V) :- eorainstance(I), _any(val(I,V)). + when(eioption_ddi(I,V), click, call, add_assumption(val(I,V))) :- eorainstance(I), _any(val(I,V)). + + elem(eioption_ddi(I,remove), dropdown_menu_item, eioption_dd(I)) :- eorainstance(I). + attr(eioption_ddi(I,remove), icon, "fa-ban") :- eorainstance(I). + attr(eioption_ddi(I,remove), class, "text-info") :- eorainstance(I). + when(eioption_ddi(I,remove), click, call, remove_assumption_signature(val(I,any))) :- eorainstance(I). + + + + + % Features + elem(ifeatures(I), container, icontainer(I)) :- sinstance(I). + attr(ifeatures(I), order, 3) :- sinstance(I). + attr(ifeatures(I), class, ("d-flex";"flex-col")) :- sinstance(I). + % attr(ifeatures(I), background_color, white) :- sinstance(I). + attr(ifeatures(I), class, ("m-4")) :- sinstance(I), sinstance((F,(I,C))). + + % Container per structre instance + elem(icontainer((F,(P,C))), container, ifeatures(P)) :- sinstance((F,(P,C))), sinstance(P). + attr(icontainer(I), class, ("m-2";"p-2")) :- sinstance(I). + % attr(icontainer(I), background_color, "#98B3EA") :- sinstance(I). + % attr(icontainer(I), background_color, white) :- sinstance(I). + attr(icontainer(I), class, ("bg-primary";"bg-opacity-10")) :- sinstance(I). + attr(icontainer(I), class, ("d-flex";"flex-col";"border";"border-dark";"border-2";"rounded")) :- sinstance(I). + + + %%%%%%%%%%%%%%%%%%%%%%%% + % Menu bar + %%%%%%%%%%%%%%%%%%%%%%%% + + elem(menu_bar, menu_bar, w). + attr(menu_bar, title, "COOM solver"). + attr(menu_bar, icon, "fa-cog"). + + + elem(menu_bar_restart, button, menu_bar). + attr(menu_bar_restart, label, "Restart"). + attr(menu_bar_restart, icon, "fa-arrows-rotate"). + attr(menu_bar_restart, class, "btn-outline-danger"). + attr(menu_bar_restart, class, "border-0"). + when(menu_bar_restart, click, call, restart). + + elem(menu_bar_clear, button, menu_bar). + attr(menu_bar_clear, label, "Clear"). + attr(menu_bar_clear, icon, "fa-trash"). + attr(menu_bar_clear, class, "btn-outline-danger"). + attr(menu_bar_clear, class, "border-0"). + when(menu_bar_clear, click, call, clear_assumptions). + + + elem(menu_bar_download, button, menu_bar). + attr(menu_bar_download, label, "Download"). + attr(menu_bar_download, icon, "fa-download"). + when(menu_bar_download, click, call, download). + + + elem(menu_bar_select, button, menu_bar). + attr(menu_bar_select, label, "Select solution"). + attr(menu_bar_select, icon, "fa-hand-pointer"). + when(menu_bar_select, click, call, select). + + elem(menu_bar_next, button, menu_bar). + attr(menu_bar_next, label, "Next"). + attr(menu_bar_next, icon, "fa-forward-step"). + when(menu_bar_next, click, call, next_solution). From 8551821c37b5d0fc8f442b31886b87d3de0e3234 Mon Sep 17 00:00:00 2001 From: Susana Hahn Date: Mon, 25 Mar 2024 10:38:33 -0600 Subject: [PATCH 2/6] Remove and add instances --- examples/asp/city-bike.lp | 2 +- src/coomsolver/encodings/ui.lp | 51 ++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/examples/asp/city-bike.lp b/examples/asp/city-bike.lp index c7192ef..37982ab 100644 --- a/examples/asp/city-bike.lp +++ b/examples/asp/city-bike.lp @@ -11,7 +11,7 @@ feature("Basket",position,"Position",1,1). feature("Basket",color,"Color",1,1). structure("Carrier"). -feature("Carrier",bag,"Bag",2,2). +feature("Carrier",bag,"Bag",0,2). structure("Bag"). feature("Bag",capacity,"Capacity",1,1). diff --git a/src/coomsolver/encodings/ui.lp b/src/coomsolver/encodings/ui.lp index d6f57a6..72d805f 100644 --- a/src/coomsolver/encodings/ui.lp +++ b/src/coomsolver/encodings/ui.lp @@ -2,12 +2,14 @@ % Auxiliaries sinstance(I):-_all(instance(I,S)), structure(S). sinstance(I):-instance(I,S), structure(S), _clinguin_browsing. +assumed_sinstance(I):- sinstance(I), _clinguin_assume(instance(I,_)). einstance(I):-_all(instance(I,E)), enumeration(E). einstance(I):-instance(I,E), enumeration(E), _clinguin_browsing. ainstance(I):-_all(instance(I,N)), not enumeration(N), not structure(N). ainstance(I):-instance(I,N), not enumeration(N), not structure(N), _clinguin_browsing. eorainstance(I):-einstance(I). eorainstance(I):-ainstance(I). +pos_sinstance(I):-_any(instance(I,S)), structure(S). % For debugging % attr(E,class,("border-1";"border";"border-dark")):- elem(E, container, _). @@ -20,16 +22,30 @@ elem(icontainer(()), container, w). % Title elem(ititle(I), container, icontainer(I)) :- sinstance(I). attr(ititle(I), order, 1) :- sinstance(I). - % attr(ititle(I), width, 50) :- sinstance(I). attr(ititle(I), class, ("d-flex";"flex-row")) :- sinstance(I). elem(ititle_l(I), label, ititle(I)) :- sinstance(I). attr(ititle_l((F,(P,C))), label,F) :- sinstance((F,(P,C))), instance((F,(P,C)),S). attr(ititle_l(I), class, ("h4")) :- sinstance(I), instance(I,S). + attr(ititle_l(I), order, 1) :- sinstance(I), instance(I,S). elem(ititle_t(I), label, ititle(I)) :- sinstance(I). - attr(ititle_t((F,(P,C))), label, @format("","({0})",S)) :- sinstance((F,(P,C))), instance((F,(P,C)),S). + attr(ititle_t((F,(P,C))), label, @format("({0})",S)) :- sinstance((F,(P,C))), instance((F,(P,C)),S). attr(ititle_t(I), class, ("m-2";"fw-lighter")) :- sinstance(I), instance(I,S). + attr(ititle_t(I), order, 2) :- sinstance(I), instance(I,S). + + + elem(ititle_bc(I), container, ititle(I)) :- assumed_sinstance(I). + attr(ititle_bc((F,(P,C))), class, ("ms-auto")) :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S). + attr(ititle_bc((F,(P,C))), order, 3) :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S). + elem(ititle_b(I), button, ititle_bc(I)) :- assumed_sinstance(I). + attr(ititle_b((F,(P,C))), icon, "fa-xmark") :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S). + when(ititle_b(I), click, call, remove_assumption(instance(I,S))) :- assumed_sinstance(I), instance(I,S). + % Remove options + when(ititle_b(I), click, call, remove_assumption_signature(val((F,(I,C)),any))) :- assumed_sinstance(I), einstance((F,(I,C))). + % Remove attr + when(ititle_b(I), click, call, remove_assumption_signature(val((F',((F,(I,C)),C')),any))) :- assumed_sinstance(I), einstance((F,(I,C))), ainstance((F',((F,(I,C)),C'))). + % Enumerations elem(ienumerations(I), container, icontainer(I)) :- sinstance(I). @@ -61,7 +77,7 @@ elem(icontainer(()), container, w). attr(eititle_l((F,(P,C))), order, 1) :- eorainstance((F,(P,C))), instance((F,(P,C)),S). elem(eititle_t(I), label, eititle(I)) :- einstance(I). - attr(eititle_t((F,(P,C))), label, @format("","({0})",S)) :- einstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_t((F,(P,C))), label, @format("({0})",S)) :- einstance((F,(P,C))), instance((F,(P,C)),S). attr(eititle_t((F,(P,C))), class, ("fw-lighter";"small")) :- einstance((F,(P,C))), instance((F,(P,C)),S). attr(eititle_t((F,(P,C))), order, 2) :- einstance((F,(P,C))), instance((F,(P,C)),S). @@ -74,7 +90,8 @@ elem(icontainer(()), container, w). elem(eioption_dd(I), dropdown_menu, eioption(I)) :- eorainstance(I). attr(eioption_dd(I), selected, V) :- eorainstance(I), _all(val(I,V)), not _clinguin_browsing. attr(eioption_dd(I), selected, V) :- eorainstance(I), val(I,V), _clinguin_browsing. - attr(eioption_dd(I), class, "disabled") :- eorainstance(I), _all(val(I,V)), not _clinguin_assume(val(I,V)). + attr(eioption_dd(I), class, ("opacity-75";"btn-outline-dark")) :- eorainstance(I), _all(val(I,V)), not _clinguin_assume(val(I,V)), _any(val(I,V')), V'!=V. + attr(eioption_dd(I), class, ("opacity-50")) :- eorainstance(I), _all(val(I,V)), not _clinguin_assume(val(I,V)), #false: _any(val(I,V')),V'!=V. elem(eioption_ddi(I,V), dropdown_menu_item, eioption_dd(I)) :- eorainstance(I), _any(val(I,V)). attr(eioption_ddi(I,V), label, V) :- eorainstance(I), _any(val(I,V)). @@ -90,7 +107,7 @@ elem(icontainer(()), container, w). % Features elem(ifeatures(I), container, icontainer(I)) :- sinstance(I). - attr(ifeatures(I), order, 3) :- sinstance(I). + attr(ifeatures(I), order, 4) :- sinstance(I). attr(ifeatures(I), class, ("d-flex";"flex-col")) :- sinstance(I). % attr(ifeatures(I), background_color, white) :- sinstance(I). attr(ifeatures(I), class, ("m-4")) :- sinstance(I), sinstance((F,(I,C))). @@ -103,6 +120,30 @@ elem(icontainer(()), container, w). attr(icontainer(I), class, ("bg-primary";"bg-opacity-10")) :- sinstance(I). attr(icontainer(I), class, ("d-flex";"flex-col";"border";"border-dark";"border-2";"rounded")) :- sinstance(I). + % Add + elem(iadd(I), container, icontainer(I)) :- sinstance(I). + attr(iadd(I), order, 3) :- sinstance(I). + attr(iadd(I), class, ("d-flex";"flex-row")) :- sinstance(I). + % attr(iadd(I), background_color, white) :- sinstance(I). + attr(iadd(I), class, ("m-4")) :- sinstance(I), sinstance((F,(I,C))). + + % Container per structre instance + % elem(iposf((F,(P,C))), container, iadd(P)) :- pos_sinstance((F,(P,C))), sinstance(P), not sinstance((F,(P,C))). + elem(iposf((F,(P,C))), container, iadd(P)) :- pos_sinstance((F,(P,C))), sinstance(P), not sinstance((F,(P,C))), #false: pos_sinstance((F,(P,C'))), not sinstance((F,(P,C'))), C' Date: Mon, 25 Mar 2024 10:57:02 -0600 Subject: [PATCH 3/6] Explanation --- src/coomsolver/encodings/ui.lp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/coomsolver/encodings/ui.lp b/src/coomsolver/encodings/ui.lp index 72d805f..f1d5ac8 100644 --- a/src/coomsolver/encodings/ui.lp +++ b/src/coomsolver/encodings/ui.lp @@ -2,7 +2,7 @@ % Auxiliaries sinstance(I):-_all(instance(I,S)), structure(S). sinstance(I):-instance(I,S), structure(S), _clinguin_browsing. -assumed_sinstance(I):- sinstance(I), _clinguin_assume(instance(I,_)). +assumed_sinstance(I):- sinstance(I), _clinguin_assume(instance(I,_)), not instance(I,":root"). einstance(I):-_all(instance(I,E)), enumeration(E). einstance(I):-instance(I,E), enumeration(E), _clinguin_browsing. ainstance(I):-_all(instance(I,N)), not enumeration(N), not structure(N). @@ -60,6 +60,7 @@ elem(icontainer(()), container, w). attr(eicontainer(I), class, ("d-flex";"flex-col")) :- einstance(I). attr(eicontainer(I), class, ("bg-secondary";"bg-opacity-25")) :- einstance(I). attr(eicontainer(I), background_color, "#D9D4F0") :- einstance(I). + attr(eicontainer((F,(P,C))), order, N) :- einstance((F,(P,C))), #count{(F',(P,C')):einstance((F',(P,C'))), F'>F}=N. % Container per enumeration for the title and one for each attribute @@ -81,8 +82,6 @@ elem(icontainer(()), container, w). attr(eititle_t((F,(P,C))), class, ("fw-lighter";"small")) :- einstance((F,(P,C))), instance((F,(P,C)),S). attr(eititle_t((F,(P,C))), order, 2) :- einstance((F,(P,C))), instance((F,(P,C)),S). - - elem(eioption(I), container, eititle(I)) :- eorainstance(I). attr(eioption(I), order, 3) :- eorainstance(I). @@ -92,10 +91,16 @@ elem(icontainer(()), container, w). attr(eioption_dd(I), selected, V) :- eorainstance(I), val(I,V), _clinguin_browsing. attr(eioption_dd(I), class, ("opacity-75";"btn-outline-dark")) :- eorainstance(I), _all(val(I,V)), not _clinguin_assume(val(I,V)), _any(val(I,V')), V'!=V. attr(eioption_dd(I), class, ("opacity-50")) :- eorainstance(I), _all(val(I,V)), not _clinguin_assume(val(I,V)), #false: _any(val(I,V')),V'!=V. + attr(eioption_dd(I), class, ("btn-danger")) :- _clinguin_muc(val(I,V)). - elem(eioption_ddi(I,V), dropdown_menu_item, eioption_dd(I)) :- eorainstance(I), _any(val(I,V)). - attr(eioption_ddi(I,V), label, V) :- eorainstance(I), _any(val(I,V)). - when(eioption_ddi(I,V), click, call, add_assumption(val(I,V))) :- eorainstance(I), _any(val(I,V)). + option((I,V),invalid):- einstance(I), option(T,V), instance(I,T), not _any(val(I,V)). + option(((A,(I,0)),V),invalid):- ainstance((A,(I,0))), attr_value(T,_,A,V), instance(I,T), not _any(val((A,(I,0)),V)). + option((I,V),valid):- eorainstance(I), _any(val(I,V)). + + elem(eioption_ddi(I,V), dropdown_menu_item, eioption_dd(I)) :- option((I,V),_). + attr(eioption_ddi(I,V), label, V) :- option((I,V),_). + when(eioption_ddi(I,V), click, call, add_assumption(val(I,V))) :- option((I,V),_). + attr(eioption_ddi(I,V), class, ("text-danger")) :- option((I,V),invalid). elem(eioption_ddi(I,remove), dropdown_menu_item, eioption_dd(I)) :- eorainstance(I). attr(eioption_ddi(I,remove), icon, "fa-ban") :- eorainstance(I). @@ -103,8 +108,6 @@ elem(icontainer(()), container, w). when(eioption_ddi(I,remove), click, call, remove_assumption_signature(val(I,any))) :- eorainstance(I). - - % Features elem(ifeatures(I), container, icontainer(I)) :- sinstance(I). attr(ifeatures(I), order, 4) :- sinstance(I). @@ -172,7 +175,7 @@ elem(icontainer(()), container, w). elem(menu_bar_download, button, menu_bar). attr(menu_bar_download, label, "Download"). attr(menu_bar_download, icon, "fa-download"). - when(menu_bar_download, click, call, download). + when(menu_bar_download, click, call, download("#show .#show instance(I,S) : instance(I,S), structure(S). #show val(X,V) : val(X,V), instance(X,Type), option(Type,_). #show val(X,V) : val(X,V), instance(X,Attr), attr_value(_,_,Attr,_).", "coom_solution.lp")). elem(menu_bar_select, button, menu_bar). @@ -183,4 +186,4 @@ elem(icontainer(()), container, w). elem(menu_bar_next, button, menu_bar). attr(menu_bar_next, label, "Next"). attr(menu_bar_next, icon, "fa-forward-step"). - when(menu_bar_next, click, call, next_solution). + when(menu_bar_next, click, call, next_solution). \ No newline at end of file From 807029a3656eb976db7465638f60e54fa99b3298 Mon Sep 17 00:00:00 2001 From: Susana Hahn Date: Mon, 25 Mar 2024 12:43:46 -0600 Subject: [PATCH 4/6] COnstraints --- coom_solution.lp | 11 ++++++ examples/asp/city-bike.lp | 13 ++++--- src/coomsolver/encodings/clingo-kids.lp | 6 --- src/coomsolver/encodings/show.lp | 6 +++ src/coomsolver/encodings/ui.lp | 52 ++++++++++++++++++++++--- 5 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 coom_solution.lp create mode 100644 src/coomsolver/encodings/show.lp diff --git a/coom_solution.lp b/coom_solution.lp new file mode 100644 index 0000000..5489b7f --- /dev/null +++ b/coom_solution.lp @@ -0,0 +1,11 @@ +val((size,((frontWheel,((),0)),0)),29). +val((size,((rearWheel,((),0)),0)),29). +val((position,((basket,((),0)),0)),"Back"). +val((saddle,((),0)),"Vintage"). +val((frontWheel,((),0)),"W29"). +val((rearWheel,((),0)),"W29"). +val((color,((),0)),"White"). +val((color,((basket,((),0)),0)),"White"). +instance((basket,((),0)),"Basket"). +instance((carrier,((),0)),"Carrier"). +instance((),":root"). \ No newline at end of file diff --git a/examples/asp/city-bike.lp b/examples/asp/city-bike.lp index 37982ab..8619242 100644 --- a/examples/asp/city-bike.lp +++ b/examples/asp/city-bike.lp @@ -12,6 +12,7 @@ feature("Basket",color,"Color",1,1). structure("Carrier"). feature("Carrier",bag,"Bag",0,2). +% :- not instance((basket,((),0)),"Basket"). structure("Bag"). feature("Bag",capacity,"Capacity",1,1). @@ -59,14 +60,14 @@ option("Material", "Cotton"). option("Material", "Leather"). option("Material", "Polyester"). -behavior((":root",0)). +{behavior((":root",0))}. require((":root",0),"color=basket.color"). binary(":root","color=basket.color","color","=","basket.color"). path("color",0,color). path("basket.color",0,basket). path("basket.color",1,color). -behavior((":root",1)). +{behavior((":root",1))}. condition((":root",1),"basket.position=Front"). binary(":root","basket.position=Front","basket.position","=","Front"). path("basket.position",0,basket). @@ -78,7 +79,7 @@ path("frontWheel.size",0,frontWheel). path("frontWheel.size",1,size). number("29",29). -behavior((":root",2)). +{behavior((":root",2))}. condition((":root",2),"carrier.bag.capacity.volume=100"). binary(":root","carrier.bag.capacity.volume=100","carrier.bag.capacity.volume","=","100"). path("carrier.bag.capacity.volume",0,carrier). @@ -92,7 +93,7 @@ path("rearWheel.size",0,rearWheel). path("rearWheel.size",1,size). number("28",28). -behavior((":root",3)). +{behavior((":root",3))}. condition((":root",3),"saddle=Vintage"). binary(":root","saddle=Vintage","saddle","=","Vintage"). path("saddle",0,saddle). @@ -104,7 +105,7 @@ path("carrier.bag.material",1,bag). path("carrier.bag.material",2,material). constant("Leather"). -behavior((":root",4)). +{behavior((":root",4))}. require((":root",4),"frontWheel.size=rearWheel.size"). binary(":root","frontWheel.size=rearWheel.size","frontWheel.size","=","rearWheel.size"). path("frontWheel.size",0,frontWheel). @@ -112,7 +113,7 @@ path("frontWheel.size",1,size). path("rearWheel.size",0,rearWheel). path("rearWheel.size",1,size). -behavior(("Bag",5)). +{behavior(("Bag",5))}. combinations(("Bag",5),0,"material"). combinations(("Bag",5),1,"capacity"). path("material",0,material). diff --git a/src/coomsolver/encodings/clingo-kids.lp b/src/coomsolver/encodings/clingo-kids.lp index 65da626..e78c293 100644 --- a/src/coomsolver/encodings/clingo-kids.lp +++ b/src/coomsolver/encodings/clingo-kids.lp @@ -91,12 +91,6 @@ enumeration("bool"). option("bool", "True"). option("bool", "False"). -% Show statements -#show . -#show instance(I,S) : instance(I,S), structure(S). - -#show val(X,V) : val(X,V), instance(X,Type), option(Type,_). -#show val(X,V) : val(X,V), instance(X,Attr), attr_value(_,_,Attr,_). #defined structure/1. #defined feature/5. diff --git a/src/coomsolver/encodings/show.lp b/src/coomsolver/encodings/show.lp new file mode 100644 index 0000000..8dbdc02 --- /dev/null +++ b/src/coomsolver/encodings/show.lp @@ -0,0 +1,6 @@ +% Show statements +#show . +#show instance(I,S) : instance(I,S), structure(S). + +#show val(X,V) : val(X,V), instance(X,Type), option(Type,_). +#show val(X,V) : val(X,V), instance(X,Attr), attr_value(_,_,Attr,_). \ No newline at end of file diff --git a/src/coomsolver/encodings/ui.lp b/src/coomsolver/encodings/ui.lp index f1d5ac8..ca56187 100644 --- a/src/coomsolver/encodings/ui.lp +++ b/src/coomsolver/encodings/ui.lp @@ -10,6 +10,9 @@ ainstance(I):-instance(I,N), not enumeration(N), not structure(N), _clinguin_br eorainstance(I):-einstance(I). eorainstance(I):-ainstance(I). pos_sinstance(I):-_any(instance(I,S)), structure(S). + +cons(I,(C,N)):-_all(constraint(I,(C,N))). + % For debugging % attr(E,class,("border-1";"border";"border-dark")):- elem(E, container, _). @@ -52,7 +55,7 @@ elem(icontainer(()), container, w). attr(ienumerations(I), order, 2) :- sinstance(I). attr(ienumerations(I), heigth, 50) :- sinstance(I). attr(ienumerations(I), class, ("d-flex";"flex-row")) :- sinstance(I). - attr(ienumerations(P), class, ("m-4")) :- sinstance(P), einstance((F,(P,C))). + attr(ienumerations(P), class, ("m-3")) :- sinstance(P), einstance((F,(P,C))). % Container per enumeration instance elem(eicontainer((F,(P,C))), container, ienumerations(P)) :- einstance((F,(P,C))). @@ -110,10 +113,10 @@ elem(icontainer(()), container, w). % Features elem(ifeatures(I), container, icontainer(I)) :- sinstance(I). - attr(ifeatures(I), order, 4) :- sinstance(I). + attr(ifeatures(I), order, 5) :- sinstance(I). attr(ifeatures(I), class, ("d-flex";"flex-col")) :- sinstance(I). % attr(ifeatures(I), background_color, white) :- sinstance(I). - attr(ifeatures(I), class, ("m-4")) :- sinstance(I), sinstance((F,(I,C))). + attr(ifeatures(I), class, ("m-3")) :- sinstance(I), sinstance((F,(I,C))). % Container per structre instance elem(icontainer((F,(P,C))), container, ifeatures(P)) :- sinstance((F,(P,C))), sinstance(P). @@ -125,10 +128,10 @@ elem(icontainer(()), container, w). % Add elem(iadd(I), container, icontainer(I)) :- sinstance(I). - attr(iadd(I), order, 3) :- sinstance(I). + attr(iadd(I), order, 4) :- sinstance(I). attr(iadd(I), class, ("d-flex";"flex-row")) :- sinstance(I). % attr(iadd(I), background_color, white) :- sinstance(I). - attr(iadd(I), class, ("m-4")) :- sinstance(I), sinstance((F,(I,C))). + attr(iadd(I), class, ("m-3")) :- sinstance(I), sinstance((F,(I,C))). % Container per structre instance % elem(iposf((F,(P,C))), container, iadd(P)) :- pos_sinstance((F,(P,C))), sinstance(P), not sinstance((F,(P,C))). @@ -147,6 +150,45 @@ elem(icontainer(()), container, w). % attr(iposf(I), class, ("bg-primary";"bg-opacity-10")) :- sinstance(I). % attr(iposf(I), class, ("d-flex";"flex-col";"border";"border-dark";"border-2";"rounded")) :- sinstance(I). + % Constraints + elem(icons(I), container, icontainer(I)) :- sinstance(I). + attr(icons(I), order, 3) :- sinstance(I). + attr(icons(I), heigth, 50) :- sinstance(I). + attr(icons(I), class, ("d-flex";"flex-row")) :- sinstance(I). + attr(icons(I), class, ("m-3")) :- sinstance(I), cons(I,C). + + + elem(icons(I,C), container, icons(I)) :- cons(I,C). + attr(icons(I,C), class, "bg-warning") :- cons(I,C). + attr(icons(I,C), class, ("m-2";"p-2";"rounded")) :- cons(I,C). + attr(icons(I,C), class, ("d-flex";"flex-col";"align-items-start")) :- cons(I,C). + attr(icons(I,C), class, ("bg-warning";"bg-opacity-25")) :- cons(I,C). + attr(icons(I,C), class, ("bg-danger";"bg-opacity-50")) :- cons(I,C), _clinguin_muc(behavior(C)). + + % Require Labels + elem(icons_lr(I,C), label, icons(I,C)) :- cons(I,C). + attr(icons_lr(I,C), label, S) :- cons(I,C), require(C, S). + + % Condition Labels + elem(icons_lc(I,C), label, icons(I,C)) :- cons(I,C). + attr(icons_lc(I,C), label, @concat("if ",S)) :- cons(I,C), condition(C, S). + attr(icons_lc(I,C), class, ("fw-light";"opacity-75")) :- cons(I,C), condition(C, S). + + % Table Labels + elem(icons_table(I,C), container, icons(I,C)) :- cons(I,C), combinations(C,_,_). + attr(icons_table(I,C), class, ("d-flex";"flex-row")) :- cons(I,C), combinations(C,_,_). + + elem(icons_table_col(I,C,Col), container,icons_table(I,C)) :- cons(I,C), combinations(C,Col,_). + attr(icons_table_col(I,C,Col), order, Col) :- cons(I,C), combinations(C,Col,_). + attr(icons_table_col(I,C,Col), class, ("d-flex";"flex-col")) :- cons(I,C), combinations(C,Col,_). + + allow(C,(Col,-1),Name):-cons(I,C), combinations(C,Col,Name). + elem(icons_table_cell(I,C,Col,Row), label,icons_table_col(I,C,Col)) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_cell(I,C,Col,Row), label,Name) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_cell(I,C,Col,Row), order,Row+1) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_cell(I,C,Col,Row), class,("border";"border-dark";"border-1")) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_cell(I,C,Col,Row), class,("fw-lighter")) :- cons(I,C), allow(C,(Col,Row),Name), Row>=0. + %%%%%%%%%%%%%%%%%%%%%%%% % Menu bar From cc029fdbd46ddc38773a8d94e0b01bc92f64540d Mon Sep 17 00:00:00 2001 From: Susana Hahn Date: Mon, 25 Mar 2024 12:47:51 -0600 Subject: [PATCH 5/6] Instructions to use clinguin --- README.md | 14 ++++++++++++++ src/coomsolver/encodings/ui.lp | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 92ad396..703c2ab 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,20 @@ Run the following for basic usage information: coomsolver -h ``` +## Clinguin + +Make sure you install clinguin with + +```bash +pip install clinguin +``` + +Run the following command to open the UI + +```bash +clinguin client-server --domain-files src/coomsolver/encodings/clingo-city.lp examples/asp/city-bike.lp --ui-files src/coomsolver/encodings/ui.lp --backend ExplanationBackend --assumption-signature behavior,1 +``` + ## Name ideas - coomsuite diff --git a/src/coomsolver/encodings/ui.lp b/src/coomsolver/encodings/ui.lp index ca56187..dee341d 100644 --- a/src/coomsolver/encodings/ui.lp +++ b/src/coomsolver/encodings/ui.lp @@ -1,3 +1,6 @@ +% TODOS +% Use new clinguin version, for @format "",and for additing choices to assumptions +% Idividual highlights when a constraint is hovered. % Auxiliaries sinstance(I):-_all(instance(I,S)), structure(S). @@ -33,7 +36,7 @@ elem(icontainer(()), container, w). attr(ititle_l(I), order, 1) :- sinstance(I), instance(I,S). elem(ititle_t(I), label, ititle(I)) :- sinstance(I). - attr(ititle_t((F,(P,C))), label, @format("({0})",S)) :- sinstance((F,(P,C))), instance((F,(P,C)),S). + attr(ititle_t((F,(P,C))), label, @format("","({0})",S)) :- sinstance((F,(P,C))), instance((F,(P,C)),S). attr(ititle_t(I), class, ("m-2";"fw-lighter")) :- sinstance(I), instance(I,S). attr(ititle_t(I), order, 2) :- sinstance(I), instance(I,S). @@ -81,7 +84,7 @@ elem(icontainer(()), container, w). attr(eititle_l((F,(P,C))), order, 1) :- eorainstance((F,(P,C))), instance((F,(P,C)),S). elem(eititle_t(I), label, eititle(I)) :- einstance(I). - attr(eititle_t((F,(P,C))), label, @format("({0})",S)) :- einstance((F,(P,C))), instance((F,(P,C)),S). + attr(eititle_t((F,(P,C))), label, @format("","({0})",S)) :- einstance((F,(P,C))), instance((F,(P,C)),S). attr(eititle_t((F,(P,C))), class, ("fw-lighter";"small")) :- einstance((F,(P,C))), instance((F,(P,C)),S). attr(eititle_t((F,(P,C))), order, 2) :- einstance((F,(P,C))), instance((F,(P,C)),S). @@ -171,7 +174,7 @@ elem(icontainer(()), container, w). % Condition Labels elem(icons_lc(I,C), label, icons(I,C)) :- cons(I,C). - attr(icons_lc(I,C), label, @concat("if ",S)) :- cons(I,C), condition(C, S). + attr(icons_lc(I,C), label, @concat("","if ",S)) :- cons(I,C), condition(C, S). attr(icons_lc(I,C), class, ("fw-light";"opacity-75")) :- cons(I,C), condition(C, S). % Table Labels From 8b0d2a1197538f08ce049921d6b3ec6b9380c8af Mon Sep 17 00:00:00 2001 From: Susana Hahn Date: Thu, 4 Apr 2024 15:29:21 -0600 Subject: [PATCH 6/6] Fixed UI: index, removed subinstance, table constraints --- coom_solution.lp | 11 -------- src/coomsolver/encodings/ui.lp | 47 ++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 coom_solution.lp diff --git a/coom_solution.lp b/coom_solution.lp deleted file mode 100644 index 5489b7f..0000000 --- a/coom_solution.lp +++ /dev/null @@ -1,11 +0,0 @@ -val((size,((frontWheel,((),0)),0)),29). -val((size,((rearWheel,((),0)),0)),29). -val((position,((basket,((),0)),0)),"Back"). -val((saddle,((),0)),"Vintage"). -val((frontWheel,((),0)),"W29"). -val((rearWheel,((),0)),"W29"). -val((color,((),0)),"White"). -val((color,((basket,((),0)),0)),"White"). -instance((basket,((),0)),"Basket"). -instance((carrier,((),0)),"Carrier"). -instance((),":root"). \ No newline at end of file diff --git a/src/coomsolver/encodings/ui.lp b/src/coomsolver/encodings/ui.lp index dee341d..8a040c6 100644 --- a/src/coomsolver/encodings/ui.lp +++ b/src/coomsolver/encodings/ui.lp @@ -16,6 +16,13 @@ pos_sinstance(I):-_any(instance(I,S)), structure(S). cons(I,(C,N)):-_all(constraint(I,(C,N))). +single_instance((I,(I',0))):-sinstance((I,(I',0))), not sinstance((I,(I',1))). +has_larger_instance((I,(I',N))):-sinstance((I,(I',N))), sinstance((I,(I',N+1))). + +sub_type(I,(I',(I,C))):-_all(instance(I,_)), _all(instance((I',(I,C)),_)). + sub_type(I,I''):- sub_type(I,I'), sub_type(I',I''). + sub_type(I,I):- _all(instance(I,_)). + % For debugging % attr(E,class,("border-1";"border";"border-dark")):- elem(E, container, _). @@ -31,7 +38,8 @@ elem(icontainer(()), container, w). attr(ititle(I), class, ("d-flex";"flex-row")) :- sinstance(I). elem(ititle_l(I), label, ititle(I)) :- sinstance(I). - attr(ititle_l((F,(P,C))), label,F) :- sinstance((F,(P,C))), instance((F,(P,C)),S). + attr(ititle_l((F,(P,C))), label,@concat("",F," [",C,"]")) :- sinstance((F,(P,C))), instance((F,(P,C)),S), not single_instance((F,(P,C))). + attr(ititle_l((F,(P,C))), label,F) :- sinstance((F,(P,C))), instance((F,(P,C)),S), single_instance((F,(P,C))). attr(ititle_l(I), class, ("h4")) :- sinstance(I), instance(I,S). attr(ititle_l(I), order, 1) :- sinstance(I), instance(I,S). @@ -44,14 +52,15 @@ elem(icontainer(()), container, w). elem(ititle_bc(I), container, ititle(I)) :- assumed_sinstance(I). attr(ititle_bc((F,(P,C))), class, ("ms-auto")) :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S). attr(ititle_bc((F,(P,C))), order, 3) :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S). - elem(ititle_b(I), button, ititle_bc(I)) :- assumed_sinstance(I). - attr(ititle_b((F,(P,C))), icon, "fa-xmark") :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S). - when(ititle_b(I), click, call, remove_assumption(instance(I,S))) :- assumed_sinstance(I), instance(I,S). - % Remove options - when(ititle_b(I), click, call, remove_assumption_signature(val((F,(I,C)),any))) :- assumed_sinstance(I), einstance((F,(I,C))). + %Remove + elem(ititle_b(I), button, ititle_bc(I)) :- assumed_sinstance(I), not has_larger_instance(I). + attr(ititle_b((F,(P,C))), icon, "fa-xmark") :- assumed_sinstance((F,(P,C))), instance((F,(P,C)),S), not has_larger_instance((F,(P,C))). + when(ititle_b(I), click, call, remove_assumption(instance(I',S))) :- assumed_sinstance(I), sub_type(I,I'), instance(I',S), not has_larger_instance(I). + when(ititle_b(I), click, call, remove_assumption_signature(val(I',any))) :- assumed_sinstance(I), sub_type(I,I'), not has_larger_instance(I). % Remove attr - when(ititle_b(I), click, call, remove_assumption_signature(val((F',((F,(I,C)),C')),any))) :- assumed_sinstance(I), einstance((F,(I,C))), ainstance((F',((F,(I,C)),C'))). - + % when(ititle_b(I), click, call, remove_assumption_signature(val((F',((F,(I',C)),C')),any))) :- assumed_sinstance(I), sub_type(I,I'), einstance((F,(I,C))), ainstance((F',((F,(I,C)),C'))). + % Remove sub instance + % when(ititle_b(I), click, call, remove_assumption(instance((I',(I,C)),S))) :- assumed_sinstance(I), assumed_sinstance((I',(I,C))), instance((I',(I,C)),S). % Enumerations elem(ienumerations(I), container, icontainer(I)) :- sinstance(I). @@ -123,6 +132,7 @@ elem(icontainer(()), container, w). % Container per structre instance elem(icontainer((F,(P,C))), container, ifeatures(P)) :- sinstance((F,(P,C))), sinstance(P). + attr(icontainer((F,(P,C))), order, C) :- sinstance((F,(P,C))). attr(icontainer(I), class, ("m-2";"p-2")) :- sinstance(I). % attr(icontainer(I), background_color, "#98B3EA") :- sinstance(I). % attr(icontainer(I), background_color, white) :- sinstance(I). @@ -171,11 +181,13 @@ elem(icontainer(()), container, w). % Require Labels elem(icons_lr(I,C), label, icons(I,C)) :- cons(I,C). attr(icons_lr(I,C), label, S) :- cons(I,C), require(C, S). + attr(icons_lr(I,C), order, 2) :- cons(I,C), require(C, S). % Condition Labels elem(icons_lc(I,C), label, icons(I,C)) :- cons(I,C). attr(icons_lc(I,C), label, @concat("","if ",S)) :- cons(I,C), condition(C, S). attr(icons_lc(I,C), class, ("fw-light";"opacity-75")) :- cons(I,C), condition(C, S). + attr(icons_lc(I,C), order, 1) :- cons(I,C), condition(C, S). % Table Labels elem(icons_table(I,C), container, icons(I,C)) :- cons(I,C), combinations(C,_,_). @@ -186,11 +198,18 @@ elem(icontainer(()), container, w). attr(icons_table_col(I,C,Col), class, ("d-flex";"flex-col")) :- cons(I,C), combinations(C,Col,_). allow(C,(Col,-1),Name):-cons(I,C), combinations(C,Col,Name). - elem(icons_table_cell(I,C,Col,Row), label,icons_table_col(I,C,Col)) :- cons(I,C), allow(C,(Col,Row),Name). - attr(icons_table_cell(I,C,Col,Row), label,Name) :- cons(I,C), allow(C,(Col,Row),Name). - attr(icons_table_cell(I,C,Col,Row), order,Row+1) :- cons(I,C), allow(C,(Col,Row),Name). - attr(icons_table_cell(I,C,Col,Row), class,("border";"border-dark";"border-1")) :- cons(I,C), allow(C,(Col,Row),Name). - attr(icons_table_cell(I,C,Col,Row), class,("fw-lighter")) :- cons(I,C), allow(C,(Col,Row),Name), Row>=0. + elem(icons_table_row(I,C,Col,Row), container,icons_table_col(I,C,Col)) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_row(I,C,Col,Row), class,("d-flex";"flex-row")) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_row(I,C,Col,Row), order,Row+1) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_row(I,C,Col,Row), class,("border";"border-dark";"border-1")) :- cons(I,C), allow(C,(Col,Row),Name). + + % elem(icons_table_cell(I,C,Col,Row), label,icons_table_row(I,C,Col,Row)) :- cons(I,C), allow(C,(Col,Row),Name). + % attr(icons_table_cell(I,C,Col,Row), label,Name) :- cons(I,C), allow(C,(Col,Row),Name). + % attr(icons_table_cell(I,C,Col,Row), class,("fw-lighter")) :- cons(I,C), allow(C,(Col,Row),Name), Row>=0. + + elem(icons_table_cell(I,C,Col,Row,Name), label,icons_table_row(I,C,Col,Row)) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_cell(I,C,Col,Row,Name), label,Name) :- cons(I,C), allow(C,(Col,Row),Name). + attr(icons_table_cell(I,C,Col,Row,Name), class,("fw-lighter";"p-1")) :- cons(I,C), allow(C,(Col,Row),Name), Row>=0. %%%%%%%%%%%%%%%%%%%%%%%% @@ -226,7 +245,7 @@ elem(icontainer(()), container, w). elem(menu_bar_select, button, menu_bar). attr(menu_bar_select, label, "Select solution"). attr(menu_bar_select, icon, "fa-hand-pointer"). - when(menu_bar_select, click, call, select). + when(menu_bar_select, click, call, select("#show instance/2. #show val/2.")). elem(menu_bar_next, button, menu_bar). attr(menu_bar_next, label, "Next").