Improving Constraint Logic Programming and BIM-Spatial Reasoning - - PowerPoint PPT Presentation

improving constraint logic programming and bim spatial
SMART_READER_LITE
LIVE PREVIEW

Improving Constraint Logic Programming and BIM-Spatial Reasoning - - PowerPoint PPT Presentation

August 13, 2019 [Aalto University, Helsinki] Improving Constraint Logic Programming and BIM-Spatial Reasoning using CLP n Arias 1 , 2 Joaqu 1 IMDEA Software Institute, 2 Universidad Polit ecnica de Madrid madrid institute for advanced


slide-1
SLIDE 1

Improving Constraint Logic Programming and BIM-Spatial Reasoning using CLP

August 13, 2019 [Aalto University, Helsinki]

Joaqu´ ın Arias1,2

1IMDEA Software Institute, 2Universidad Polit´

ecnica de Madrid

madrid institute for advanced studies in software development technologies

slide-2
SLIDE 2

1 / 17

www.software.imdea.org

Outline.

  • About me.
  • Introduction to (Constraint) Logic Programming (CLP).
  • Improving CLP:
  • TCLP = tabling + Constraints.
  • Incremental evaluation of aggregates.
  • Implementation of an Abstract Interpreter Algorithm.
  • s(CAPS) = ASP + Constraints - Grounding.
  • Modelling and reasoning in Event Calculus.
  • Spatial reasoning in Building Information Modelling (BIM) using CLP

.

madrid institute for advanced studies in software development technologies

slide-3
SLIDE 3

2 / 17

www.software.imdea.org

About me.

Founded 1971 Faculty members 2887 Research groups 200 PhD students 1900 Grade/Master students 26738 Sport groups 18 Founded 2006 Faculty members 19 Postdoctoral researchers 16 Programmers 3 Research assistants 26 Interns 29 Founded 2008 Partners 195 Start-ups supported 280 I&E students1 170 Master students1 1700

1since its beginning

madrid institute for advanced studies in software development technologies

slide-4
SLIDE 4

2 / 17

www.software.imdea.org

About me.

1993-2002 Architect

1999-2000 RWTH-Aachen

2011-2015 Computer Science 2015- PhD Student in DSSC

Summer’17 UTD-Dallas Summer’19 A!-Helsinki

2013-2014 Intern 2014- Research Assistant

Advisor: Dr. Manuel Carro

2015- I&E student

Summer’19 VisuaLynk Oy

madrid institute for advanced studies in software development technologies

slide-5
SLIDE 5

2 / 17

www.software.imdea.org

About me.

1993-2002 Architect

1999-2000 RWTH-Aachen

2011-2015 Computer Science 2015- PhD Student in DSSC

Summer’17 UTD-Dallas Summer’19 A!-Helsinki

2013-2014 Intern 2014- Research Assistant

Advisor: Dr. Manuel Carro

2015- I&E student

Summer’19 VisuaLynk Oy

2010 & 2015 I love biking

madrid institute for advanced studies in software development technologies

slide-6
SLIDE 6

3 / 17

www.software.imdea.org

(Constraint) Logic Programming?

madrid institute for advanced studies in software development technologies

slide-7
SLIDE 7

3 / 17

www.software.imdea.org

(Constraint) Logic Programming?

madrid institute for advanced studies in software development technologies

slide-8
SLIDE 8

3 / 17

www.software.imdea.org

(Constraint) Logic Programming?

  • Is based on 1st order logic.

∀x. man(x) → mortal(x)

madrid institute for advanced studies in software development technologies

slide-9
SLIDE 9

3 / 17

www.software.imdea.org

(Constraint) Logic Programming?

  • Is based on 1st order logic.

∀x. man(x) → mortal(x)

  • You write logical specifications of searches

and get them executed.

1

mortal(X) :- man(X). % X is mortal if X is a man.

2

man(socrates). % Socrates is a man. ?- mortal(socrates). % Is Socrates mortal?

madrid institute for advanced studies in software development technologies

slide-10
SLIDE 10

3 / 17

www.software.imdea.org

(Constraint) Logic Programming?

  • Is based on 1st order logic.

∀x. man(x) → mortal(x)

  • You write logical specifications of searches

and get them executed.

1

mortal(X) :- man(X). % X is mortal if X is a man.

2

man(socrates). % Socrates is a man. ?- mortal(socrates). % Is Socrates mortal?

  • Passive vs Active Constraints

% Search and filter % Prune the search ?- age(X,A), A > 18. ?- A #> 18, age(X,A).

madrid institute for advanced studies in software development technologies

slide-11
SLIDE 11

4 / 17

www.software.imdea.org

(Constraint) Logic Programming?

1

% append(X,Y,Z) true if X concatenated with Y is Z

2

append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).

3

append( [], Ys, Ys). ?- append([1],[2,3], X). X = [1,2,3] ? madrid institute for advanced studies in software development technologies

slide-12
SLIDE 12

4 / 17

www.software.imdea.org

(Constraint) Logic Programming?

1

% append(X,Y,Z) true if X concatenated with Y is Z

2

append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).

3

append( [], Ys, Ys). ?- append([1],[2,3], X). X = [1,2,3] ? ?- append(X, Y, [1,2,3]). madrid institute for advanced studies in software development technologies

slide-13
SLIDE 13

4 / 17

www.software.imdea.org

(Constraint) Logic Programming?

1

% append(X,Y,Z) true if X concatenated with Y is Z

2

append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).

3

append( [], Ys, Ys). ?- append([1],[2,3], X). X = [1,2,3] ? ?- append(X, Y, [1,2,3]). X = [], Y = [1,2,3] ?; X = [1], Y = [2,3] ?; X = [1,2], Y = [3] ?; X = [1,2,3], Y = [] ? madrid institute for advanced studies in software development technologies

slide-14
SLIDE 14

4 / 17

www.software.imdea.org

(Constraint) Logic Programming?

1

% append(X,Y,Z) true if X concatenated with Y is Z

2

append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).

3

append( [], Ys, Ys). ?- append([1],[2,3], X). X = [1,2,3] ? ?- append(X, Y, [1,2,3]). X = [], Y = [1,2,3] ?; X = [1], Y = [2,3] ?; X = [1,2], Y = [3] ?; X = [1,2,3], Y = [] ?

When the Top-Down execution loops due to:

  • Left recursion:

1

path(A,B) :- path(A,Z), edge(Z,B).

2

path(A,B) :- edge(A,B).

  • Non-stratified negation:

1

p(X) :- not q(X).

2

q(X) :- not p(X). madrid institute for advanced studies in software development technologies

slide-15
SLIDE 15

4 / 17

www.software.imdea.org

(Constraint) Logic Programming?

1

% append(X,Y,Z) true if X concatenated with Y is Z

2

append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).

3

append( [], Ys, Ys). ?- append([1],[2,3], X). X = [1,2,3] ? ?- append(X, Y, [1,2,3]). X = [], Y = [1,2,3] ?; X = [1], Y = [2,3] ?; X = [1,2], Y = [3] ?; X = [1,2,3], Y = [] ?

When the Top-Down execution loops due to:

  • Left recursion:

1

path(A,B) :- path(A,Z), edge(Z,B).

2

path(A,B) :- edge(A,B).

  • Non-stratified negation:

1

p(X) :- not q(X).

2

q(X) :- not p(X).

Solution:

  • Tabling [17; 15; 21]
  • Suspends repeated calls & reuses answers.
  • Improves termination and efficiency.
  • s(ASP) [12; 13]
  • Goal directed (without grounding).
  • Stable model semantics & constructive negation.

madrid institute for advanced studies in software development technologies

slide-16
SLIDE 16

5 / 17

www.software.imdea.org

Mod TCLP .

Modular TCLP: Modular integration of tabling + Constraints [Arias and Carro 2016, 2019a].

  • Adding constraint variant check is extended with entailment check.

1

p(X) :- X #> Y, p(Y).

2

p(0). ?- p(A).

  • Also more particular calls suspend p(Y){Y < X} entails p(X).
  • Termination guaranteed for compact constraint domains [18].
  • Previous proposals not fully use entailment [16; 9] or not modular [8].

madrid institute for advanced studies in software development technologies

slide-17
SLIDE 17

5 / 17

www.software.imdea.org

Mod TCLP .

Modular TCLP: Modular integration of tabling + Constraints [Arias and Carro 2016, 2019a].

  • Adding constraint variant check is extended with entailment check.

1

p(X) :- X #> Y, p(Y).

2

p(0). ?- p(A).

  • Also more particular calls suspend p(Y){Y < X} entails p(X).
  • Termination guaranteed for compact constraint domains [18].
  • Previous proposals not fully use entailment [16; 9] or not modular [8].

Additionally:

  • Answers checked for entailment: only more general answers kept.
  • Less resumptions: speedup.

madrid institute for advanced studies in software development technologies

slide-18
SLIDE 18

5 / 17

www.software.imdea.org

Mod TCLP .

Modular TCLP: Modular integration of tabling + Constraints [Arias and Carro 2016, 2019a].

  • Adding constraint variant check is extended with entailment check.

1

p(X) :- X #> Y, p(Y).

2

p(0). ?- p(A).

  • Also more particular calls suspend p(Y){Y < X} entails p(X).
  • Termination guaranteed for compact constraint domains [18].
  • Previous proposals not fully use entailment [16; 9] or not modular [8].

Additionally:

  • Answers checked for entailment: only more general answers kept.
  • Less resumptions: speedup.
  • Termination guaranteed for programs that generate compact constraint stores [Arias & Carro].

madrid institute for advanced studies in software development technologies

slide-19
SLIDE 19

5 / 17

www.software.imdea.org

Mod TCLP .

Modular TCLP: Modular integration of tabling + Constraints [Arias and Carro 2016, 2019a].

  • Adding constraint variant check is extended with entailment check.

1

p(X) :- X #> Y, p(Y).

2

p(0). ?- p(A).

  • Also more particular calls suspend p(Y){Y < X} entails p(X).
  • Termination guaranteed for compact constraint domains [18].
  • Previous proposals not fully use entailment [16; 9] or not modular [8].

Additionally:

  • Answers checked for entailment: only more general answers kept.
  • Less resumptions: speedup.
  • Termination guaranteed for programs that generate compact constraint stores [Arias & Carro].
  • (Involved) implementation available in Ciao Prolog.

http://www.ciao-lang.org madrid institute for advanced studies in software development technologies

slide-20
SLIDE 20

6 / 17

www.software.imdea.org

Mod TCLP .

Termination comparison: Find nodes in a weighted graph within a distance K from each other. (using comparable –very similar– programs).

1

dist(A,B,D) :- D1 #> 0, D2 #> 0, D #= D1+D2,

2

dist(A,Z,D1), edge(Z,B,D2).

3

dist(A,B,D) :- edge(A,B,D). ?- D #< K, dist(a,b,D). Graph LP CLP TAB TCLP Without cycles Left recursion x x

  • Right recursion
  • With cycles

Left recursion x x x

  • Right recursion

x

  • x
  • n

1 2 3 4 madrid institute for advanced studies in software development technologies

slide-21
SLIDE 21

7 / 17

www.software.imdea.org

Mod TCLP: Application I.

Incremental evaluation of aggregates: [Arias and Carro 2019c] Instead of collect all the elements S={1,2,3} and then compute the aggregate min(S)=1.

  • Increases efficiency (memory / speed) & termination (e.g., reachability with shortest path).
  • Standard least fixpoint semantics not well-suited for programs with aggregates [11; 14; 19].
  • The behavior of implementations featuring aggregates [XSB,B-Prolog,Yap] is sometimes erratic [19].

madrid institute for advanced studies in software development technologies

slide-22
SLIDE 22

7 / 17

www.software.imdea.org

Mod TCLP: Application I.

Incremental evaluation of aggregates: [Arias and Carro 2019c] Instead of collect all the elements S={1,2,3} and then compute the aggregate min(S)=1.

  • Increases efficiency (memory / speed) & termination (e.g., reachability with shortest path).
  • Standard least fixpoint semantics not well-suited for programs with aggregates [11; 14; 19].
  • The behavior of implementations featuring aggregates [XSB,B-Prolog,Yap] is sometimes erratic [19].

We Propose

  • a new semantics for lattice-based aggregated that makes answers to queries

be consistent the usual least fixpoint semantics of logic programming...

madrid institute for advanced studies in software development technologies

slide-23
SLIDE 23

7 / 17

www.software.imdea.org

Mod TCLP: Application I.

Incremental evaluation of aggregates: [Arias and Carro 2019c] Instead of collect all the elements S={1,2,3} and then compute the aggregate min(S)=1.

  • Increases efficiency (memory / speed) & termination (e.g., reachability with shortest path).
  • Standard least fixpoint semantics not well-suited for programs with aggregates [11; 14; 19].
  • The behavior of implementations featuring aggregates [XSB,B-Prolog,Yap] is sometimes erratic [19].

We Propose

  • a new semantics for lattice-based aggregated that makes answers to queries

be consistent the usual least fixpoint semantics of logic programming...

  • ...and a clean, easy-to-use interface, based on an extended TCLP

, to define the operations on which the aggregates (also non-lattice based) are built.

madrid institute for advanced studies in software development technologies

slide-24
SLIDE 24

8 / 17

www.software.imdea.org

Mod TCLP: Application II.

Implementation of an Abstract Interpretation Algorithm using Tabled CLP: [Arias and Carro 2019b] We adapted PLAI, a fixpoint algorithm for the abstract interpretation of logic programs included in CiaoPP:

  • The tabling engine drives the fixpoint computation.
  • The constraint solver handles the LUB of the abstract substitutions of different clauses.
  • Determining whether the fixpoint has been reached uses semantic equivalence.

madrid institute for advanced studies in software development technologies

slide-25
SLIDE 25

8 / 17

www.software.imdea.org

Mod TCLP: Application II.

Implementation of an Abstract Interpretation Algorithm using Tabled CLP: [Arias and Carro 2019b] We adapted PLAI, a fixpoint algorithm for the abstract interpretation of logic programs included in CiaoPP:

  • The tabling engine drives the fixpoint computation.
  • The constraint solver handles the LUB of the abstract substitutions of different clauses.
  • Determining whether the fixpoint has been reached uses semantic equivalence.

Conclusion

  • The resulting implementation is one-third the size of the implementation in CiaoPP

.

madrid institute for advanced studies in software development technologies

slide-26
SLIDE 26

8 / 17

www.software.imdea.org

Mod TCLP: Application II.

Implementation of an Abstract Interpretation Algorithm using Tabled CLP: [Arias and Carro 2019b] We adapted PLAI, a fixpoint algorithm for the abstract interpretation of logic programs included in CiaoPP:

  • The tabling engine drives the fixpoint computation.
  • The constraint solver handles the LUB of the abstract substitutions of different clauses.
  • Determining whether the fixpoint has been reached uses semantic equivalence.

Conclusion

  • The resulting implementation is one-third the size of the implementation in CiaoPP

.

  • We compare their performance analyzing several programs using domains relevant

for program optimization and correctness of parallelization:

  • Using Groundness TCLP speed-up in 21/24 programs with an average of 1.31.
  • Using Sharing+Freeness TCLP speed up in 11/14 programs with an average of 0.97.

madrid institute for advanced studies in software development technologies

slide-27
SLIDE 27

9 / 17

www.software.imdea.org

s(CASP).

s(CASP): Extending s(ASP) with constraints [Arias et al. 2018].

  • Grounding phase an issue since ranges of (constrained) variables may be infinite.
  • Current CASP systems (e.g., EZCSP [7] and clingo[DL/LP] [10]) limit (some of):
  • Admissible constraint domains.
  • Where constraints can appear.
  • Type / number of models computed.

madrid institute for advanced studies in software development technologies

slide-28
SLIDE 28

9 / 17

www.software.imdea.org

s(CASP).

s(CASP): Extending s(ASP) with constraints [Arias et al. 2018].

  • Grounding phase an issue since ranges of (constrained) variables may be infinite.
  • Current CASP systems (e.g., EZCSP [7] and clingo[DL/LP] [10]) limit (some of):
  • Admissible constraint domains.
  • Where constraints can appear.
  • Type / number of models computed.

Main points:

  • We re-implemented the s(ASP) interpreter: Prolog takes care of environment.
  • Increased flexibility and performance.

madrid institute for advanced studies in software development technologies

slide-29
SLIDE 29

9 / 17

www.software.imdea.org

s(CASP).

s(CASP): Extending s(ASP) with constraints [Arias et al. 2018].

  • Grounding phase an issue since ranges of (constrained) variables may be infinite.
  • Current CASP systems (e.g., EZCSP [7] and clingo[DL/LP] [10]) limit (some of):
  • Admissible constraint domains.
  • Where constraints can appear.
  • Type / number of models computed.

Main points:

  • We re-implemented the s(ASP) interpreter: Prolog takes care of environment.
  • Increased flexibility and performance.
  • (Simple) constraint solver for disequality, CLP(), using attributed variables.

madrid institute for advanced studies in software development technologies

slide-30
SLIDE 30

9 / 17

www.software.imdea.org

s(CASP).

s(CASP): Extending s(ASP) with constraints [Arias et al. 2018].

  • Grounding phase an issue since ranges of (constrained) variables may be infinite.
  • Current CASP systems (e.g., EZCSP [7] and clingo[DL/LP] [10]) limit (some of):
  • Admissible constraint domains.
  • Where constraints can appear.
  • Type / number of models computed.

Main points:

  • We re-implemented the s(ASP) interpreter: Prolog takes care of environment.
  • Increased flexibility and performance.
  • (Simple) constraint solver for disequality, CLP(), using attributed variables.
  • Generic CLP interface and an extended compiler to plug in constraint solvers.

madrid institute for advanced studies in software development technologies

slide-31
SLIDE 31

9 / 17

www.software.imdea.org

s(CASP).

s(CASP): Extending s(ASP) with constraints [Arias et al. 2018].

  • Grounding phase an issue since ranges of (constrained) variables may be infinite.
  • Current CASP systems (e.g., EZCSP [7] and clingo[DL/LP] [10]) limit (some of):
  • Admissible constraint domains.
  • Where constraints can appear.
  • Type / number of models computed.

Main points:

  • We re-implemented the s(ASP) interpreter: Prolog takes care of environment.
  • Increased flexibility and performance.
  • (Simple) constraint solver for disequality, CLP(), using attributed variables.
  • Generic CLP interface and an extended compiler to plug in constraint solvers.
  • Design and implementation of C-forall which supports constraints in arbitrary domains.

https://gitlab.software.imdea.org/joaquin.arias/sCASP madrid institute for advanced studies in software development technologies

slide-32
SLIDE 32

10 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 answers

Figure: A C-forall evaluation that succeeds. madrid institute for advanced studies in software development technologies

slide-33
SLIDE 33

10 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 A′

1

C2 = ⊤∧¬A′

1

answers (a)

Figure: A C-forall evaluation that succeeds. madrid institute for advanced studies in software development technologies

slide-34
SLIDE 34

10 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 A′

1

C2 = ⊤∧¬A′

1

A′

2

C3 = C2 ∧¬A′

2

answers (a) (b)

Figure: A C-forall evaluation that succeeds. madrid institute for advanced studies in software development technologies

slide-35
SLIDE 35

10 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 A′

1

C2 = ⊤∧¬A′

1

A′

2

C3 = C2 ∧¬A′

2

A′

3 ≡ C3

answers (a) (b) (c)

Figure: A C-forall evaluation that succeeds. madrid institute for advanced studies in software development technologies

slide-36
SLIDE 36

11 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 answers

Figure: A C-forall evaluation that fails. madrid institute for advanced studies in software development technologies

slide-37
SLIDE 37

11 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 A′

1

C2 = ⊤∧¬A′

1

answers (a)

Figure: A C-forall evaluation that fails. madrid institute for advanced studies in software development technologies

slide-38
SLIDE 38

11 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 A′

1

C2 = ⊤∧¬A′

1

A′

2

C3 = C2 ∧¬A′

2

answers (a) (b)

Figure: A C-forall evaluation that fails. madrid institute for advanced studies in software development technologies

slide-39
SLIDE 39

11 / 17

www.software.imdea.org

s(CASP).

s(CASP): c_forall(X,Goal)

A1 A2 A3 A4 A′

1

C2 = ⊤∧¬A′

1

A′

2

C3 = C2 ∧¬A′

2

A′

3

C4 answers (a) (b) (c)

Figure: A C-forall evaluation that fails. madrid institute for advanced studies in software development technologies

slide-40
SLIDE 40

12 / 17

www.software.imdea.org

s(CASP): Application I.

Modelling and Reasoning in Event Calculus using s(CASP): [Arias et al. 2019]

  • Commonsense Reasoning requires the ability to model continuous characteristics of the world.
  • Event Calculus is a formalism that represent continuous change and capture the law of inertia:

HoldsAt(f,t2) ← Happens(e,t1) ∧ Initiates(e,f,t1) ∧ t1 < t2 ∧¬StoppedIn(t1,f,t2) madrid institute for advanced studies in software development technologies

slide-41
SLIDE 41

12 / 17

www.software.imdea.org

s(CASP): Application I.

Modelling and Reasoning in Event Calculus using s(CASP): [Arias et al. 2019]

  • Commonsense Reasoning requires the ability to model continuous characteristics of the world.
  • Event Calculus is a formalism that represent continuous change and capture the law of inertia:

HoldsAt(f,t2) ← Happens(e,t1) ∧ Initiates(e,f,t1) ∧ t1 < t2 ∧¬StoppedIn(t1,f,t2)

Advantages:

  • s(CASP) captures the notion of continues change thanks to groundness-free.

1

holdsAt(F,T) :- T1 #< T, initiates(E,F,T1), happens(E,T1), not stoppedIn(T1,F,T). madrid institute for advanced studies in software development technologies

slide-42
SLIDE 42

12 / 17

www.software.imdea.org

s(CASP): Application I.

Modelling and Reasoning in Event Calculus using s(CASP): [Arias et al. 2019]

  • Commonsense Reasoning requires the ability to model continuous characteristics of the world.
  • Event Calculus is a formalism that represent continuous change and capture the law of inertia:

HoldsAt(f,t2) ← Happens(e,t1) ∧ Initiates(e,f,t1) ∧ t1 < t2 ∧¬StoppedIn(t1,f,t2)

Advantages:

  • s(CASP) captures the notion of continues change thanks to groundness-free.

1

holdsAt(F,T) :- T1 #< T, initiates(E,F,T1), happens(E,T1), not stoppedIn(T1,F,T).

  • It can represent complex models and answer queries using constraints.

1

trajectory(filling,T1,level(overflow),T2):-

2

T1 #< T2, X2 #= X + T2-T1,

3

max_level(Max), X2 #> Max,

4

holdsAt(level(X),T1).

5

% Two possible models

6

max_level(10):- not max_level(16).

7

max_level(16):- not max_level(10). madrid institute for advanced studies in software development technologies

slide-43
SLIDE 43

13 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

madrid institute for advanced studies in software development technologies

slide-44
SLIDE 44

13 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Motivation: Spatial, ontology and logic queries for Industry Foundation Classes (IFC) building data.

  • We designed a CLP-based reasoner to detect spatial semantics relationships in/between BIM models.
  • BimSPARQL [20] also combines IFC geometry data analysis with rule-based reasoning technologies...
  • ...but CLP provides a unique formalism to combine the different semantics.

madrid institute for advanced studies in software development technologies

slide-45
SLIDE 45

13 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Motivation: Spatial, ontology and logic queries for Industry Foundation Classes (IFC) building data.

  • We designed a CLP-based reasoner to detect spatial semantics relationships in/between BIM models.
  • BimSPARQL [20] also combines IFC geometry data analysis with rule-based reasoning technologies...
  • ...but CLP provides a unique formalism to combine the different semantics.

Additionally:

  • The spatial constraint solver is n-dimensional...

1

interval(point(Xa), point(Xb), Sh) :- Sh=shape([X], [X #>= Xa,X #< Xb]).

2

rectangle(point(Xa,Ya), point(Xb,Yb), Sh) :- Sh=shape([X,Y], [X #>= Xa,X #< Xb, Y #>= Ya,Y #< Yb]).

3

box(point(Xa,Ya,Za), point(Xb,Yb,Zb), Sh) :- Sh=shape([X,Y,Z], [X #>= Xa,X #< Xb, ...). madrid institute for advanced studies in software development technologies

slide-46
SLIDE 46

13 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Motivation: Spatial, ontology and logic queries for Industry Foundation Classes (IFC) building data.

  • We designed a CLP-based reasoner to detect spatial semantics relationships in/between BIM models.
  • BimSPARQL [20] also combines IFC geometry data analysis with rule-based reasoning technologies...
  • ...but CLP provides a unique formalism to combine the different semantics.

Additionally:

  • The spatial constraint solver is n-dimensional...

1

interval(point(Xa), point(Xb), Sh) :- Sh=shape([X], [X #>= Xa,X #< Xb]).

2

rectangle(point(Xa,Ya), point(Xb,Yb), Sh) :- Sh=shape([X,Y], [X #>= Xa,X #< Xb, Y #>= Ya,Y #< Yb]).

3

box(point(Xa,Ya,Za), point(Xb,Yb,Zb), Sh) :- Sh=shape([X,Y,Z], [X #>= Xa,X #< Xb, ...).

  • ...the extra dimensions can be used to represent, e.g., movement, change or progress.

madrid institute for advanced studies in software development technologies

slide-47
SLIDE 47

13 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Motivation: Spatial, ontology and logic queries for Industry Foundation Classes (IFC) building data.

  • We designed a CLP-based reasoner to detect spatial semantics relationships in/between BIM models.
  • BimSPARQL [20] also combines IFC geometry data analysis with rule-based reasoning technologies...
  • ...but CLP provides a unique formalism to combine the different semantics.

Additionally:

  • The spatial constraint solver is n-dimensional...

1

interval(point(Xa), point(Xb), Sh) :- Sh=shape([X], [X #>= Xa,X #< Xb]).

2

rectangle(point(Xa,Ya), point(Xb,Yb), Sh) :- Sh=shape([X,Y], [X #>= Xa,X #< Xb, Y #>= Ya,Y #< Yb]).

3

box(point(Xa,Ya,Za), point(Xb,Yb,Zb), Sh) :- Sh=shape([X,Y,Z], [X #>= Xa,X #< Xb, ...).

  • ...the extra dimensions can be used to represent, e.g., movement, change or progress.
  • We can construct new objects using, e.g., complementary, union, intersection and subtraction.

madrid institute for advanced studies in software development technologies

slide-48
SLIDE 48

14 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Implementation I

1

% Compute the intersection of shapes

2

shape_intersect(Sh1s, Sh2s, ShInt) :-

3

shape_intersect_(Sh1s, Sh2s, [], ShInt).

4 5

shape_intersect_([],_,ShInt,ShInt) :- !.

6

shape_intersect_(_,[],ShInt,ShInt) :- !.

7

shape_intersect_([Sh1|Sh1s],[Sh2|Sh2s],

8

ShInt0,ShInt):-

9

intersect_shapes([Sh1], [Sh2], Sh12),

10

shape_union(ShInt0,Sh12,ShInt1),

11

shape_intersect_([Sh1], Sh2s, ShInt1,ShInt2),

12

shape_intersect_(Sh1s,[Sh2|Sh2s],ShInt2,ShInt).

13

intersect_shapes([shape(Vars,Geo1)],

14

[shape(Vars,Geo2)],ShInt):-

15

copy_term([Vars,Geo1,Geo2],[CVars,CGeo1,CGeo2]),

16

( apply_clp_constraints(CGeo1),

17

apply_clp_constraints(CGeo2) ->

18

dump_clp_constraints(CVars, Vars, GeoInt),

19

ShInt = [shape(Vars,GeoInt)]

20

; ShInt = []

21

).

22

% Compute the union of shapes

23

shape_union(Sh1s, Sh2s, ShUnions) :-

24

append(Sh1s, Sh2s, ShUnions). madrid institute for advanced studies in software development technologies

slide-49
SLIDE 49

14 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Implementation I

1

% Compute the intersection of shapes

2

shape_intersect(Sh1s, Sh2s, ShInt) :-

3

shape_intersect_(Sh1s, Sh2s, [], ShInt).

4 5

shape_intersect_([],_,ShInt,ShInt) :- !.

6

shape_intersect_(_,[],ShInt,ShInt) :- !.

7

shape_intersect_([Sh1|Sh1s],[Sh2|Sh2s],

8

ShInt0,ShInt):-

9

intersect_shapes([Sh1], [Sh2], Sh12),

10

shape_union(ShInt0,Sh12,ShInt1),

11

shape_intersect_([Sh1], Sh2s, ShInt1,ShInt2),

12

shape_intersect_(Sh1s,[Sh2|Sh2s],ShInt2,ShInt).

13

intersect_shapes([shape(Vars,Geo1)],

14

[shape(Vars,Geo2)],ShInt):-

15

copy_term([Vars,Geo1,Geo2],[CVars,CGeo1,CGeo2]),

16

( apply_clp_constraints(CGeo1),

17

apply_clp_constraints(CGeo2) ->

18

dump_clp_constraints(CVars, Vars, GeoInt),

19

ShInt = [shape(Vars,GeoInt)]

20

; ShInt = []

21

).

22

% Compute the union of shapes

23

shape_union(Sh1s, Sh2s, ShUnions) :-

24

append(Sh1s, Sh2s, ShUnions). ? shape_intersect([shape([X],[X #>= 0,X #< 5])], [shape([X],[X #>= 2,X #< 7])],Sh). Sh = [shape([X],[X #>= 2,X #< 5])] ? madrid institute for advanced studies in software development technologies

slide-50
SLIDE 50

14 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Implementation I

1

% Compute the intersection of shapes

2

shape_intersect(Sh1s, Sh2s, ShInt) :-

3

shape_intersect_(Sh1s, Sh2s, [], ShInt).

4 5

shape_intersect_([],_,ShInt,ShInt) :- !.

6

shape_intersect_(_,[],ShInt,ShInt) :- !.

7

shape_intersect_([Sh1|Sh1s],[Sh2|Sh2s],

8

ShInt0,ShInt):-

9

intersect_shapes([Sh1], [Sh2], Sh12),

10

shape_union(ShInt0,Sh12,ShInt1),

11

shape_intersect_([Sh1], Sh2s, ShInt1,ShInt2),

12

shape_intersect_(Sh1s,[Sh2|Sh2s],ShInt2,ShInt).

13

intersect_shapes([shape(Vars,Geo1)],

14

[shape(Vars,Geo2)],ShInt):-

15

copy_term([Vars,Geo1,Geo2],[CVars,CGeo1,CGeo2]),

16

( apply_clp_constraints(CGeo1),

17

apply_clp_constraints(CGeo2) ->

18

dump_clp_constraints(CVars, Vars, GeoInt),

19

ShInt = [shape(Vars,GeoInt)]

20

; ShInt = []

21

).

22

% Compute the union of shapes

23

shape_union(Sh1s, Sh2s, ShUnions) :-

24

append(Sh1s, Sh2s, ShUnions). ? shape_intersect([shape([X],[X #>= 0,X #< 5])], [shape([X],[X #>= 7,X #< 9])],Sh). Sh=[] ? madrid institute for advanced studies in software development technologies

slide-51
SLIDE 51

15 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Implementation II

1

% Compute the complementary shape

2

shape_complement([], [shape(_,[])]) :- !.

3

shape_complement([shape(_,[])], []) :- !.

4

shape_complement([shape(Vars,Geo2)], NotSh2s) :-

5

setof(shape(Vars,Dual),

6

Geo2ˆdual_clp(Geo2,Dual), NotSh2s).

7 8

% Compute the substraction of Sh2s from Sh1s

9

shape_substract(Sh1s,Sh2s, Sh1Remains) :-

10

shape_substract_(Sh1s,Sh2s, Sh1Remains).

11 12

shape_substract_([],_,[]) :- !.

13

shape_substract_(Sh1s,[],Sh1s) :- !.

14

shape_substract_([Sh1|Sh1s],Sh2s, Sh1Rems):-

15

substract_shape([Sh1],Sh2s, Rem0),

16

shape_substract_(Sh1s,Sh2s, Rem1),

17

shape_union(Rem0,Rem1, Sh1Rems).

18 19

substract_shape([Sh1],[Sh2|Sh2s], Sh1Rems) :-

20

( intersect_shape_([Sh1],[Sh2], ShInt),

21

ShInt == [] ->

22

shape_substract_([Sh1],Sh2s, Sh1Rems)

23

; shape_complement([Sh2], NotSh2),

24

shape_intersect(Sh1,NotSh2, ShRem0),

25

shape_substract_(ShRem0,Sh2s, Sh1Rems)

26

). madrid institute for advanced studies in software development technologies

slide-52
SLIDE 52

15 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Implementation II

1

% Compute the complementary shape

2

shape_complement([], [shape(_,[])]) :- !.

3

shape_complement([shape(_,[])], []) :- !.

4

shape_complement([shape(Vars,Geo2)], NotSh2s) :-

5

setof(shape(Vars,Dual),

6

Geo2ˆdual_clp(Geo2,Dual), NotSh2s).

7 8

% Compute the substraction of Sh2s from Sh1s

9

shape_substract(Sh1s,Sh2s, Sh1Remains) :-

10

shape_substract_(Sh1s,Sh2s, Sh1Remains).

11 12

shape_substract_([],_,[]) :- !.

13

shape_substract_(Sh1s,[],Sh1s) :- !.

14

shape_substract_([Sh1|Sh1s],Sh2s, Sh1Rems):-

15

substract_shape([Sh1],Sh2s, Rem0),

16

shape_substract_(Sh1s,Sh2s, Rem1),

17

shape_union(Rem0,Rem1, Sh1Rems).

18 19

substract_shape([Sh1],[Sh2|Sh2s], Sh1Rems) :-

20

( intersect_shape_([Sh1],[Sh2], ShInt),

21

ShInt == [] ->

22

shape_substract_([Sh1],Sh2s, Sh1Rems)

23

; shape_complement([Sh2], NotSh2),

24

shape_intersect(Sh1,NotSh2, ShRem0),

25

shape_substract_(ShRem0,Sh2s, Sh1Rems)

26

). ? shape_complement([shape([X],[X #>= 0,X #< 5])], Sh). Sh = [shape([X],[X #< 0]),shape([X],[X #>= 5])] ? madrid institute for advanced studies in software development technologies

slide-53
SLIDE 53

15 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Implementation II

1

% Compute the complementary shape

2

shape_complement([], [shape(_,[])]) :- !.

3

shape_complement([shape(_,[])], []) :- !.

4

shape_complement([shape(Vars,Geo2)], NotSh2s) :-

5

setof(shape(Vars,Dual),

6

Geo2ˆdual_clp(Geo2,Dual), NotSh2s).

7 8

% Compute the substraction of Sh2s from Sh1s

9

shape_substract(Sh1s,Sh2s, Sh1Remains) :-

10

shape_substract_(Sh1s,Sh2s, Sh1Remains).

11 12

shape_substract_([],_,[]) :- !.

13

shape_substract_(Sh1s,[],Sh1s) :- !.

14

shape_substract_([Sh1|Sh1s],Sh2s, Sh1Rems):-

15

substract_shape([Sh1],Sh2s, Rem0),

16

shape_substract_(Sh1s,Sh2s, Rem1),

17

shape_union(Rem0,Rem1, Sh1Rems).

18 19

substract_shape([Sh1],[Sh2|Sh2s], Sh1Rems) :-

20

( intersect_shape_([Sh1],[Sh2], ShInt),

21

ShInt == [] ->

22

shape_substract_([Sh1],Sh2s, Sh1Rems)

23

; shape_complement([Sh2], NotSh2),

24

shape_intersect(Sh1,NotSh2, ShRem0),

25

shape_substract_(ShRem0,Sh2s, Sh1Rems)

26

). ? shape_substract([shape([X],[X #>= 0,X #< 5])], [shape([X],[X #>= 2,X #< 7])],Sh). Sh = [shape([X],[X #>= 0,X #< 2])] ? madrid institute for advanced studies in software development technologies

slide-54
SLIDE 54

16 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Visualization

  • Dataset: 7000+ objects.
  • For each Sh from ARQ:
  • Green: Intersected shapes

Sh2s from STR.

  • Red: parts of Sh not

covered by Sh2s. madrid institute for advanced studies in software development technologies

slide-55
SLIDE 55

17 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Future work

  • Represent more complex shapes. We can now define convex polygons in 2D:

1

convex([point(Xa,Ya), point(Xb,Yb)], shape([X,Y], [(Xb-Xa) * (Y-Ya) - (X-Xa) * (Yb - Ya) #=< 0])).

2

convex([A,B,C|Cs],shape(V,[G|Gs])) :- convex([A,B],shape(V,[G])), convex([B,C|Cs],shape(V,Gs)). madrid institute for advanced studies in software development technologies

slide-56
SLIDE 56

17 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Future work

  • Represent more complex shapes. We can now define convex polygons in 2D:

1

convex([point(Xa,Ya), point(Xb,Yb)], shape([X,Y], [(Xb-Xa) * (Y-Ya) - (X-Xa) * (Yb - Ya) #=< 0])).

2

convex([A,B,C|Cs],shape(V,[G|Gs])) :- convex([A,B],shape(V,[G])), convex([B,C|Cs],shape(V,Gs)).

  • Provide primitives corresponding to IFC’s spatial relationships, e.g., IfcRelContainedInSpatialStructure.

madrid institute for advanced studies in software development technologies

slide-57
SLIDE 57

17 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Future work

  • Represent more complex shapes. We can now define convex polygons in 2D:

1

convex([point(Xa,Ya), point(Xb,Yb)], shape([X,Y], [(Xb-Xa) * (Y-Ya) - (X-Xa) * (Yb - Ya) #=< 0])).

2

convex([A,B,C|Cs],shape(V,[G|Gs])) :- convex([A,B],shape(V,[G])), convex([B,C|Cs],shape(V,Gs)).

  • Provide primitives corresponding to IFC’s spatial relationships, e.g., IfcRelContainedInSpatialStructure.
  • Define predicates for moving, rotating, or scaling objects, among other constructors.

madrid institute for advanced studies in software development technologies

slide-58
SLIDE 58

17 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Future work

  • Represent more complex shapes. We can now define convex polygons in 2D:

1

convex([point(Xa,Ya), point(Xb,Yb)], shape([X,Y], [(Xb-Xa) * (Y-Ya) - (X-Xa) * (Yb - Ya) #=< 0])).

2

convex([A,B,C|Cs],shape(V,[G|Gs])) :- convex([A,B],shape(V,[G])), convex([B,C|Cs],shape(V,Gs)).

  • Provide primitives corresponding to IFC’s spatial relationships, e.g., IfcRelContainedInSpatialStructure.
  • Define predicates for moving, rotating, or scaling objects, among other constructors.
  • Apply the spatial reasoner, e.g., checking constraint consistency, modelling plans or revising schedules.
  • Create an interface to query/store data in the IFC models and/or databases.

madrid institute for advanced studies in software development technologies

slide-59
SLIDE 59

17 / 17

www.software.imdea.org

BIM-Spatial Reasoning using CLP .

Future work

  • Represent more complex shapes. We can now define convex polygons in 2D:

1

convex([point(Xa,Ya), point(Xb,Yb)], shape([X,Y], [(Xb-Xa) * (Y-Ya) - (X-Xa) * (Yb - Ya) #=< 0])).

2

convex([A,B,C|Cs],shape(V,[G|Gs])) :- convex([A,B],shape(V,[G])), convex([B,C|Cs],shape(V,Gs)).

  • Provide primitives corresponding to IFC’s spatial relationships, e.g., IfcRelContainedInSpatialStructure.
  • Define predicates for moving, rotating, or scaling objects, among other constructors.
  • Apply the spatial reasoner, e.g., checking constraint consistency, modelling plans or revising schedules.
  • Create an interface to query/store data in the IFC models and/or databases.

THANKS

madrid institute for advanced studies in software development technologies

slide-60
SLIDE 60

18 / 17

www.software.imdea.org

  • Bibliography. I

[1] Arias, J. and Carro, M. (2016). Description and Evaluation of a Generic Design to Integrate CLP and Tabled

  • Execution. In 18th Int’l. ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming

(PPDP’16), pages 10–23. ACM Press. [2] Arias, J. and Carro, M. (2019a). Description, Implementation, and Evaluation of a Generic Design for Tabled CLP. Theory and Practice of Logic Programming, 19(3):412–448. [3] Arias, J. and Carro, M. (2019b). Evaluation of the Implementation of an Abstract Interpretation Algorithm using Tabled CLP. Theory and Practice of Logic Programming. Forthcoming – accepted for publication at ICLP’19. [4] Arias, J. and Carro, M. (2019c). Incremental evaluation of lattice-based aggregates in logic programming using modular TCLP. In Alferes, J. J. and Johansson, M., editors, Practical Aspects of Declarative Languages - 21st International Symposium (PADL 2019), volume 11372 of Lecture Notes in Computer Science, pages 98–114. Springer. madrid institute for advanced studies in software development technologies

slide-61
SLIDE 61

19 / 17

www.software.imdea.org

  • Bibliography. II

[5] Arias, J., Carro, M., Chen, Z., and Gupta, G. (2019). Constraint Answer Set Programming without Grounding and its Applications. In Alviano, M. and Pieris, A., editors, 3rd International Workshop on the Resurgence of Datalog in Academia and Industry (Datalog 2.0), volume 2368, pages 22–26. CEUR-WS. [6] Arias, J., Carro, M., Salazar, E., Marple, K., and Gupta, G. (2018). Constraint answer set programming without

  • grounding. Theory and Practice of Logic Programming, 18(3-4):337–354.

[7] Balduccini, M. and Lierler, Y. (2017). Constraint Answer Set Solver EZCSP and why Integration Schemas Matter. Theory and Practice of Logic Programming, 17(4):462–515. [8] Chico de Guzm´ an, P ., Carro, M., Hermenegildo, M. V., and Stuckey, P . (2012). A General Implementation Framework for Tabled CLP. In Schrijvers, T. and Thiemann, P ., editors, FLOPS’12, number 7294 in LNCS, pages 104–119. Springer Verlag. [9] Cui, B. and Warren, D. S. (2000). A system for Tabled Constraint Logic Programming. In Int’l. Conference on Computational Logic, volume 1861 of LNCS, pages 478–492. [10] Janhunen, T., Kaminski, R., Ostrowski, M., Schellhorn, S., Wanko, P ., and Schaub, T. (2017). Clingo goes Linear Constraints over Reals and Integers. TPLP, 17(5-6):872–888. madrid institute for advanced studies in software development technologies

slide-62
SLIDE 62

20 / 17

www.software.imdea.org

  • Bibliography. III

[11] Kemp, D. B. and Stuckey, P . J. (1991). Semantics of Logic Programs with Aggregates. In Int’l. Simposium on Logic Programming, pages 387–401. Citeseer. [12] Marple, K., Salazar, E., Chen, Z., and Gupta, G. (2017a). The s(ASP) Predicate Answer Set Programming

  • System. The Association for Logic Programming Newsletter.

[13] Marple, K., Salazar, E., and Gupta, G. (2017b). Computing Stable Models of Normal Logic Programs Without

  • Grounding. CoRR, abs/1709.00501.

[14] Pelov, N., Denecker, M., and Bruynooghe, M. (2007). Well-Founded and Stable Semantics of Logic Programs with

  • Aggregates. Theory and Practice of Logic Programming, (3):301–353.

[15] Santos Costa, V., Rocha, R., and Damas, L. (2012). The YAP Prolog system. Theory and Practice of Logic Programming, (1-2):5–34. [16] Schrijvers, T., Demoen, B., and Warren, D. S. (2008). TCHR: a Framework for Tabled CLP. Theory and Practice

  • f Logic Programming, (4):491–526.

madrid institute for advanced studies in software development technologies

slide-63
SLIDE 63

21 / 17

www.software.imdea.org

  • Bibliography. IV

[17] Swift, T. and Warren, D. S. (2012). XSB: Extending Prolog with Tabled Logic Programming. Theory and Practice

  • f Logic Programming, (1-2):157–187.

[18] Toman, D. (1997). Memoing Evaluation for Constraint Extensions of Datalog. Constraints, 2(3/4):337–359. [19] Vandenbroucke, A., Pirog, M., Desouter, B., and Schrijvers, T. (2016). Tabling with Sound Answer Subsumption. Theory and Practice of Logic Programming, 32nd Int’l. Conference on Logic Programming, (5-6):933–949. [20] Zhang, C., Beetz, J., and de Vries, B. (2018). Bimsparql: Domain-specific functional SPARQL extensions for querying RDF building data. Semantic Web, 9(6):829–855. [21] Zhou, N. (2012). The Language Features and Architecture of B-Prolog. Theory and Practice of Logic Programming, (1-2):189–218. madrid institute for advanced studies in software development technologies