Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrote condition/requires constraint to prop formulas #16

Merged
merged 12 commits into from
Jun 6, 2024
271 changes: 192 additions & 79 deletions examples/asp/city-bike.lp

Large diffs are not rendered by default.

113 changes: 87 additions & 26 deletions examples/asp/kids-bike.lp
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
% Parts of the model
part("root").

% Attributes of the model
attribute("Color","discrete").
discrete("Color").
domain("Color","Red").
domain("Color","Green").
domain("Color","Yellow").
domain("Color","Blue").

attribute("Wheel","discrete").
discrete("Wheel").
domain("Wheel","W14").
domain("Wheel","W16").
domain("Wheel","W18").
domain("Wheel","W20").

attribute("Wheel.size","numeric").
domain("Wheel.size",14).
domain("Wheel.size",16).
domain("Wheel.size",18).
domain("Wheel.size",20).
integer("Wheel.size").
range("Wheel.size",14,20).
% domain("Wheel.size",14).
% domain("Wheel.size",16).
% domain("Wheel.size",18).
% domain("Wheel.size",20).

% Complete instance tree
type("root","product").

type("root.color[0]","Color").
parent("root.color[0]", "root").
feature("root.color[0]","color").
parent("root.color[0]","root").
index("root.color[0]",0).

type("root.frontWheel[0]","Wheel").
parent("root.frontWheel[0]", "root").
feature("root.frontWheel[0]","frontWheel").
parent("root.frontWheel[0]","root").
index("root.frontWheel[0]",0).

type("root.frontWheel[0].size[0]","Wheel.size").
parent("root.frontWheel[0].size[0]","root.frontWheel[0]").
isnumeric("root.frontWheel[0].size[0]").
index("root.frontWheel[0].size[0]",0).

type("root.rearWheel[0]","Wheel").
parent("root.rearWheel[0]", "root").
feature("root.rearWheel[0]","rearWheel").
parent("root.rearWheel[0]","root").
index("root.rearWheel[0]",0).

type("root.rearWheel[0].size[0]","Wheel.size").
parent("root.rearWheel[0].size[0]","root.rearWheel[0]").
isnumeric("root.rearWheel[0].size[0]").
index("root.rearWheel[0].size[0]",0).

type("root.wheelSupport[0]","bool").
parent("root.wheelSupport[0]", "root").
feature("root.wheelSupport[0]","wheelSupport").
index("root.wheelSupport[0]",0).

% Instantiated constraints
constraint((0,"root")).
condition(0).
condition((0,"root"),"root.color[0]=Yellow").
constraint(0,"!root.color[0]=Yellow||root.frontWheel[0].size[0]>16").
binary("!root.color[0]=Yellow||root.frontWheel[0].size[0]>16","!root.color[0]=Yellow","||","root.frontWheel[0].size[0]>16").
unary("!root.color[0]=Yellow","!","root.color[0]=Yellow").
binary("root.color[0]=Yellow","root.color[0]","=","Yellow").
constant("Yellow").
require((0,"root"),"root.frontWheel[0].size[0]>16").
binary("root.frontWheel[0].size[0]>16","root.frontWheel[0].size[0]",">","16").
number("16",16).


constraint((1,"root")).
table((1,"root")).
column((1,"root"),0,0,"root.wheelSupport[0]").
column((1,"root"),0,1,"root.rearWheel[0]").
allow(1,(0,0),"True").
Expand All @@ -65,17 +67,24 @@ allow(1,(0,1),"False").
allow(1,(1,1),"W18").
allow(1,(1,1),"W20").

% binary("(root.wheelSupport[0]=True&&(root.rearWheel[0]=W14||root.rearWheel[0]=W16))||(root.wheelSupport[0]=False&&(root.rearWheel[0]=W18||root.rearWheel[0]=W20))","(root.wheelSupport[0]=True&&(root.rearWheel[0]=W14||root.rearWheel[0]=W16))","||","(root.wheelSupport[0]=False&&(root.rearWheel[0]=W18||root.rearWheel[0]=W20))").
% unary("(root.wheelSupport[0]=True&&(root.rearWheel[0]=W14||root.rearWheel[0]=W16))","()","root.wheelSupport[0]=True&&(root.rearWheel[0]=W14||root.rearWheel[0]=W16)").
% binary("root.wheelSupport[0]=True&&(root.rearWheel[0]=W14||root.rearWheel[0]=W16)","root.wheelSupport[0]=True","&&","(root.rearWheel[0]=W14||root.rearWheel[0]=W16)").
% unary("(root.rearWheel[0]=W14||root.rearWheel[0]=W16)","()","root.rearWheel[0]=W14||root.rearWheel[0]=W16").
% binary("root.rearWheel[0]=W14||root.rearWheel[0]=W16","root.rearWheel[0]=W14","||","root.rearWheel[0]=W16").
% binary("root.rearWheel[0]=W14","root.rearWheel[0]","=","W14")

constraint((2,"root")).
require((2,"root"),"root.frontWheel[0].size[0]=root.rearWheel[0].size[0]").
% unary("(root.wheelSupport[0]=False&&(root.rearWheel[0]=W18||root.rearWheel[0]=W20))","()","root.wheelSupport[0]=False&&(root.rearWheel[0]=W18||root.rearWheel[0]=W20)")

constraint(2,"root.frontWheel[0].size[0]=root.rearWheel[0].size[0]").
binary("root.frontWheel[0].size[0]=root.rearWheel[0].size[0]","root.frontWheel[0].size[0]","=","root.rearWheel[0].size[0]").

% Attribute constraints
constraint(("Wheel","root.frontWheel[0]")).
table(("Wheel","root.frontWheel[0]")).
column(("Wheel","root.frontWheel[0]"),0,0,"root.frontWheel[0]").
column(("Wheel","root.frontWheel[0]"),0,1,"root.frontWheel[0].size[0]").

constraint(("Wheel","root.rearWheel[0]")).
table(("Wheel","root.rearWheel[0]")).
column(("Wheel","root.rearWheel[0]"),0,0,"root.rearWheel[0]").
column(("Wheel","root.rearWheel[0]"),0,1,"root.rearWheel[0].size[0]").

Expand All @@ -87,3 +96,55 @@ allow("Wheel",(0,2),"W18").
allow("Wheel",(1,2),18).
allow("Wheel",(0,3),"W20").
allow("Wheel",(1,3),20).

% Cardinality constraints
% only need to check for min, not possible to exceed max as all possible objects are instantiated before
cardinality("root","root.color",1).
path("root.color","root.color[0]").

cardinality("root","root.wheelSupport",1).
path("root.wheelSupport","root.wheelSupport[0]").

cardinality("root","root.frontWheel",1).
path("root.frontWheel","root.frontWheel[0]").

cardinality("root.frontWheel[0]","root.frontWheel[0].size",1).
path("root.frontWheel[0].size","root.frontWheel[0].size[0]").

cardinality("root","root.rearWheel",1).
path("root.rearWheel","root.rearWheel[0]").

cardinality("root.rearWheel[0]","root.rearWheel[0].size",1).
path("root.rearWheel[0].size","root.rearWheel[0].size[0]").


% constraint("Cardinality","count(root.color)>=1").
% binary("count(root.color)>=1","count(root.color)",">=","1").
% function("count(root.color)","count","root.color").
% path("root.color","root.color[0]").
% number("1",1).

% constraint("Cardinality","count(root.wheelSupport)>=1").
% binary("count(root.wheelSupport)>=1","count(root.wheelSupport)",">=","1").
% function("count(root.wheelSupport)","count","root.wheelSupport").
% path("root.wheelSupport","root.wheelSupport[0]").

% constraint("Cardinality","count(root.frontWheel)>=1").
% binary("count(root.frontWheel)>=1","count(root.frontWheel)",">=","1").
% function("count(root.frontWheel)","count","root.frontWheel").
% path("root.frontWheel","root.frontWheel[0]").

% constraint("Cardinality","count(root.rearWheel)>=1").
% binary("count(root.rearWheel)>=1","count(root.rearWheel)",">=","1").
% function("count(root.rearWheel)","count","root.rearWheel").
% path("root.rearWheel","root.rearWheel[0]").

% constraint("Cardinality","count(root.frontWheel[0].size)>=1").
% binary("count(root.frontWheel[0].size)>=1","count(root.frontWheel[0].size)",">=","1").
% function("count(root.frontWheel[0].size)","count","root.frontWheel[0].size").
% path("root.frontWheel[0].size","root.frontWheel[0].size[0]").

% constraint("Cardinality","count(root.rearWheel[0].size)>=1").
% binary("count(root.rearWheel[0].size)>=1","count(root.rearWheel[0].size)",">=","1").
% function("count(root.rearWheel[0].size)","count","root.rearWheel[0].size").
% path("root.rearWheel[0].size","root.rearWheel[0].size[0]").
16 changes: 8 additions & 8 deletions examples/asp/pc-coom.lp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ coom_range("Application","price",50,50).

coom_behavior(0).
coom_context(0,"product").
coom_imply("product","price","sum(hdunit.price)+motherboard.price+sum(motherboard.cpu.price)+os.price+sum(screen.price)+sum(applications.price)").
coom_imply(0,"price","sum(hdunit.price)+motherboard.price+sum(motherboard.cpu.price)+os.price+sum(screen.price)+sum(applications.price)").
coom_path("price",0,"price").
coom_binary("sum(hdunit.price)+motherboard.price+sum(motherboard.cpu.price)+os.price+sum(screen.price)+sum(applications.price)","sum(hdunit.price)","+","motherboard.price+sum(motherboard.cpu.price)+os.price+sum(screen.price)+sum(applications.price)").
coom_binary("motherboard.price+sum(motherboard.cpu.price)+os.price+sum(screen.price)+sum(applications.price)","motherboard.price","+","sum(motherboard.cpu.price)+os.price+sum(screen.price)+sum(applications.price)").
Expand Down Expand Up @@ -212,9 +212,9 @@ coom_constant("CPUD").

coom_behavior(7).
coom_context(7,"HDUnit").
coom_imply("HDUnit","price","sum(hdisk.price)+sum(hdcontroller.price)").
coom_imply(7,"price","sum(hdisk.price)+sum(hdcontroller.price)").
coom_path("price",0,"price").
coom_binary("HDUnit","sum(hdisk.price)+sum(hdcontroller.price)","sum(hdisk.price)","+","sum(hdcontroller.price)").
coom_binary("sum(hdisk.price)+sum(hdcontroller.price)","sum(hdisk.price)","+","sum(hdcontroller.price)").
coom_function("HDUnit","sum(hdisk.price)","sum","hdisk.price").
coom_path("hdisk.price",0,"hdisk").
coom_path("hdisk.price",1,"price").
Expand All @@ -224,29 +224,29 @@ coom_path("hdcontroller.price",1,"price").

coom_behavior(8).
coom_context(8,"Motherboard").
coom_imply("Motherboard","price","mbtype.price").
coom_imply(8,"price","mbtype.price").
coom_path("price",0,"price").
coom_path("mbtype.price",0,"mbtype").
coom_path("mbtype.price",1,"price").

coom_behavior(9).
coom_context(9,"Motherboard").
coom_condition(9,"mbtype=MBSilver").
coom_binary("Motherboard","mbtype=MBSilver","mbtype","=","MBSilver").
coom_binary("mbtype=MBSilver","mbtype","=","MBSilver").
coom_path("mbtype",0,"mbtype").
coom_constant("MBSilver").
coom_require(9,"cpu!=CPUD").
coom_binary("Motherboard","cpu!=CPUD","cpu","!=","CPUD").
coom_binary("cpu!=CPUD","cpu","!=","CPUD").
coom_path("cpu",0,"cpu").
coom_constant("CPUD").

coom_behavior(10).
coom_context(10,"Motherboard").
coom_condition(10,"mbtype=MBDiamond").
coom_binary("Motherboard","mbtype=MBDiamond","mbtype","=","MBDiamond").
coom_binary("mbtype=MBDiamond","mbtype","=","MBDiamond").
coom_path("mbtype",0,"mbtype").
coom_constant("MBDiamond").
coom_require(10,"cpu!=CPUS").
coom_binary("Motherboard","cpu!=CPUS","cpu","!=","CPUS").
coom_binary("cpu!=CPUS","cpu","!=","CPUS").
coom_path("cpu",0,"cpu").
coom_constant("CPUS").
6 changes: 3 additions & 3 deletions examples/asp/travel-bike-coom.lp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ coom_feature("product","requestedVolume","num",1,1).
coom_range("product","requestedVolume",200,200).
coom_feature("product","frontWheel","Wheel",1,1).
coom_feature("product","rearWheel","Wheel",1,1).
coom_feature("product","frame","Frame",1,1).
coom_feature("product","carrier","Carrier",1,1).
coom_feature("product","frame","Frame",1,1).
coom_feature("product","color","Color",1,1).

coom_structure("Carrier").
Expand Down Expand Up @@ -84,7 +84,7 @@ coom_number("4",4).

coom_behavior(1).
coom_context(1,"product").
coom_imply("product","totalWeight","frontWheel.weight+rearWheel.weight+sum(carrier.bag.capacity.weight)+sum(frame.bag.capacity.weight)").
coom_imply(1,"totalWeight","frontWheel.weight+rearWheel.weight+sum(carrier.bag.capacity.weight)+sum(frame.bag.capacity.weight)").
coom_path("totalWeight",0,"totalWeight").
coom_binary("frontWheel.weight+rearWheel.weight+sum(carrier.bag.capacity.weight)+sum(frame.bag.capacity.weight)","frontWheel.weight","+","rearWheel.weight+sum(carrier.bag.capacity.weight)+sum(frame.bag.capacity.weight)").
coom_binary("rearWheel.weight+sum(carrier.bag.capacity.weight)+sum(frame.bag.capacity.weight)","rearWheel.weight","+","sum(carrier.bag.capacity.weight)+sum(frame.bag.capacity.weight)").
Expand Down Expand Up @@ -115,7 +115,7 @@ coom_number("1000",1000).

coom_behavior(3).
coom_context(3,"product").
coom_imply("product","totalVolume","sum(carrier.bag.capacity.volume)+sum(frame.bag.capacity.volume)").
coom_imply(3,"totalVolume","sum(carrier.bag.capacity.volume)+sum(frame.bag.capacity.volume)").
coom_path("totalVolume",0,"totalVolume").
coom_binary("sum(carrier.bag.capacity.volume)+sum(frame.bag.capacity.volume)","sum(carrier.bag.capacity.volume)","+","sum(frame.bag.capacity.volume)").
coom_function("product","sum(carrier.bag.capacity.volume)","sum","carrier.bag.capacity.volume").
Expand Down
Loading