Both sides previous revision
Poprzednia wersja
|
|
pl:miw:miw08_xtt_serialization [2008/06/14 10:42] gjn |
pl:miw:miw08_xtt_serialization [2019/06/27 15:50] (aktualna) |
| ====== Opis ====== |
| __**Projekt zakończony**__ |
| |
| Karol, Gorlach, <Karol.gorlach@gmail.com> |
| |
| Try to propose an effective encoding of XTT with UML and Java. |
| |
| ====== Spotkania ====== |
| |
| ===== 08.02.26 ===== |
| |
| ===== 080318 ===== |
| |
| ===== 080408 ===== |
| * xtt w java... |
| |
| |
| ===== 080422 ===== |
| * opis alg dla javy i sql |
| |
| |
| ===== 080527 ===== |
| * sprawozdanie |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| ====== Projekt ====== |
| **realizacja tablic XTT w javie** |
| |
| Model tabic XTT zrealizowalem w jave za pomocą klas Reguł, w której sładowymi są: |
| |
| -atrybuty XTT tablicy-precondition atributes |
| |
| -assert atributes |
| |
| -decision atributes |
| |
| Poszczegule reguły czyli opiekty klasy Regula sa umieszczone w liście typu Regula |
| |
| Przykłady implementacji: |
| |
| * napisany przez mnie kod dla przykładu termostatu:{{:pl:miw:miw08_xtt_serialization:Termostat.java.txt|Termostat.java}} |
| |
| * dla przykładu cen biletów dla wyciagu narciarskiego:{{:pl:miw:miw08_xtt_serialization:WyciagNarciarski.java.txt|WyciagNarciarski.java}} |
| |
| |
| * dla przykładu cen biletów na pociag na określonej trasie:{{:pl:miw:miw08_xtt_serialization: |
| rozkladpociagow.java.txt|RozkladPociagow.java}} |
| |
| |
| |
| |
| ====== Sprawozdanie ====== |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| ==== Sposób reprezentacji ==== |
| |
| Ogólna Forma reprezentacji reguł w XTT: |
| |
| {{:pl:miw:miw08_xtt_serialization:xtt1.jpg|:pl:miw:miw08_xtt_serialization:xtt1.jpg}} |
| |
| Kolumny są określone następująco: |
| |
| I-identyfikator reguły(numer elementu w tablicy) |
| |
| Ctx-(ang. Contex) opis reguły |
| |
| A1 ..An - warunki wstępne |
| |
| B1 ..Bn - warunki modyfikujące |
| |
| C1 ..Cn - warunek określany |
| |
| H1 ..Hn – warunki decyzyjne |
| |
| N- atrybut kontrolny określający nastepującą regułę |
| |
| E- atrybut kontrolny określający opcjonalną, inną regułę |
| |
| |
| Aby określić rolę musimy podąć następujące parametry wejściowe: |
| |
| Roles={Info,Preconditions,Assert,Retract,Decision,Ctrl} |
| |
| Przypadek ogólny reguły-klasy w javie: |
| |
| <code java> |
| class Regula{ |
| Object precondition[]; |
| Object precondition1[]; |
| Object decision; |
| Object asert; |
| int CtrlN; |
| int CtrlL; |
| //konstruktory |
| public Regula(int CtrlN,int CtrlL,Object precondition,Object precondition1,Object asert,Object decision) |
| { |
| if(precondition==null) |
| { |
| this.precondition=null; |
| } |
| else |
| { |
| this.precondition=new Object[1]; |
| this.precondition[0]=precondition; |
| } |
| if(precondition1==null) |
| { |
| this.precondition1=null; |
| } |
| else |
| { |
| this.precondition1=new Object[1]; |
| this.precondition1[0]=precondition1; |
| } |
| this.decision=decision; |
| this.asert=asert; |
| this.CtrlN=CtrlN; |
| this.CtrlL=CtrlL; |
| } |
| public Regula(int CtrlN,int CtrlL,Object precondition[],Object precondition1[],Object asert,Object decision) |
| { |
| if(precondition==null) |
| { |
| this.precondition=null; |
| } |
| else |
| { |
| this.precondition=new Object[precondition.length]; |
| System.arraycopy(precondition,0,this.precondition,0,precondition.length); |
| } |
| if(precondition1==null) |
| { |
| this.precondition1=null; |
| } |
| else |
| { |
| this.precondition1=new Object[precondition1.length]; |
| System.arraycopy(precondition1,0,this.precondition1,0,precondition1.length); |
| } |
| this.decision=decision; |
| this.asert=asert; |
| this.CtrlN=CtrlN; |
| this.CtrlL=CtrlL; |
| } |
| public Regula(int CtrlN,int CtrlL,Object precondition[],Object precondition1,Object asert,Object decision) |
| { |
| if(precondition==null) |
| { |
| this.precondition=null; |
| } |
| else |
| { |
| this.precondition=new Object[precondition.length]; |
| System.arraycopy(precondition,0,this.precondition,0,precondition.length); |
| } |
| this.precondition1=new Object[1]; |
| this.precondition1[0]=precondition1; |
| this.decision=decision; |
| this.asert=asert; |
| this.CtrlN=CtrlN; |
| this.CtrlL=CtrlL; |
| } |
| public Regula(int CtrlN,int CtrlL,Object precondition,Object precondition1[],Object asert,Object decision) |
| { |
| if(precondition1==null) |
| { |
| this.precondition1=null; |
| } |
| else |
| { |
| this.precondition1=new Object[precondition1.length]; |
| System.arraycopy(precondition1,0,this.precondition1,0,precondition1.length); |
| } |
| if(precondition==null) |
| { |
| this.precondition=null; |
| } |
| else |
| { |
| this.precondition=new Object[1]; |
| this.precondition[0]=precondition; |
| } |
| this.decision=decision; |
| this.asert=asert; |
| this.CtrlN=CtrlN; |
| this.CtrlL=CtrlL; |
| } |
| // metody |
| public Object Sprawdz(Object object){ |
| |
| for(int i=0;i<this.precondition.length;i++){ |
| if(object==this.precondition[i]){ |
| |
| if(this.asert!=null) |
| { |
| return this.asert; |
| } |
| else |
| { |
| return this.decision; |
| } |
| } |
| |
| } |
| return null; |
| } |
| public Object Sprawdz(Object object,Object object1){ |
| for(int i=0;i<this.precondition.length;i++){ |
| if(object==this.precondition[i]){ |
| for(int j=0;i<this.precondition1.length;j++){ |
| if(object1==this.precondition1[j]){ |
| if(this.asert!=null) |
| { |
| return this.asert; |
| } |
| else |
| { |
| return this.decision; |
| } |
| } |
| } |
| } |
| } |
| return null; |
| } |
| public String toString(){ |
| return "numer :"+this.CtrlN; |
| } |
| } |
| </code> |
| |
| ====Sposób tworzenia tablic xtt w Javie:==== |
| |
| Klasy reprezentują reguły, Każda reguła składa się z |
| |
| Atrybutów: |
| |
| - warunki wstępne np.: pojedyncze elementy lub zbiory elementów |
| -warunków modyfikujących np.: za pomocą których możemy zmieniać warunki określające reguł |
| -warunki określające |
| -warunki decyzyjne |
| |
| Poszczególne reguły są umieszczone w tablicy, a więc każda regułę identyfikuje jednoznacznie położenie w tablicy. |
| Istnieje możliwość odwoływania się z jednej reguły do drugiej, w ten sposób że każda reguła posiada pole określające inną regułę reprezentującą ten sam typ atrybutów , i warunków określających (np. poszukiwana reguła nie posiada szukanych przez nas atrybutów) |
| Każda reguła zawiera również informacje o regule wyższego poziomu, lub niższego (pole klasy). Co wiąże się z poszukiwaniem warunków decyzyjnych. |
| Do odwoływania się pomiędzy regułami służą metody (wykorzystujące informacje znajdującą się w polach obiektów-reguł ) |
| |
| |
| |
| ====Przykład Termostatu==== |
| Termostat jest wzorcowym przykładem do prezentacji działania systemów regulowych, mozna go znaleźć na wiki:[[hekate: |
| hekate_concepts#xtt+]] |
| |
| Diagram ARD+ termostatu: |
| {{:pl:miw:miw08_xtt_serialization:xtt-structure-therm.png|:pl:miw:miw08_xtt_serialization:xtt-structure-therm.png}} |
| |
| Dla przykładu termostatu tablica XTT wygląda tak: |
| |
| {{:pl:miw:miw08_xtt_serialization:tabela_termostat.png|:pl:miw:miw08_xtt_serialization:tabela_termostat.png}} |
| |
| napisany przezemnie kod w javie dla tablicy XTT za pomocą reguł- przykład termostatu |
| |
| <code java> |
| public class Termostat{ |
| public static void main(String args[]){ |
| // incjalizacja listy |
| List<Regula> list= new ArrayList<Regula>(); |
| // deklaracja atrybutow |
| String dniprac[]={"monday","tuesday","wednesday","thurstday","friday"}; |
| String dniwolne[]={"saturday","sunday"}; |
| String winter[]={"december","january","february"}; |
| String spring[]={"march","april","may"}; |
| String summer[]={"june","july","august"}; |
| String fall[]={"september","october","november"}; |
| Integer before17[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; |
| Integer ANY[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; |
| Integer after9[]={10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; |
| Integer in9and17[]={9,17}; |
| // deklaracja regul |
| list.add(new Regula(2,1,dniprac,null,"workday",null)); //regula1 |
| list.add(new Regula(2,0,dniwolne,null,"weekend",null)); //regula2 |
| list.add(new Regula(6,3,"workday",before17,"dbh",null));//regula3 |
| list.add(new Regula(6,4,"workday",ANY,"ndbh",null)); //regula4 |
| list.add(new Regula(6,5,"workday",after9,"ndbh",null)); //regula5 |
| list.add(new Regula(6,2,"weekend",in9and17,"ndbh",null));//regula6 |
| list.add(new Regula(12,7,winter,null,"winter",null)); //regula7 |
| list.add(new Regula(14,8,spring,null,"spring",null)); //regula8 |
| list.add(new Regula(16,9,summer,null,"summer",null)); //regula9 |
| list.add(new Regula(10,6,fall,null,"fall",null)); //regula10 |
| list.add(new Regula(0,11,"ndbh","summer",null,27)); //regula11 |
| list.add(new Regula(0,12,"dbh","summer",null,24)); //regula12 |
| list.add(new Regula(0,13,"ndbh","spring",null,15)); //regula13 |
| list.add(new Regula(0,14,"dbh","spring",null,20)); //regula14 |
| list.add(new Regula(0,15,"ndbh","winter",null,14)); //regula15 |
| list.add(new Regula(0,16,"dbh","winter",null,18)); //regula16 |
| list.add(new Regula(0,17,"ndbh","fall",null,16)); //regula17 |
| list.add(new Regula(0,0,"dbh","fall",null,20)); //regula18 |
| // przykladowe uzycie metody |
| System.out.println(list.get(0).Sprawdz("tuesday")); |
| System.out.println(list.get(17).Sprawdz("dbh","fall")); |
| } |
| </code> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| ==== Inne przykłady zastosowania XTT ==== |
| |
| ====Cennik biletów na wyciąg narciarski==== |
| |
| Buduję tablicę XTT dla problemu dotyczacego spisu cen biletów do wyciagu narciarskiego w różnych porach dnia, róznych dniach i porach roku. |
| |
| Oto diagram ARD+ który prezentuje wzajemne powiazania miedzy elementami dla szukanego problemu: |
| |
| {{:pl:miw:miw08_xtt_serialization:diagram1.png|:pl:miw:miw08_xtt_serialization:diagram1.png}} |
| |
| Na tej podtawie łatwo zbudowac tablicę XTT, oraz reguły: |
| |
| {{:pl:miw:miw08_xtt_serialization:xtt_wyciag_narciarski.png|:pl:miw:miw08_xtt_serialization:xtt_wyciag_narciarski.png}} |
| |
| Utworzenie takiej tablicy w java prezentuje ponizszy kod: |
| |
| <code java> |
| public class WyciagNarciarski{ |
| |
| public static void main(String args[]){ |
| // incjalizacja listy |
| List<Regula> list= new ArrayList<Regula>(); |
| // deklaracja atrybutow |
| String dniprac[]={"monday","tuesday","wednesday","thurstday","friday"}; |
| String dniwolne[]={"saturday","sunday"}; |
| String out[]={"june","july","august","september"}; |
| String in_the_middle[]={"december","january","february"}; |
| String before[]={"october","november"}; |
| String after[]={"march","april","may"}; |
| Integer before12[]={8,9,10,11,12}; |
| Integer between_12_16[]={12,13,14,15}; |
| Integer after16[]={16,17,18,19,20}; |
| Integer ANY[]={8,9,10,11,12,13,14,15,16,17,18,19,20}; |
| Integer All[]={8,9,10,11,12,13,14,15,16,17,18,19,20}; |
| String grup_All_season[]={"out","before","in_the_middle","after"}; |
| String para_near_season[]={"before","after"}; |
| String morning[]={"morning_weekend","morning_workd"}; |
| String midday[]={"midday_weekend","midday_workd"}; |
| String evening[]={"evening_workd","evening_weekend"}; |
| String allday[]={"All_weekend","All_workd"}; |
| // deklaracja regul |
| list.add(new Regula(2,1,dniprac,null,"workday",null)); //regula1 |
| list.add(new Regula(7,0,dniwolne,null,"weekend",null)); //regula2 |
| list.add(new Regula(12,3,"workday" ,before12,"morning_workd",null)); //regula3 |
| list.add(new Regula(12,4,"workday",between_12_16,"midday_workd",null)); //regula4 |
| list.add(new Regula(12,5,"workday",after16,"evening_workd",null)); //regula5 |
| list.add(new Regula(12,6,"workday",All,"All_workd",null)); //regula6 |
| list.add(new Regula(12,7,"workday",ANY,"single",null)); //regula7 |
| list.add(new Regula(12,8,"weekend",before12,"morning_weekend",null)); //regula8 |
| list.add(new Regula(12,9,"weekend",between_12_16,"midday_weekend",null));//regula9 |
| list.add(new Regula(12,10,"weekend",after16,"evening_weekend",null)); //regula10 |
| list.add(new Regula(12,11,"weekend",All,"All_weekend",null)); //regula11 |
| list.add(new Regula(12,2,"weekend",ANY,"single",null)); //regula12 |
| list.add(new Regula(16,13,out,null,"out",null)); //regula13 |
| list.add(new Regula(16,14,before,null,"before",null)); //regula14 |
| list.add(new Regula(16,15,in_the_middle,null,"in the middle",null)); //regula15 |
| list.add(new Regula(16,12,after,null,"after",null)); //regula16 |
| list.add(new Regula(0,17,grup_All_season,"single",null,5)); //regula17 |
| list.add(new Regula(0,18,para_near_season,morning,null,20)); //regula18 |
| list.add(new Regula(0,19,para_near_season,midday,null,25)); //regula19 |
| list.add(new Regula(0,20,para_near_season,evening,null,15)); //regula20 |
| list.add(new Regula(0,21,para_near_season,allday,null,35)); //regula21 |
| list.add(new Regula(0,22,"in_the_middle","morning_workd",null,28)); //regula22 |
| list.add(new Regula(0,23,"in_the_middle","midday_workd",null,35)); //regula23 |
| list.add(new Regula(0,24,"in_the_middle","evening_workd",null,28)); //regula24 |
| list.add(new Regula(0,25,"in_the_middle","All_workd",null,60)); //regula25 |
| list.add(new Regula(0,26,"in_the_middle","morning_weekend",null,35)); //regula26 |
| list.add(new Regula(0,27,"in_the_middle","midday_weekend",null,40)); //regula22 |
| list.add(new Regula(0,28,"in_the_middle","evening_weekend",null,30)); //regula27 |
| list.add(new Regula(0,0,"in_the_middle","All_weekend",null,80)); //regula28 |
| |
| // przykladowe uzycie metody |
| System.out.println(list.get(0).Sprawdz("tuesday")); |
| System.out.println(list.get(21).Sprawdz("in_the_middle","morning_workd")); |
| } |
| } |
| </code> |
| |
| ====Ceny biletów na pociąg==== |
| Buduję tablicę XTT dla problemu dotyczacego spisu cen biletów na pociagi na trasie Kraków-Przemyś,biorąc pod uwagę klasę, rodzaj pociagu i ilośc przejechanych kilometrów |
| Oto diagram ARD+ który prezentuje wzajemne powiazania miedzy elementami dla szukanego problemu: |
| |
| {{:pl:miw:miw08_xtt_serialization:diagram1d.png|:pl:miw:miw08_xtt_serialization:diagram1d.png}} |
| |
| Na tej podtawie łatwo zbudowac tablicę XTT, oraz reguły: |
| |
| {{:pl:miw:miw08_xtt_serialization:ceny_biletow_pociagow.png|:pl:miw:miw08_xtt_serialization:ceny_biletow_pociagow.png}} |
| |
| Utworzenie takiej tablicy w java prezentuje ponizszy kod: |
| |
| <code java> |
| public class RozkladPociagow{ |
| |
| public static void main(String args[]){ |
| // incjalizacja listy |
| List<Regula> list= new ArrayList<Regula>(); |
| // deklaracja regul |
| list.add(new Regula(2,1,"rzeszowianin",null,"osobowy",null)); //regula1 |
| list.add(new Regula(3,0,"przemyslanin",null,"pospieszny",null));//regula2 |
| list.add(new Regula(5,3,"osobowy",2,"osob2",null)); //regula3 |
| list.add(new Regula(5,4,"pospieszny",1,"posp1",null)); //regula4 |
| list.add(new Regula(5,2,"pospieszny",2,"posp2",null)); //regula5 |
| list.add(new Regula(10,6,"Krakow-Bochnia",null,50,null)); //regula6 |
| list.add(new Regula(13,7,"Krakow-Tarnow",null,100,null)); //regula7 |
| list.add(new Regula(16,8,"Krakow-Debica",null,150,null)); //regula8 |
| list.add(new Regula(19,9,"Krakow-Rzeszow",null,200,null)); //regula9 |
| list.add(new Regula(22,5,"Krakow-Przemysl",null,300,null)); //regula10 |
| list.add(new Regula(0,11,"osob2",50,null,5)); //regula11 |
| list.add(new Regula(0,12,"posp1",50,null,10)); //regula12 |
| list.add(new Regula(0,13,"posp2",50,null,7)); //regula13 |
| list.add(new Regula(0,14,"osob2",100,null,8)); //regula14 |
| list.add(new Regula(0,15,"posp1",100,null,16)); //regula15 |
| list.add(new Regula(0,16,"posp2",100,null,9)); //regula16 |
| list.add(new Regula(0,17,"osob2",150,null,11)); //regula17 |
| list.add(new Regula(0,18,"posp1",150,null,25)); //regula18 |
| list.add(new Regula(0,19,"posp2",150,null,20)); //regula19 |
| list.add(new Regula(0,20,"osob2",200,null,15)); //regula20 |
| list.add(new Regula(0,21,"posp1",200,null,32)); //regula21 |
| list.add(new Regula(0,22,"posp2",200,null,25)); //regula22 |
| list.add(new Regula(0,23,"osob2",300,null,20)); //regula23 |
| list.add(new Regula(0,24,"posp1",300,null,40)); //regula24 |
| list.add(new Regula(0,0,"posp2",300,null,30)); //regula25 |
| // przykladowe uzycie metody |
| System.out.println(list.get(0).Sprawdz("rzeszowianin")); |
| System.out.println(list.get(10).Sprawdz("osob2",50)); |
| } |
| } |
| </code> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| ====Inne Podejście==== |
| |
| Reprezentacja tablic xtt w języku SQL |
| |
| Należy na wstępie zbudować tablice reprezentujące wzajemne powiązania pomiędzy regułami w xtt: |
| |
| Zapis ten można interpretować w ten sposób że: |
| -Tablice SQL reprezentują reguły w xtt |
| -indeks tablicy (klucz) – są to warunki określające w tablicy xtt |
| -klucze obce są to –warunki wstępne w tablicy xtt |
| |
| Dopiero po zbudowaniu wzajemnych zależności pomiędzy tablicami: wprowadzamy dane do tablic (reprezentacje reguł w xtt) |
| |
| Reprezentacja Reguł w języku SQL |
| |
| Należy na wstępie zbudować tablice reprezentujące wzajemne powiązania pomiędzy regułami : |
| |
| Zapis ten można interpretować w ten sposób że: |
| -Tablice SQL reprezentują reguły w xtt |
| -indeks tablicy (klucz) – są to warunki określające w tablicy xtt |
| -klucze obce są to –warunki wstępne w tablicy xtt |
| |
| Dopiero po zbudowaniu wzajemnych zależności pomiędzy tablicami: wprowadzamy dane do tablic (reprezentacje reguł w xtt) |
| |
| **alternatywne rozwiązanie:** |
| |
| realizacja XTT za pomocą SQL. |
| |
| >Ze wzgledu na to że reprezentacja danych jest w tablicach, oraz wystepuja powiązania w łatwy sposób mozna zbudowac tablicę i powiązania miedzy nimi.Wzorując się na budowie schematów ARD+ zbudowałem powiazania miedzy tablicami. |
| |
| |
| **Tablice SQL dla pozostałych przykładów(Cennik biletów pociagow oraz Cennik biletów na wyciag narciarski)** |
| |
| Ponizej ilustruje szablon reliacji tablic w sql zrealizowany w DBdesigner dla przykładow: |
| * [[:pl:miw:miw08_xtt_serialization#Przykład Termostatu]] |
| |
| {{:pl:miw:miw08_xtt_serialization:termostat.png|termostat}} |
| |
| |
| * [[:pl:miw:miw08_xtt_serialization#Cennik biletów na wyciąg narciarski]] |
| |
| {{:pl:miw:miw08_xtt_serialization:wyciag.png|:pl:miw:miw08_xtt_serialization:wyciag.png}} |
| |
| * [[:pl:miw:miw08_xtt_serialization#Ceny biletów na pociąg]] |
| |
| {{:pl:miw:miw08_xtt_serialization:pociag.png|:pl:miw:miw08_xtt_serialization:pociag.png}} |
| |
| ====== Materiały ====== |
| [[hekate:hekate_concepts#xtt+]] |
| |
| ====== Literatura ====== |
| |
| * Antoni Ligęza,"Logical Foundations for Rule-Based System",Uczelniane Wydawnictwa Naukowo-dydaktyczne AGH Kraków 2005. |
| |