flux. flux predicates holds(x, z) –asserts x in z knows(x, z) –x is known to be true in z...

34
FLUX

Upload: elliott-winson

Post on 14-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

FLUX

Page 2: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

FLUX Predicates

• holds(X, Z)– Asserts X in Z

• knows(X, Z)– X is known to be true in Z

• knows_val(X, V, Z)–

• update(Z1, FAdd, FRemove, Z2)– Z2 = Z1 + FAdd – FRemove

• execute(A, Z1, Z2)– Z2 is the state after executing A in Z1

)],[( ZXVknowsX

Page 3: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

FLUX as a Modeling Language

• perform(+Action, -Perceptions).– Executes the action on the environment simulator

– Returns the perception list

• state_update(Z1, Action, Z2, Perceptions)– Updates agent’s internal world model from Z1 to Z2,

provided Action has been executed and Perceptions have been detected

Page 4: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Non FLUX modeling

• Action preconditions (the poss/2 or 3 predicate)– Some examples do not include it

– The underlying code does not uses it

– Each example models it in a different way...• poss(Action, State)

• poss(Action, Perceptions, State)

• Model initialization• Planing• Environment simulator

Page 5: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

CHR Operational Semantics in FLUX

Page 6: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Agent View

• World Model– Execution State– Program Rules

• Actions– Transitions

• Execution– While a final state has not been reached

• Apply transitions non-deterministically

Page 7: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

World Model

},...,{},,...,{},,...,{ 000 nnn bbuugg

rule0 @ a, b \ c, d <=> g0 | b0.

rule1 @ x, y ==> g1 | b1.

init(Z) :-holds(goal(g0), Z), ..., holds(goal(gn), Z), holds(udstore(u0), Z), ..., holds(udstore(un), Z),holds(bicstore(b0), Z), ..., holds(bicstore(bn), Z), holds(rule(a, b \ c, d <=> g0 | b0), Z),holds(rule(x, y ==> g1 | b1), Z).

Page 8: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper Predicates

isBIC(true).

isBIC(false).

isBIC(_ == _).

isUDC(X) :- not isBIC(X).

Page 9: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper Predicates

• getVars(Constraints, Variables)– getVars([p(X), q(Y,X)], W), W = [X,Y].

• renameVars(HeadKeep0, HeadRemove0, Guard0, Body0, HeadKeep, HeadRemove, Guard, Body)

• findMatchingConstraints(Z, Constraints, Matching)

Page 10: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper Predicates

• generateMatchingEquations(Constraints, Matching, Equations)– generateMatchingEquations([c(X),d(Y)], [c(1),

d(2)], W = [X == 1, Y == 2].

Page 11: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper Predicates

• entails(Z, V, C, Z1)– Z = <G,U,B>– Z1 = <G,U,B’>– Z Z1– vCBCTBBCCT |'|

Page 12: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper Predicates

processBics(Z, _, [], Z).

processBics(Z, LV, [B|R], Zf) :- entails(Z,LV,B, Z1), update(Z1,[bicstore(B)], [], Z2),

processBics(Z2, LV, R,Zf).

Page 13: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper PredicatesremoveMatching(Z1, [], Z1).

removeMatching(Z1, [C|R], Z2) :-

removeMatching(Z1, R, Z12),

update(Z12, [], [udstore(C)], Z2).

addBody(Z1, [], Z1).

addBody(Z1, [C|R], Z2) :-

addBody(Z1, R, Z12),

update(Z12, [goal(C)], [], Z2).

addEquations(Z1, [], Z1).

addEquations(Z1, [C|R], Z2) :-

addEquations(Z1, R, Z12),

update(Z12, [bicstore(C)], [], Z2).

Page 14: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

state_update(Z1, introduce, Z2, []) :-

(knows_val([X], goal(X), Z1),

isUDC(X),

update(Z1, [udstore(X)], [goal(X)], Z2))

; Z1 = Z2.

Page 15: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

state_update(Z1, solve, Z2, []) :-

(knows_val([X], goal(X), Z1),

isBIC(X),

getVars([X], LV),

entails(Z1, LV, X, Z2))

; Z1 = Z2.

Page 16: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

state_update(Z1, simplify, Zf, []) :-

(knows_val([HeadRemove0, Guard0, Body0],rule(HeadRemove0 <==> Guard0 : Body0), Z1),

renameVars([], HeadRemove0, Guard0,

Body0, _, HeadRemove, Guard, Body),

...

Page 17: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

...

findMatchingConstraints(Z1, HeadRemove,Matching),

generateMatchingEquations(HeadRemove,

Matching, Equations),

getVars(HeadRemove, HeadVars),

getVars(Guard, GuardVars),

subtract(GuardVars, HeadVars, GuardLocalVars),

processBics(Z1, HeadVars, Equations, Z2),

processBics(Z2, GuardLocalVars, Guard, Z3),

...

Page 18: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

...

((knows(bicstore(false), Z3), fail)

;

(not knows(bicstore(false), Z3),

removeMatching(Z3, Matching, Z4),

addBody(Z4, Body, Z5),

addEquations(Z5, Equations, Zf)

)

)

) ; Z1 = Zf.

Page 19: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

CHOR Semantics in FLUX

Page 20: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

CHR + O

• F-Atoms are syntax sugar for special UD constraints using Kifer’s codification– O:C isa(O,C)– C::S sub(C,S)– X[F->V] fd(X,F,V)

• A new transition was added. It completes the current UD-store with information inherited by the means of inheritance

• Syntatic constraints:– O:C and C::S cannot appear on HeadRemove

Page 21: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Helper Predicates

isFAtom(isa(_,_)).

isFAtom(sub(_,_)).

isFAtom(fd(_,_,_)).

Page 22: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

'),(

'),(),,,(

),,(

),,,(

|),,('

'),('),(

),,(|),,,(

'

'),('),(

'),(),(),(,,

'),(),(),(,,

)(,

',''',,,

10

10

01

1111

000

0

0

00

00

ISAISAccisa

SUBSUBccsub

cc

CANDIDATEvfccvc

FDvfcfdvvv

CANDIDATEvfcc

cvfcfdFD

ISAISAccisaSUBSUBccsub

FDvfcfdvfccCANDIDATE

falseDD

ISAISAxxisaxSUBSUBxxsubx

ISAzxisaSUBzysubISAyxisazyx

SUBzxsubSUBzysubSUByxsubzyx

xIsFAtomGx

DUFDFDISAISASUBSUBGDUFDISASUBG Inherit

TaxonomyCompletion

TaxonomyValidation

Feature Inheritance

validadeCycles/2

propagateSub/2propagateIsa/2

computeInheritedFeatures/2

computeOverriding/3

cancelOverridenByCS/3

Page 23: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

state_update(Z1, inherit, Zf, []) :-

(not (knows_val([X], goal(X), Z1), isFAtom(X)),

handleTypeInheritance(Z1, Z2),

handleFeatureInheritance(Z2,Zf)) ; Z1 = Zf.

handleTypeInheritance(Z1, Zf) :-

propagateSub(Z1,Z2),

propagateIsa(Z2,Z3),

validateCycles(Z3,Zf).

Page 24: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

handleFeatureInheritance(Z,Zf) :-

computeInheritedFeatures(Z,Candidates),

computeOverriding(Z,Candidates, CandidatesWithOutOverriden),

cancelOverridenByCS(Z, CandidatesWithOutOverriden,

CandidatesWithOutOverridenExt),

computeSourceValue(Z,CandidatesWithOutOverridenExt,

CandidatesFinal, Conflicts),

transformCandidates(CandidatesFinal, NewFeatures),

update(Z, NewFeatures, [], Z1),

getVars(Conflicts, VarC),

processBics(Z1, VarC, Conflicts, Zf).

Page 25: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Examples

Page 26: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Clyde

rule1 @@ main <==>

clyde:royalElephant,

royalElephant::elephant,

elephant[color->gray],

royalElephant[color->white) ].

Page 27: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Clyde (Results)

clyde[color->white]

clyde:elephant

royalElephant[color->white]

elephant[color->gray]

royalElephant::elephant

clyde:royalElephant

Page 28: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Nixon diamond

rule1 @@ main <==>

quaker[policy->pacifist], republican[policy->hawk], nixon:quaker, nixon:republican.

Page 29: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Nixon Diamond (Results)Source Based Multiple

Inheritance

nixon : republican

nixon : quaker

republican[policy -> hawk]

quaker[policy -> pacifist]

Page 30: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Nixon Diamond (Results)Value Based

Multiple Inheritancenixon[policy->pacifist]

nixon[policy->hawk]

nixon:republican

nixon:quaker

Republican[policy->hawk]

quaker[policy->pacifist]

hawk==pacifist

pacifist==hawk

false

Page 31: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Example 2.5.1 (Adapt.)

rule1 @@ main <==>

c1::c2, c2[m->a].

rule2 @@ c1[m->a] \ c2[m->a] <==> c2[m->b].

Page 32: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Example 2.5.1 (Adapt.)(Results)

c1[m->a]

c2[m->b]

c1::c2

Page 33: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Example 2.5.3

rule1 @@ main <==>

c1:c2, c3::c2,

c2[m->a], c3[m->b].

rule2 @@ c1[m->a] ===> c1:c3.

Page 34: FLUX. FLUX Predicates holds(X, Z) –Asserts X in Z knows(X, Z) –X is known to be true in Z knows_val(X, V, Z) – update(Z1, FAdd, FRemove, Z2) –Z2 = Z1

Example 2.5.3 (Results)

c1 : c3

c1[m-> a]

c3[m->b]

c2[m->a]

c3 :: c2

c1 : c2