Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHREK Marcos Aurélio MSN:

Similar presentations


Presentation on theme: "CHREK Marcos Aurélio MSN:"— Presentation transcript:

1 CHREK Marcos Aurélio E-mail: maurelio1234@gmail.commaurelio1234@gmail.com MSN: maurelio1234@hotmail.commaurelio1234@hotmail.com

2 Baixando o CHREK Abrir a pasta \\profile\scratch_maas$\ na rede do CIN Copiar a pasta chrek para C:\temp\ Executar o context

3 Configurando o Context Configurar atalhos em: Options > Environmento Options > Execute Keys Atalhos configurados no editor –F9 – GUI para acompanhamento passo da execução –F10 – Explicação do raciocínio no Console do Context e no arquivo console.txt

4 Configurando o Context

5

6

7 Acompanhando a execução de um programa CHR Restrições Definidas pelo usuário Restrições Built-in Regras do programa Execução

8 Exemplos – Hello World main() true | writeLn("hello world"). Definição de GOAL

9 Exemplos - Max :- explain max(X,Y,Z) le(X,Y) | Z = Y. max(X,Y,Z) le(Y,X) | Z = X. max(X,Y,Z) ==> true | le(X,Z), le(Y,Z). main() true | max(17,139,M), writeLn(M). Ativa Explicação do Raciocínio!

10 Exemplos - Fibonacci primes(1) true | true. primes(N) gt(N,1) | M = N~1, prime(N), primes(M). prime(I) \ prime(J) ==> modEqual(J, I, 0) | true. main() true | primes(100).

11 Restrições built-in A = B true false ground(X) unbound(X) ne(X,Y)  X != Y le(X,Y)  X>=Y ge(X,Y)  X<=Y lt(X,Y)  X<Y gt(X,Y)  X>Y writeLn(X) write(X) readInt(X) instanceOf(X,Str)

12 Diretivas de compilação :- “ ” –explain –standalone –bicpackage “package” –goal “goal constraint name” –stats running_time

13 Criando predicados built-in Criar uma classe que esteja dentro de um pacote Extender chord.constraint.builtin. BuiltInConstraint Implementar o método: public boolean execute(boolean guard) throws VariableNotBoundException Cada built-in pode ser executado várias vezes durante o programa Se guard = true a execução não deve ter efeitos colaterais

14 Exemplo - Built-in package builtin; import chord.variable.*; import chord.constraint.builtin.*; public class MyBuiltIn extends BuiltInConstraint { public boolean execute(boolean guard) throws VariableNotBoundException { Object obj1 = getArgument(0); Variable val1 = null; if (obj1 instanceof Variable) { val1 = ((Variable) obj1); } boolean ret = true; if (!guard) { ret = VariableTable.getInstance(). bind(val1, new Integer((int)(Math.random() * 100))); } return ret; }

15 :- bicpackage "builtin" main() true | myBuiltIn(X), writeLn(X). Para compilar: Programa usando built-in Mais exemplos: javac -classpath runtime.jar builtin/MyBuiltIn.java Exemplo - Built-in http://chord.cvs.sourceforge.net/chord/CHORD/src/chord/constraint/builtin/

16 Case Study: Triangram

17 Case Study - Triangram Triangram –Basic parts are only of a type: triangles –Uses three types of triangles

18 Case Study - Triangram Triangram –The objective is to form geometric figures from the basic types of triangles –It's only allowed to form a restricted number of types of figures: the straight hexagons, pentagons and the quadrilaterals

19 Case Study - Triangram UML/OCL –Representation of the world: convex polygons

20 Case Study - Triangram UML/OCL –Representation of the world: triangle

21 Case Study - Triangram Implementation –Goal Scenary being tested Class hierarchy Classes signatures –Rules Invariants Methods –Query  propagation rules with the F-Atom of the method in the body of the rule and pre-conditions in the head –Transactional  simpagation rules with pre-conditions in the head, removals in simplificateHead and pos-conditions in the body

22 Case Study - Triangram scaleneTriangle::triangle, isoscelesTriangle::triangle, equilateralTriangle::isoscelesTriangle,... CHORD Implementation - Goal main() true |... Class Hierarchy tri1 : equilateralTriangle [side ->> s11 [ adjacent ->> s12, adjacent ->> s13, length -> 3 ],... ],... Scenary being tested triangle[side *=>> segmentLine, triangleSide *=>> triangleSide, hypotenuse *=> segmentLine],... Class signatures

23 Case Study - Triangram... X:segmentLine[adjacent->>S] ==> true | S:segmentLine[adjacent->>X]. X:triangle, X[side->>S1], X[side->>S2], S1[length->L1], S2[length->L2] ==> ne(S1,S2), L1 = L2 | X:regularPolygon.... Invariants

24 Case Study - Triangram Query Methods... Pol1 : rectangle [ side ->> SidePol1[ length -> L, adjacent ->> A1[ length -> LA1 ] ], parts ->> P1, parts ->> P2 ], Pol2 : isoscelesTriangle [ triangleSide ->> TS1[ side -> SidePol2 [ length -> L, adjacent ->> A2 [length -> LA1 ] ], position -> base ] ] ==> ne(P1,Pol2), ne(P2,Pol2) | Pol1[isCompatible(Pol2, SidePol1, SidePol2)->void]....

25 Case Study - Triangram Transactional Methods... Pol11:triangle[isCompatible(Pol2, SidePol1, SidePol2)->void], Pol2 : triangle,...\ A11[adjacent ->> SidePol1], A12[adjacent ->> SidePol1], A21[adjacent ->> SidePol2], A22[adjacent ->> SidePol2] ==> A11 != A12, A21 != A22 | A11[adjacent ->> A22], A12[adjacent ->> A21], A21[adjacent ->> A12], A22[adjacent ->> A11], Pol3 : rectangle[side ->> {A11,A12,A21,A22}, parts ->> {Pol1,Pol2}],...


Download ppt "CHREK Marcos Aurélio MSN:"

Similar presentations


Ads by Google