Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
1
Wissensverarbeitung
Alexander Felfernig und Gerald SteinbauerInstitut für Softwaretechnologie
Inffeldgasse 16b/2A-8010 Graz
Austria
Wissensverarbeitung- Constraint Satisfaction -
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
2
Wissensverarbeitung
References• Skriptum (TU Wien, Institut für Informationssysteme,
Thomas Eiter et al.) ÖH-Copyshop, Studienzentrum
• Stuart Russell und Peter Norvig. Artificial Intelligence - A Modern Approach. Prentice Hall. 2003.
• Knowledge-based Configuration - From Research to Business Cases: Alexander Felfernig, Lothar Hotz, Claire Bagley, and Juha Tiihonen (ab Mai 2014).
• Vorlesungsfolien TU Graz (teilweise basierend auf den Folien der TUWien)
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
3
Wissensverarbeitung
References1. S. Brailsford, C. Potts, and B. Smith. Constraint Satisfaction Problems: Algorithms
and Applications, Europ. Jrnl. of Operations Research, 119:557-581, 1999. [OR1999]
2. A. Felfernig, G. Friedrich, K. Isak, K. Shchekotykhin, E. Teppan, and D. Jannach. Automated Debugging of Recommender User Interface Descriptions, Journal ofApplied Intelligence, Springer Verlag, 31(1):1-14, 2009. [AI2009]
3. A. Felfernig, G. Friedrich, D. Jannach, and M. Zanker, An Environment for the Development of Knowledge-based Recommender Applications, International Journal of Electronic Commerce (IJEC), 11(2), pp. 11-34, 2006. [IJEC2006]
4. A. Felfernig, Reducing Development and Maintenance Efforts for Web-based Recommender Applications, International Jrnl. of Web Engineering and Technology, 3(3):329-351, 2007. [WebEng2007]
5. E. Teppan, A. Felfernig: Minimization of Product Utility Estimation Errors in Recommender Result Set Evaluations. Web Intelligence 2009: 20-27, 2009. [WebIntelligence2009]
6. A. Felfernig, G. Friedrich, D. Jannach, and M. Stumptner, Consistency-basedDiagnosis of configuration knowledge bases, AI Journal, 152(2):213–234, 2004. [AIJ2004]
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
4
Wissensverarbeitung
References6. A. Felfernig, G. Friedrich, M. Schubert, M. Mandl, M. Mairitsch, and E. Teppan.
Plausible Repairs for Inconsistent Requirements, 21st International Joint Conference on Artificial Intelligence (IJCAI'09), Pasadena, California, USA, pp. 791-796, 2009. [IJCAI2009]
7. A. Felfernig and R. Burke. Constraint-based Recommender Systems: Technologies and Research Issues, ACM International Conference on Electronic Commerce (ICEC'08), Innsbruck, Austria, Aug. 19-22, pp. 17-26, 2008. [ICEC2008]
8. E.C. Freuder. In Pursuit of the Holy Grail. Constraints, 2(1): 57-61, 1997. [Constraints1997]
9. U. Junker. QUICKXPLAIN: Preferred Explanations and Relaxations for Over-Constrained Problems. 19th National Conference on AI (AAAI04), pages 167–172, 2004. [AAAI2004]
10. R. Reiter. A theory of diagnosis from first principles, AI Journal, 23(1):57–95, 1987. [AIJ1987]
11. S. Russel and P. Norvig. Artificial Intelligence - A Modern Approach, Prentice Hall, 2nd edition, 2002, see also: http://aima.cs.berkeley.edu [ArtInt2002]
12. A. Felfernig, M. Schubert, and C. Zehentner. An Efficient Diagnosis Algorithm for Inconsistent Constraint Sets, AI for Engineering Design, Analysis, and Manufacturing (AIEDAM), Cambridge University Press, 25(2):175—184, 2011. [AIEDAM2011]
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
5
Wissensverarbeitung
Goals
Modeling Constraint Satisfaction Problems (CSPs).Applications of constraint technologies.Solving CSPs.Debugging CSPs.
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
6
Wissensverarbeitung
Constraint Technologies
Constraint technologies are one of the closest approaches computer science has yet made to the Holy Grail of programming: a user states the problem, the computer solves it[Constraints1997].Example application areas:
- Configuration (e.g., cars, telecommunication switches)
- Scheduling (e.g., job shop scheduling, course scheduling)
- Recommendation (e.g., computers, financial services)
- Test case generation (e.g., in model-based testing)
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
7
Wissensverarbeitung
Constraint Satisfaction Problem (CSP)
Specific type of decision problem where different alternatives constrain each other
Alternatives are typically represented in the form of finite domain variables
Alternatives should be selected in a way that none of the constraints is violated
Users could have preferences on the inclusion of certain alternatives, e.g., prefer(Rome, Paris)
Optimization requirements could exist, e.g., minimizecosts in a building design, maximize number of used slots in a module
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
8
Wissensverarbeitung
A Constraint Satisfaction Problem (or CSP) is defined by a set of variables V = {v1,v2, …, vm}, and a set of constraints C = {c1, c2, …, cn}. Each variable vi has a nonempty domain dvi of possible values. Each constraint cj involves some subset of the variables and specifies the allowable combinations of values for that subset.
A state of the problem is defined by an assignment of values to some or all of the variables.
An assignment that does not violate any constraints is called a consistent or legal assignment.
A complete assignment is one in which every variable is mentioned, and a solution to a CSP is a complete assignment that satisfies all the constraints.
Let d be the domain size → O(d m)
Constraint Satisfaction Problem (CSP)
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
9
Wissensverarbeitung
V={v1, v2, v3}dv1=[1,2]dv2=[1,2,3]dv3=[1,2]
C={c1,c2}c1:v1>v2c2:v2=v3
Solutions …
CSPs: A Simple Example
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
10
Wissensverarbeitung
Types of ConstraintsUnary Constraints
– restrict the values of a single variable– e.g., v1 <> 5
Binary Constraints– binary constraints relate two variables– e.g., v1 > v2
Higher order constraints – involve three or more variables– e.g., (v1 = 5 or v2 = 3) and v4 > v5
Extensional vs. intensional– dom(vi)={1,2}– intensional: v1 = v2– extensional: {(1,1), (2,2)}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
11
Wissensverarbeitung
Boolean CSPsVariable domains with exactly two valuesAny CSP is convertible into a Boolean CSPSAT encoding
– a boolean variable indicates whether a certain value of a variable is set
Conventional representation– V={va, vb}; dva={1,2}; dvb={1,2}– C={c1: va>vb}
Corresponding SAT encoding– V={va1, va2, vb1, vb2}; dom(vai)=dom(vbi)={true, false}– C={c1: va2=true vb1=true va1=false vb2=false}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
12
Wissensverarbeitung
Conjunctive Queries
SELECT v1.a, v2.a, v3.aFROM v1,v2,v3WHERE v1.a > v2.a and v2.a = v3.a;
variables and
domains
constraints
Table v1 (a)12
Table v2 (a)123
Table v3 (a)12
solution
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
13
Wissensverarbeitung
PROLOG
– v1(1).– v1(2).– v2(1).– v2(2).– v2(3).– v3(1).– v3(2).
– c1(V1,V2):-V1>V2.– c2(V2,V3):-V2=V3.
– q(V1,V2,V3):-v1(V1),v2(V2),v3(V3),c1(V1,V2),c2(V2,V3).
variables and
domains
constraints
all constraints must be satisfied…
solutions …?- q(X,Y,Z).
X = 2Y = 1Z = 1 ;
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
14
Wissensverarbeitung
Map Coloring
– Map Coloring Problem: assign colors to each region s.t. no neighboring regions have the same color.
– Representation as CSP:• V = {WA, NT, SA, Q, NSW, V, T}; dvi = {red, green, blue};
• C = {WA≠NT, WA≠SA, NT≠SA, NT≠Q, SA≠Q,
SA≠NSW, SA≠V, Q≠NSW, NSW≠V}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
15
Wissensverarbeitung
– Example solution:• WA = red, NT = green, SA = blue, Q = red, NSW = green, V = red,
T = red ;
Map Coloring
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
16
Wissensverarbeitung
CHOCO
CHOCO: JAVA library for CSP solving.The central element of a CHOCO program is the Problem
object: Problem pb = new Problem();
Definition of variables: IntDomainVar WA = pb.makeEnumIntVar("WA", 0, 2);
Definition of constraints: pb.post(pb.neq(Map[0], Map[1]));
Operators, e.g.:neq(IntExp v1, IntExp v2) : v1 != v2. eq(IntExp v1, IntExp v2) : v1 = v2. leq(IntExp v1, IntExp v2) : v1 <= v2. lt(IntExp v1, IntExp v2) : v1 < v2. minus(IntExp exp1, IntExp exp2) : exp1 - exp2. plus(IntExp exp1, IntExp exp2) : exp1 + exp2.
16
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
17
Wissensverarbeitung
package chocosamples;import choco.Problem;import choco.integer.IntDomainVar;import java.util.logging.Logger;
public class map {…
public static void main(String[] args) {System.out.println(demo());
}
public static String demo() {…logger.fine("CHOCO Sample: Map Coloring");Problem pb = new Problem();
IntDomainVar WA = pb.makeEnumIntVar("WA", 0, 2);IntDomainVar NT = pb.makeEnumIntVar("NT", 0, 2);IntDomainVar SA = pb.makeEnumIntVar("SA", 0, 2);IntDomainVar Q = pb.makeEnumIntVar("Q", 0, 2);IntDomainVar NSW = pb.makeEnumIntVar("NSW", 0, 2);IntDomainVar V = pb.makeEnumIntVar("V", 0, 2);IntDomainVar T = pb.makeEnumIntVar("T", 0, 2);
IntDomainVar[] Map = {WA, NT, SA, Q, NSW, V, T};
pb.post(pb.neq(Map[0], Map[1]));pb.post(pb.neq(Map[0], Map[2]));pb.post(pb.neq(Map[1], Map[2]));pb.post(pb.neq(Map[1], Map[3]));pb.post(pb.neq(Map[2], Map[3]));pb.post(pb.neq(Map[2], Map[4]));pb.post(pb.neq(Map[2], Map[5]));pb.post(pb.neq(Map[3], Map[4]));pb.post(pb.neq(Map[4], Map[5]));
if (pb.solve() == Boolean.TRUE){
do {System.out.println("WA:" + WA.getVal());System.out.println("NT:" + NT.getVal());System.out.println("SA:" + SA.getVal());
System.out.println("Q:" + Q.getVal());System.out.println("NSW:" + NSW.getVal());
System.out.println("V:" + V.getVal());System.out.println("T:" + T.getVal());
System.out.println("\n");}
while(pb.nextSolution() == Boolean.TRUE);}
…}}
problemobject
variables
array ofvariables
constraints
output results
CHOCO
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
18
Wissensverarbeitung
a b c d e f g h8 87 76 65 54 43 32 21 1
a b c d e f g h
8 queens: positioning 8 queens on a 8x8 board (b): none of the queens
endangers any of the other queens.
Constraints (example):b11 = true
b1j = false (j=2..8)b11 = true bk1 = false (k=2..8)
b11 = true blm = false (8 ≥ l,m ≥ 2 l=m)
8 queens
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
19
Wissensverarbeitung
Magic Square
Magic Square: n2 numbers are arranged in a way s.t. the values in rows, columns, and diagonals result in the same sum.
Constraints (example):alldifferent(v11, v12, v13,
v21, v22, v23, v31, v32, v33)
sum(v11..v13) = …sum(v31..v33) = …sum(v11..v31) = …
2 7 6 159 5 1 154 3 8 1515 15 15 15
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
20
Wissensverarbeitung
Resource Allocation
Task:The following items should be distributed between three different containers:
1 barrel of fuel1 paper roll1 box of fireworks1 palette with 6 personal computers1 palette with computer games1 barell of old oil1 palette of roof tiles1 palette of aluminium rain pipes
Constraints:The following constraints have to be taken into account: c1: fuel and oil must not be combined
with fireworks in one container c2: personal computers and computer
games must be stored in one container c3: aluminium rain pipes must be stored
in container #3 c4: each container is allowed to have at
maximum 3 items c5: container #1 is not allowed to carry
fuel c6: if fuel is in container #3 then
container #2 must not store roof tiles
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
21
Wissensverarbeitung
Resource Allocation
V={fuel, paper, fireworks, computer, games, oil, rooftiles, rainpipes, c1fuel, c2fuel, c3fuel, c1paper, …, c3rainpipes}dfuel={1..3}dpaper={1..3}dfireworks={1..3}dcomputer={1..3}dgames={1..3}doil={1..3}drooftiles={1..3}drainpipes={1..3}dc1fuel={0,1}, …, dc3rainpipes={0,1}
C={c1, c2, c3, c4, c5, c6}c1: fuel <> fireworks and oil <>
fireworksc2: computer = games
c3: rainpipes = 3c4a: c1fuel=1 fuel=1 and
c2fuel=1 fuel=2 andc3fuel=1 fuel=3 … ?
c4b: c1fuel + c1paper + c1fireworks + c1computer + c1games + c1oil + c1rooftiles + c1rainpipes <=3 …
c5: fuel <> 1c6: not(fuel = 3 ) or not(rooftiles=2)
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
22
Wissensverarbeitung
Configuration Knowledge Base (CKB)Constraint Satisfaction Problem (CSP)– Variables V: {v1, v2, …, vm}
– Domains D: {dv1, dv2, …, dvm}
– Constraints C: {c1, c2, …, cn}
CSP Solution– assignment (S) of variables
in V consistent with the constraints ci C
Example: Configuration Problem V: Customer and product
properties VC={vc1, vc2, …, vck} VPROD={vp1, vp2, …, vpl}
D: Domains of VC and VPROD D={dvc1, …, dvck, dvp1, …, dvpl}
C: Compatibility (CC), filter (CF), product constraints (CPROD), and customer requirements (CR) CC={cc1,…, ccp} CF={cf1,…, cfq} CPROD={cp1,…, cpr} CR={cr1,…, crs}
[ICEC2008]
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
23
Wissensverarbeitung
Configuration: Simple Example– rr:exp-return-rate– wr:willingness-to-take-risks– ip:investment-period
– id:product-identifier– pr:return-rate– prl:risk-level– pip:investment-period
– dom(rr)={‘1-3%’,’>3-6%’,’>6-9%’,’>9%’}
– dom(wr)={low, medium, high}– dom(ip)={short-t, medium-t,
long-t}
– dom(id)=integer– dom(pr)=dom(rr)– dom(prl)=dom(wr)– dom(pip)=dom(ip)
cc1: wr=medium ip<>short-t cc2: wr=high ip=long-t cc3: ip=long-t rr=>3-6%
rr=>6-9% cc4: rr=>9% wr=high cc5: rr=>6-9% wr<>low
cf1: rr=pr cf2: wr=prl cf3: ip=pip
cr1: rr=1-3% cr2: wr=low cr3: ip=short-t
cp1: id=1 pr=‘1-3%’ prl=low pip=short-t … … cpr:id=r pr=‘>9%’ prl=high pip=long-t
VC
VPROD
D
CC
CF
CR
CPROD
Solution S: {rr=1-3%, wr=low, ip=short-t, id=1, pr=1-3%, prl=low, pip=short-t}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
24
Wissensverarbeitung
CSP Solving
Goal: find an assignment for the variables which is consistent and complete
Basic approach:– Select variable and assign a corresponding value– Test consistency between instantiated variables and
constraints– Backtrack in the case of an inconsistency
Backtracking is a complete search algorithm – every existing solution is found
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
25
Wissensverarbeitung
Backtracking
• „Uninformed“ algorithm which is very inefficient for large problems• Improvements: e.g., forward checking, local consistency
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
26
Wissensverarbeitung
Backtracking
Variable and value orderings
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
27
Wissensverarbeitung
Forward Checking
Whenever a variable vi is assigned, forward checking looks at each unassigned variable vj connected to vivia a constraint and deletes from vjs domain any value that is inconsistent with the value chosen from vi.
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
28
Wissensverarbeitung
Local Consistency
Node consistency: Node consistency requires that every unary constraint on a variable is satisfied by all values in the domain of the variable.
Arc consistency: A variable of a constraint satisfaction problem is arc-consistent with another one if each of its admissible values is consistent with some admissible value of the second variable. A CSP is arc consistent if every variable is arc consistent with any other one.
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
29
Wissensverarbeitung
Local Consistency
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
30
Wissensverarbeitung
Local Consistency
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
31
Wissensverarbeitung
Performance
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
32
Wissensverarbeitung
Exercisesa. Machen Sie das folgende CSP arc-consistent: V={v1, v2, v3}dv1=[1,2]dv2=[1,2,3]dv3=[1,2]
C={c1,c2}c1:v1>v2c2:v2=v3
b. Geben Sie Beispiele für Constraints zur Unterstützung der persönlichen LV Planung
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
33
Wissensverarbeitung
Configuration Knowledge Base (CKB)Constraint Satisfaction Problem (CSP)– Variables V: {v1, v2, …, vm}
– Domains D: {dv1, dv2, …, dvm}
– Constraints C: {c1, c2, …, cn}
CSP Solution– assignment (S) of variables
in V consistent with the constraints ci C
Example: Configuration Problem V: Customer and product
properties VC={vc1, vc2, …, vck} VPROD={vp1, vp2, …, vpl}
D: Domains of VC and VPROD D={dvc1, …, dvck, dvp1, …, dvpl}
C: Compatibility (CC), filter (CF), product constraints (CPROD), and customer requirements (CR) CC={cc1,…, ccp} CF={cf1,…, cfq} CPROD={cp1,…, cpr} CR={cr1,…, crs}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
34
Wissensverarbeitung
Configuration: Simple Example– rr:exp-return-rate– wr:willingness-to-take-risks– ip:investment-period
– id:product-identifier– pr:return-rate– prl:risk-level– pip:investment-period
– dom(rr)={‘1-3%’,’>3-6%’,’>6-9%’,’>9%’}
– dom(wr)={low, medium, high}– dom(ip)={short-t, medium-t,
long-t}
– dom(id)=integer– dom(pr)=dom(rr)– dom(prl)=dom(wr)– dom(pip)=dom(ip)
cc1: wr=medium ip<>short-t cc2: wr=high ip=long-t cc3: ip=long-t rr=>3-6%
rr=>6-9% cc4: rr=>9% wr=high cc5: rr=>6-9% wr<>low
cf1: rr=pr cf2: wr=prl cf3: ip=pip
cr1: rr=1-3% cr2: wr=low cr3: ip=short-t
cp1: id=1 pr=‘1-3%’ prl=low pip=short-t … … cpr:id=r pr=‘>9%’ prl=high pip=long-t
VC
VPROD
D
CC
CF
CR
CPROD
Solution S: {rr=1-3%, wr=low, ip=short-t, id=1, pr=1-3%, prl=low, pip=short-t}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
35
Wissensverarbeitung
Engineering of CKBs: Scenario
Knowledge Engineers are responsible for constraint acquisition & maintenance.
Domain experts articulate domain knowledge (often in terms of examples).
Constraints are changed very frequently.
The correctness of the knowledge base is crucial: faulty definitions would cause follow-up costs.
New constraints have to be integrated and tested as soon as possible.
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
36
Wissensverarbeitung
Engineering of CKBs
Goal: Effective testing & debugging of constraint setsApproach:
– induce conflicts in the constraint set– resolve the conflict sets using model-based diagnosis
Result: minimal diagnoses for constraint sets.
?
?
?
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
37
Wissensverarbeitung
Diagnosing Constraint Sets: Approach
c1
c2
c3
c4
cn
Constraint Set (C)
t1
t2
tp
Test Cases (T)+
should be:consistentbut are:
inconsistent
Diagnoses (i)
Conflict Set CS = {c1, c2, …, cq} C s.t. tiT: CS {ti} inconsistent. Minimal (CS): CS’ with CS’ CS.
…
…
c1
c2
c3
Conflict Sets (CSi)
c4
c2
c1
CS1
CSr
CS2 …
…
c1
c4
Diagnosis C: C - {ti} consistent ti T.
1
…
c2
c3
k
…
…
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
38
Wissensverarbeitung
Diagnosing Constraint Sets: Example
c1
c2
c3
c4
c5
Constraint Set (C)
t1
t2
Test Cases (T)+
should be:consistent
Diagnoses (i)
t1: wr=high rr=‘>9%’
t2: rr =>6-9% wr=medium
c1: wr=medium ip<>short-tc2: wr=high ip=long-tc3: ip=long-t rr=>3-6% rr=>6-9%c4: rr=>9% wr=highc5: rr=>6-9% wr<>low wr<>medium
c3
c3(t1 ok)
2={c5, c3}
but are: inconsistent
CS1c5
c5 (t2 ok)
c2
CS2
1={c5, c2}
c2 (t1 ok)
Constraints:
Test cases:
c2
c3
CS2
Conflict Sets (CSi)
c5
CS1
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
39
Wissensverarbeitung
Diagnosing Constraint Sets: Example
V={v1,v2,v3,v4}dv1=[1..4], dv2=[1..4], dv3=[1..3], dv4=[1..2]c1: v1 > v2
c2: v3 > v1
c3: v3 = v1
c4: v4 < v3
c5: v3 > v2
c6: v4 < v1
c7: v4 <> v2
Conflict Set CS = {c1, c2, …, cq} C s.t. CS inconsistent.
Minimal (CS): CS’ with CS’ CS.
Diagnosis C: C - consistent.
Solution?
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
40
Wissensverarbeitung
Determining Conflict Sets: Simple Algorithm (Sketch)V={v1,v2,v3,v4}; dv1=[1..4], dv2=[1..4], dv3=[1..3], dv4=[1..2]c1: v1 > v2, c2: v3 > v1, c3: v3 = v1, c4: v4 < v3, c5: v3 > v2, c6: v4 < v1, c7: v4 <> v2
v1 v2 v3 v4
1 1 1 1
2 2 2 2
3 3 3
4 4
v1 v2 v3 v4
1 1 1 1
2 2 2 2
3 3 3
4 4
v1 v2 v3 v4
1 1 1 1
2 2 2 2
3 3 3
4 4
v1 v2 v3 v4
1 1 1 1
2 2 2 2
3 3 3
4 4
c1 c2 c3 c3 c1 c2c3 c2 conflict set CS1: {c2, c3}
c1 c2 c4 c5 c6 c7c1 c2 c4 c5 c6c7 c6 c1 c2c7
c6 c2 c1c7 conflict set CS2: {c1,c2,c6,c7}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
41
Wissensverarbeitung
Determining Diagnoses:Simple Algorithm (Sketch)
CS1:{c2, c3}
diagnosis 1 {c2}
c2 c3
CS2:{c1, c2, c6, c7}c1
c2 c6c7diagnosis 2 {c1,c3}
¬diagnosis {c2,c3} (not minimal)
diagnosis 3 {c3,c6} diagnosis 4 {c3,c7}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
42
Wissensverarbeitung
Example Knowledge Representation
SELECT *FROM v1, v2, v3, v4WHERE v1.v1>v2.v2 And /*c1*/v3.v3>v1.v1 And /*c2*/v3.v3=v1.v1 And /*c3*/v4.v4<v3.v3 And /*c4*/v3.v3>v2.v2 And /*c5*/v4.v4<v1.v1 And /*c6*/v4.v4<>v2.v2; /*c7*//* original query …
no solution*/
variables and
domains
Table v1 (v1)
1234
Table v2 (v2)
1234
Table v3 (v3)
123
Table v4 (v4)
12
SELECT *FROM v1, v2, v3, v4WHERE v1.v1>v2.v2 And /*c1*/v3.v3>v1.v1 And /*c2*/v3.v3=v1.v1 And /*c3*/v4.v4<v3.v3 And /*c4*/v3.v3>v2.v2 And /*c5*/v4.v4<v1.v1 And /*c6*/v4.v4<>v2.v2; /*c7*//* query taking into
account 1*/
SELECT *FROM v1, v2, v3, v4WHERE v1.v1>v2.v2 And /*c1*/v3.v3>v1.v1 And /*c2*/v3.v3=v1.v1 And /*c3*/v4.v4<v3.v3 And /*c4*/v3.v3>v2.v2 And /*c5*/v4.v4<v1.v1 And /*c6*/v4.v4<>v2.v2; /*c7*//* query taking into
account 4*/
…
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
43
Wissensverarbeitung
Conflict Sets and Diagnoses: Add. Examples
V={v1,v2,v3}dv1=dv2=dv3=[1..3]c1:v1>v2
c2:v2>v3
c3:v3>v1
Conflict sets:– CS1={c1,c2,c3}
Diagnoses:– 1={c1}– 2={c2}– 3={c3}
V={v1,v2,v3} dv1=dv2=dv3=[1..3] c1:v1>v2 c2:v1<v2 c3:v2=v1 Conflict sets:
- CS1={c1,c2}- CS2={c1,c3}- CS3={c2,c3}
Diagnoses:- 1={c1,c2}- 2={c1,c3}- 3={c2,c3}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
44
Wissensverarbeitung
Simple Conflict Detection
C {c1, c2, …, cn}; /* C: all constraints*/B ; /* B: constraints part of the minimal conflict */IF inconsistent(C)
REPEAT B; /* : currently investigated constraint set */REPEAT
c element(C - ) /* c: one constraint */ {c};
UNTIL inconsistent()B B {c};
UNTIL inconsistent(B)RETURN (B);
#consistency checks: worst case: O(n2/2+n)
consistency checks best case: 3
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
45
Wissensverarbeitung
Example
V={v1,v2,v3}; dv1=dv2=dv3=[1..3]; C={c1,c2,c3}c1:v1>v2; c2:v2>v3; c3:v3>v1B: ; :
– c:c1; : {c1}– c:c2; : {c1, c2}– c:c3; : {c1, c2, c3}
B:{c3}; : {c3}– c:c1; : {c3,c1}– c:c2; : {c3,c1,c2}
B:{c3,c2}; : {c3,c2}– c:c1; : {c3,c2,c1}
B:{c3,c2,c1} /* minimal conflict set */
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
46
Wissensverarbeitung
Example
V={v1,v2,v3}; dv1=dv2=dv3=[1..3]; C={c1,c2,c3}c1:v1>v2; c2:v2=v1; c3:v3<>v1
B: ; : – c:c1; : {c1}– c:c2; : {c1, c2}
B:{c2}; : {c2}– c:c1; : {c2,c1}
B:{c2,c1} /* minimal conflict set */
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
47
Wissensverarbeitung
Example
V={v1,v2,v3}; dv1=dv2=dv3=[1..3]; C={c1,c2,c3}c1:v1>v2; c2:v2>v2; c3:v3<>v1
B: ; : – c:c1; : {c1}– c:c2; : {c1, c2}
B:{c2} /* minimal conflict set */
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
48
Wissensverarbeitung
QuickXPlain
QuickXPlain(C={c1,c2, …, cm})IF (is empty(C) or consistent(C)) return /* no inconsistency */ELSE return QX(, , C); /* C inconsistent */
QX(B, , C={c1,c2, …, cn})IF ( <> AND inconsistent(B)) return(); /* pruning of C */IF (C = {c}) return({c}); /* conflict element c detected */k=n/2;C1 {c1, …, ck}; C2 {ck+1, …, cn}; /* B still consistent */2 QX(B C1, C1, C2);1 QX(B 2, 2, C1);return (2 1)
#consistency checks: worst case: O(2k*log(m/k)+2k) best case: O(log(m/k)+2k
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
49
Wissensverarbeitung
Example
V={v1,v2,v3}; dv1=dv2=dv3=[1..3]; C={c1,c2,c3}c1:v1>v2; c2:v2>v3; c3:v3>v1
QuickXPlain(C={c1,c2,c3})
B=, C={c1,c2,c3}C1={c1} C2={c2,c3}
2={c3, c2}
{c3, c2,c1}
B={c1}, C={c2,c3}C1={c2} C2={c3}
B={c1,c2}, C={c3}2={c3}
B={c1,c3}, C={c2}
1={c2}
B={c3,c2}, C={c1}
1={c1}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
50
Wissensverarbeitung
ExampleV={v1,v2,v3}; dv1=dv2=dv3=[1..3]; C={c1,c2,c3}
c1:v1>v2; c2:v2=v2; c3:v2>v1;c4:3=3; c5:7=7;c6:v3=v3;c7:2=2;c8:3=3,c9:1=1,c10:2=2
QuickXPlain(C={c1..c10})
B=, C={c1..c10}C1={c1..c5} C2={c6..c10}
B={c1..c5}, C={c6..c10}C1={c6..c7} C2={c8..c10}
2= B=, C={c1..c5}
C1={c1..c2} C2={c3..c5}
B= {c1..c2}, C={c3..c5}C1={c3} C2={c4..c5}
B= {c1..c3},C={c4..c5}
2= B={c1..c2}, C={c3}
1= {c3}
2= {c3}B= {c3}, C={c1..c2}
C1={c1} C2={c2}
1= {c1}
B= {c3,c1}, C={c2}2=
B= {c3}, C={c1}
1={c1}
1= {c3,c1}
{c3,c1}
Alexander Felfernig & Gerald Steinbauer
Institute for Software Technology
51
Wissensverarbeitung
Exercisesa. Berechnen Sie alle minimalen Konflikte im folgenden
CSP mit Hilfe von „Simple Conflict Detection“: V={v1, v2, v3}dv1=[1,2]; dv2=[1,2]; dv3=[1,2]
C={c1,c2,c3}c1:v1>v2c2:v2>v3
c3:v3>v1
b. Repräsentieren Sie das o.a. CSP als conjunctive query.