NB. load 'user\projects\Tour_moodul.txt' load '~addons\tables\tara\tara.ijs' load 'system\main\files.ijs' ts=: 6!:2, 7!:2@] 9!:3(5) NB. set system for linear display of verbs bdiag=: [: >/~ [: i. ] NB. 13 : '>/~ i.y' adiag=: [: |: bdiag NB. 13 : '|: bdiag y' rankings=: ,"1 0~@i. , /:"1@=@i.@>: ext =: [: ,/ _1&,. {"2 1 rankings@#@~.@{. fin3 =: ([: ; >./"1 <@ext/. ])@$:@<: ` (i.@(1&,)) @. (1&>:) NB. xcoord =: I. i. NB. not working for some reason xcoord =: 13 : 'I. i. y' NB. I. i.6 NB. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 NB. xcoord=: [: #~ [: i. ] NB. 13 : '#~ (i.y)' NB. #~ (i.6) NB. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 NB. vana NB. ycoord=: [: }. ([: I. 0: <:/ ([: , bdiag + _1: + bdiag) * [: , (] , ]) $ [: i. ]) { ([: , bdiag + _1: + bdiag) * [: , (] , ]) $ [: i. ] NB. 13 : '}. (I. 0<:/ ilist) { ilist=. (, (bdiag y) +_1+bdiag y) * , (y, y)$i. y' NB. ycoord 9 NB. 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 6 0 1 2 3 4 5 6 7 NB. ioftrue=: # i.@# NB. ,ioftrue bdiag 5 NB. 0 0 0 0 0 0 0 0 0 1 0 0 0 1 2 0 0 1 2 3 NB. ,I. bdiag 5 NB. 0 0 0 0 0 0 0 0 0 1 0 0 0 1 2 0 0 1 2 3 NB. tc=: 13 : '(y, y) $ y# y * i.y' NB. not needed any more NB. tc 5 NB. 0 0 0 0 0 NB. 5 5 5 5 5 NB. 10 10 10 10 10 NB. 15 15 15 15 15 NB. 20 20 20 20 20 NB. ycoord=: 13 : 'bd - (bd=. I. ,bdiag y) { ,tc y' ycoord =: 13 : '(i. +/i. y) - (<: I. i. y) { + /\ i. <: y' NB. ycoord =: 13 : '(i. +/b) - (<: I. b) { + /\ _1}.(b=.i. y)' NB. sama kiire ja mahukas NB. ycoord =: 13 : '(i. (0.5 * y * y -1) ) - (<: I. b) { + /\ _1}.(b=.i. y)' NB. sama kiire ja mahukas NB. ycoord 5 NB. 0 0 1 0 1 2 0 1 2 3 NB. teine aeglasem arvutusviis NB. (I. ,bdiag y) { 0 1 |. 0,"1 I. bdiag 5 NB. vana, 2x aeglasem ja mahukam NB. base_table=: monad define NB. (y , y) $ (i.#ilist) (ilist=. I. 0<:/ (, bd + _1 + bd) * ,(y , y)$i. y) } ,bd=. bdiag y NB. ) base_table =: 13 : '(y ,y)$(1+i.(0.5 * y * y-1) ) (I. bd) } bd=. ,bdiag y' NB. base_table 5 NB. 0 0 0 0 0 NB. 1 0 0 0 0 NB. 2 3 0 0 0 NB. 4 5 6 0 0 NB. 7 8 9 10 0 base2table=: base_table - [: |: base_table equi_table=: 1: - [: =@i. ] all_seqs =: (([: i. [: ! ]) A. [: i. ]) C."1 (as=. ([: i. [: ! ]) A. [: i. ]) C. bdiag all_seqs2 =: as C."1 (as=. ([: i. [: ! ]) A. [: i. ]) C. bdiag NB. 2x kiirem, 25% mälumahukam all_seqs3 =: 13 : '(bdiag y) sort_table ((i.!y) A. (i.y))' NB. leiab väljavõtuindeksid NB. +/"1 ( (i.#all_seqs_4) {all_seqs_4 ) { ,tabel NB. all_seqs4 =: 13 : 'I. ,"_1 (bdiag y) sort_table ((i.!y) A. (i.y))' CM=: #. e.~ [: i. [ , [ gm=: ([: >: [: >./ ,) CM ] NB. 13 : '(>:>./,y) CM y' votable_from_preftable=: [: +/ ] f"1 [: i. # tourtable_from_votable=: |: < ] all_smallest_from =: ] e. <./ NB. all_smallest_from =: (e. <./)~ NB. teine kuju all_not_smallest_from =: -. ] e. <./ indexes_all_smallest_from =: 13 : 'I. (e. <./)~ y' NB. indexes_all_smallest_from =: ] i. <./ NB. vana, vale ? all_largest_from =: ] e. >./ indexes_all_largest_from=: ] i. >./ exclude =: 13 : '(0) ((I. y) { I. x) } x' NB. (i.5) exclude 1 2 NB. 0 0 0 3 4 NB.------------------------------------ vale getsample =: +/{.\: NB.------------------------------------ vale subsample_from =:dyad define (getsample x) { (getsample x) {"1 (i.#y){y ) NB.------------------------------------ NB. vana, veidi aeglasem ja mälunõudlikum minfaults=. [: <./ [: <. [: +/"1 [: +/"1 ((([: ! #) , #) $ [: bdiag #) * (([: i. [: ! #) A. [: i. #) C."1 (([: i. [: ! #) A. [: i. #) C. ] minfaults =: [: <./ [: <. [: +/"1 [: +/"1 ((([: ! #) , #) $ ]) * (([: i. [: ! #) A. [: i. #) C."1 (([: i. [: ! #) A. [: i. #) C. [: bdiag # NB. turniiritabeli paremusjärjestus võitude alusel wins_seq =: [: \: [: +/"1 ] NB. sordi tabel x järjestuse y alusel ridu-veerge pidi sort_table =: 13 : 'y {"1 y { x' NB. vana NB. sort_table =: ([ /: [: /: ]) /:"1 [: /:"1 ] NB. konformsusskaala - listi elementide loendamine ja järjestamine elementide kasvavasse järjestusse NB. sobib kaarte kujul graafi rea- ja veerusummade leidmiseks m46 =: ({.;#)/.~ konformity =: /:~ >m46 NB. reasum =: konformity 0{"1 arcs NB. veerusum =: konformity 1{"1 arcs NB. ================================ heuristic tournament method H NB. ------------------------------------- NB. TURNIIRIMEETOD. NB. 1. VÄLJAVÕTU VÕITUDE ALUSEL NB. 2. VÄLJAVÕTU KAOTUSTE ALUSEL NB.------------------------------------ touranking =: monad define table_objects =: (#y)#1 remove_list =: 0$0 remove_value =: 0$0 rowsums =: +/"1 y colsums =: +/ y lisating =: 0 whilst. (+/table_objects)>1 do. smallest2 =: */~ smallest=: table_objects whilst. newsample = 1 do. newsmallest =: -. all_smallest_from (I. smallest) { +/"1 y * smallest2 if. (newsample =: 0 < +/newsmallest) do. smallest2 =: */~ smallest=: (0) ((I. newsmallest) { I. smallest) } smallest end. newsmallest =: -. all_largest_from (I. smallest) { +/ y * smallest2 if. (0 < +/newsmallest) do. smallest2 =: */~ smallest =: (0) ((I. newsmallest) { I. smallest) } smallest newsample =: 1 end. end. if. 1 < +/smallest do. lisating =: 1 end. remove =: smallest i.1 remove_list =: remove, remove_list remove_value =: (remove{rowsums) , remove_value rowsums =: rowsums-remove{"1 y colsums =: colsums-remove{y table_objects =: (0) remove } table_objects end. remove =: table_objects i.1 remove_list =: remove, remove_list remove_value =: (remove{rowsums) , remove_value result =: (3, #y)$remove_list, remove_value, (#y)#lisating NB. result=. (+/remove_value), lisating ) NB. ================================ modified heuristic tournament method H NB. modified to check if the result depends on the initial sequence of elements NB.------------------------------------ touranking40 =: monad define table_objects=. (#y)#1 remove_value=. 0 rowsums=. +/"1 y lisating=. 0 whilst. (* +/table_objects) do. 0=((*0{(sm=. (0) ((I. nsm) { I. sm) } sm)) *. (* +/(nsm=. -. all_largest_from (I. sm) {( +/ sm* (sm *"1 y))))) +. (*0{(sm=. (0) ((I. nsm) { I. sm) } sm)) *. (* +/(nsm=. (-. all_smallest_from (I. sm) {( +/"1 sm*"1 ((sm=. table_objects) * y))))) NB. whilst. ((*0{(sm=. (0) ((I. nsm) { I. sm) } sm)) *. (* +/(nsm=. -. all_largest_from (I. sm) {( +/ sm* (sm *"1 y))))) +. (*0{(sm=. (0) ((I. nsm) { I. sm) } sm)) *. (* +/(nsm=. (-. all_smallest_from (I. sm) {( +/"1 sm*"1 (sm * y))))) do. NB. end. if. (-.*<:+/sm) do. remove=. sm i.1 remove_value=. (remove{rowsums) + remove_value rowsums=. rowsums-remove{"1 y table_objects=. (0) remove } table_objects else. minresult=. (#y) * (#y) maxresult=. 0 to_be_removed=. I. sm winsums=. +/(sm*rowsums) if. -.*winsums do. maxresult=. 0 lisating=. 0 elseif. winsums = #to_be_removed do. maxresult=. 1 lisating=. 0 elseif. winsums > #to_be_removed do. for_j. i.#to_be_removed do. jtobe_removed=. j{to_be_removed subresult=. 0 { touranking40 (((0) jtobe_removed } table_objects) subsample_from y) minresult=. minresult <. subresult maxresult=. maxresult >. subresult end. if. minresult < maxresult do. lisating=.1 end. end. remove_value=. maxresult + remove_value table_objects=. (#y)#0 end. end. result=. remove_value, lisating ) NB. ================================ modified heuristic tournament method H NB. modified to check if the result depends on the initial sequence of elements NB.------------------------------------ touranking4 =: monad define n=. #y table_objects=. n#1 remove_list=. 0$0 remove_value=. 0$0 rowsums=. +/"1 y colsums=. +/ y lisating=. 0 whilst. (* +/table_objects) do. smallest=. table_objects whilst. newsample do. newsample=. 0 newsmallest=. -. all_smallest_from (I. smallest) {( +/"1 smallest*"1 (smallest * y)) if. (* +/newsmallest) do. smallest=. (0) ((I. newsmallest) { I. smallest) } smallest newsample=. 1 end. newsmallest=. -. all_largest_from (I. smallest) {( +/ smallest* (smallest *"1 y)) if. (* +/newsmallest) do. smallest=. (0) ((I. newsmallest) { I. smallest) } smallest newsample=. 1 end. end. if. (+/smallest) > 1 do. minresult=. *:n NB. n * n maxresult=. 0 to_be_removed=. I. smallest winsums=. +/(smallest*rowsums) if. (winsums)=0 do. minresult=. maxresult=. 0 lisating=. 0 elseif. winsums = #to_be_removed do. minresult=. maxresult=. 1 lisating=. 0 elseif. winsums > #to_be_removed do. for_j. i.#to_be_removed do. jtobe_removed=. j{to_be_removed subresult=. 0 { touranking4 (((0) jtobe_removed } table_objects) subsample_from y) minresult=. minresult <. subresult maxresult=. maxresult >. subresult end. if. minresult < maxresult do. lisating=.1 end. end. remove_value=. remove_value , maxresult table_objects=. n#0 else. remove=. smallest i.1 remove_list=. remove, remove_list remove_value=. (remove{rowsums) , remove_value rowsums=. rowsums-remove{"1 y colsums=. colsums-remove{y table_objects=. (0) remove } table_objects end. end. NB. result=. (+/remove_value), lisating remove_value2=: remove_value result=. (+/remove_value) if. result > 1 do. remove_list2=: 1 |. remove_list result2=: y sort_table remove_list2 yt=: y result2=. +/+/ ((bdiag #remove_list2) * result2) result=. (result <. result2), lisating else. result=. result, lisating end. ) NB.------------- kõigi y x y turniiritabelite läbivaatus kui x=3 ja 0:1 turniiritabelite läbivaatus kui x=2 NB. checking all 1:0 tournament tables of size 7x7 NB. result =. 2 all_tourankings 7 NB. checking all tournament tables of size 6x6 NB. result =. 3 all_tourankings 6 all_tourankings =: dyad define n=. y vvk=: (3-x) }. fin3 2 slots=: +/1+i.<:y basef=: slots#x nrof_tables=: x^ slots tables=: nrof_tables # 1 xcoordy=: xcoord <:y ycoordy=: ycoord y tyk=: 1+ i.+/i.y tyk_tyk=: tyk, -tyk equi_table_=. equi_table y bdg=: bdiag y all1_bdg=: 0 < * ( all_bdg=: ( (i.!y) A. i.y ) C."1 ((i.!y) A. i.y) C. (base2table y) ) for_j. i.nrof_tables do. if. (j { tables) do. NB. *. (j > 286240) do. alga=: ( basef #: j ) {vvk below =: I. 0{|:alga above =: I. 1{|:alga x0=: (below { xcoordy) , <:y x1=: (above { xcoordy) , <:y y0=: (below { ycoordy) , <:y y1=: (above { ycoordy) , <:y p0=: (x0, y1) p1=: (y0, x1) tt=: gm p0 ,. p1 NB. vana p0=: (x0 ,. y0) NB. vana p1=: (x1 ,. y1) NB. vana tt=: ((gm p0) + |: (gm p1)) * equi_table_ sumfaults=: {. (touranking4 tt) jperms=: basef #. vvk i. |:"2 (2,(#tyk)) $"1 ((+/"2 tyk_tyk e."1 (all_tt=.((!y),y)$tt) * all_bdg)) tables=: (0) ((I. (j < jperms)) { jperms) } tables if. (sumfaults > (<./ <. +/"1 +/"1 all_tt * all1_bdg)) *. (*sumfaults) do. tables=: (2) j } tables end. end. end. NB. for_j result=. I. -.(2 i. tables) ) NB.------------------------------------ sisendiks turniiritabel, väljundiks kõik optimaalsed järjestused all_rankings2 =: monad define n=. #y su=. 0 seqs=. (i.!n) A. i.n min_faults=. n*n*n for_j. i.#seqs do. minfault=. +/+/ (bdiag n) * ( j{seqs ) C."1 (( j{seqs ) C. y) if. minfault < min_faults do. seq=. j su=. >:su min_faults=. minfault elseif. minfault = min_faults do. seq =. seq, j end. end. result=. (seq { seqs) ) NB.----------------------- sisendiks turniiritabel, väljundiks esimene optimaalne järjestus. Nõuab vähe mälu all_rankings3 =: monad define n=. #y su=. 0 min_faults=. n*n*n bdg=. bdiag n for_j. i.!n do. if. min_faults > (minfault=. +/+/ (bdg) * ( j A. i.n ) C."1 (( j A. i.n ) C. y)) do. seq=. j min_faults=. minfault end. end. result=. (seq A. i.n) , min_faults ) NB.---------------------------- vaja enne algväärtustada all1_bdg all_rankings4 =: monad define NB. all1_bdg=: 0 < * ( ( (i.!#y) A. i.#y ) C."1 ((i.!#y) A. i.#y) C. (base2table) ) NB. all_tt=: ( (i.!#y) A. i.#y ) C."1 ((i.!#y) A. i.#y) C. (bdiag #y) all_tt=:((!#y),#y)$y fault_list=: <. +/"1 +/"1 all_tt * all1_bdg NB. fault_list=: <. +/"1 +/"1 (((!#y),#y)$y) * all_tt result=. |:(|:((I. all_smallest_from fault_list) A. i.#y)) ,. (<./ fault_list) ) NB.-------------- seni kiireim min rikete arvu leidmine. Eelduseks, et all_seqs_ on kõik bdiag permutatsioonid NB. väljastab minimaalse rikete arvu all_rankings5 =: monad define NB. all_seqs_=: all_seqs #y result=. <./ <. +/"1 +/"1 (((!#y),#y)$y) * all_seqs_ ) NB. ------------- 2x kiirem kui all_rankings5 all_seqs4 =: 13 : 'I. ,"_1 (bdiag y) sort_table ((i.!y) A. (i.y))' NB. all_seqs_4 =: all_seqs4 #y NB. opt_ranking2 =: 13 : '/: ( {. /: +/"1 ( (i.#all_seqs_4) {all_seqs_4 ) { ,y ) A. i.#y' NB. opt_ranking väljastab esimese optimaalse järjestuse NB. (all_seqs4 #tablename) opt_ranking tablename opt_ranking =: 13 : '/: ( {. /: +/"1 ( (i.#x) {x ) { ,y ) A. i.#y' NB. local optimization - ranking subrankings NB. $ p2 paremad_jarjestused3 6 paremad_jarjestused2 =: 13 : '0{"2 ((i.y) e."2 b) { b=. all_rankings2"2 a {"1 ( a=. (i.(#x)- <:y) +/ i. y ) { x' paremad_jarjestused3 =: 13 : 'a {"1 ( a=. (i.(#x)- <:y) +/ i. y ) { x' NB. local optimization - ranking of subrankings by heuristics subseq_tours =: 13 : 'beginning + ( beginning =: I. 0 < (rikkeid"_1 subseqs ) - ( +/"1 (1{"2 tourtables ) ) ) { (0{"2 tourtables =: touranking"_1 subseqs =: x paremad_jarjestused3 y)' NB. p2 subseq_tours 9 NB. local optimization - optimal ranking of subrankings NB. vigane, pakub lahendiks järjestuse, milles on rohkem, mitte vähem rikkeid subseq_opt =: 13 : 'beginning + (beginning =: I. -. *./"1 (i. y) ="1 tourtables) { tourtables =: opt_ranking"_1 subseqs =: x paremad_jarjestused3 y' NB. p2 subseq_opt 9 NB.------------------------------------ järjenumbrile vastava 0:0, 0:1 turniiritabeli tekitamine NB. +t=. 82755 gettablee 6 gettablee =: dyad define vvk=: fin3 2 alga=: ( ((+/>:i.<: y)#3) #: x ) {vvk x0=: (a0=: I. 0{"1 alga) { x=: xcoord y y1=: (a1=: I. 1{"1 alga) { y=: ycoord y p0=: (x0 , y1) p1=: ( (a0 { y) , a1 { x ) tt=. ( gm p0,.p1 ) NB. * (1- =@i.y) ) NB.------------------------------------ järjenumbrile vastava turniiritabeli tekitamine, sobib nii 0:1 kui ka 0:0, 0:1 turniiritabelite tekitamiseks NB. +t=. 82755 gettable 3 6 gettable =: dyad define vvk=. |. (i. {.y ) { |. fin3 2 alga=. ( ((+/>:i.<: {:y)# {.y ) #: x ) {vvk x0=. (a0=. I. 0{"1 alga) { x=. xcoord {:y y1=. (a1=. I. 1{"1 alga) { y=. ycoord {:y p0=. (x0 , y1) p1=. ( (a0 { y) , a1 { x ) tt=. gm p0,.p1 ) NB.------------------------------------ järjenumbrile vastava turniiritabeli kaarte tekitamine, sobib nii 0:1 kui ka 0:0, 0:1 turniiritabelite jaoks getarcs =: dyad define vvk=. |. (i. {.y ) { |.vvk alga=. ( ((+/>:i.<: {:y)# {.y ) #: x ) {vvk x0=. (a0=. I. 0{"1 alga) { x=. xcoord {:y y1=. (a1=. I. 1{"1 alga) { y=. ycoord {:y p=. (x0 , y1) ,. ( (a0 { y) , a1 { x ) ) NB.------------------------------------ järjenumbrile vastava 0:1 turniiritabeli tekitamine gettable2 =: dyad define vvk=: }. fin3 2 alga=: ( ((+/>:i.<:y)#2) #: x ) {vvk x0=: (a0=: I. 0{"1 alga) { x=: xcoord y x1=: (a1=: I. 1{"1 alga) { x y0=: a0 { y=: ycoord y y1=: a1 { y p0=: (x0 , y1) p1=: (y0 , x1) tt=: ( gm p0,.p1 ) * (1- =@i.y) ) NB.------------------------------------ checkranking =: dyad define result=. 0$0 for_j. i.#y do. tt=. (j{y) gettable x result=. result , -. (all_rankings5 tt) = {: touranking tt end. result=. result ) NB.------------------------------------ back_to_base3 =: dyad define slots=: +/1+i.<:x xcoordy=: xcoord <:x koordinaadid=: xcoordy ,. (i.slots) {ycoord y xresult=. 0$0 yresult=. 0$0 for_j. i.x do. xresult=. xresult, (<( j{koordinaadid )) {y yresult=. yresult, (<( |.j{koordinaadid )) {y end. result=. xresult ,. yresult ) NB.------------------------------------ NB.------------------------------------ minrike=. [: +/ [: +/ ([: bdiag [: # ]) * ([ A. [: i. [: # ]) C."1 ([ A. [: i. [: # ]) C. ] NB. ================ NB. removable=: ((i.(y-5)){ 0{ touranking3 |:(x gettable y)) e. ~.(i.(y-5)){"1 |."1 all_rankings2 (x gettable y) removable=: (([: i. ] - 5:) { 0: { [: touranking [: |: gettable) e. [: ~. ([: i. ] - 5:) {"1 [: |."1 [: all_rankings2 gettable NB. removable2=: ((i.(y-5)){ 0{ touranking |:(x gettable 2 y)) e. ~.(i.(y-5)){"1 |."1 all_rankings2 (x gettable 2 y) NB. vana removable2=: (([: i. ] - 5:) { 0: { [: touranking [: |: gettable2) e. [: ~. ([: i. ] - 5:) {"1 [: |."1 [: all_rankings2 gettable2 removable2 =: 13 : '((i.(y-5)){ 0{ touranking |:(x gettable 2 y)) e. ~.(i.(y-5)){"1 |."1 all_rankings2 (x gettable 2 y)' NB. ================ removables =: dyad define vale=: _1 for_j. i.#x do. if. -. (j{x) removable y do. vale=:j break. end. end. result=. vale ) NB. ================ removables2 =: dyad define vale=: _1 for_j. i.#x do. if. -. (j{x) removable2 y do. vale=:vale, j break. end. end. result=. vale ) NB. ================ tour_1nihu_r NB. annab G meetodi järgi tabeli t turniirijärjestuse NB. tour_1nihu_r t NB. sordib tabeli t ümber uueks tabeliks NB. t sort_table tour_1nihu_r t tour_1nihu_r =: monad define y =. y ranking =. i.# y while. ( -. *./ (i.# y) = new_ranking =. tour_1nihu y sort_table ranking) do. ranking =. new_ranking { ranking end. ) NB. ================ g =: +. / . *. mp=: +/ . * NB. ================================ Global optimization method G number_to_delimiter =: 13 : ' ". ((>1{x) + i. <: koht =. I. -. (>0{x) i. y) { y' nihu_alla =: 13 : '(nihe * _1) , 0{4 $. $. abi e. nihe =. >./ , abi =. ((+/\"1 |: y * bdiag #y) - (+/\"1 y * adiag #y))' nihu_yles =: 13 : '(nihe * _1) , 0{4 $. $. abi e. nihe =. >./ , abi =. (|. |: +/\"1 |."1 y * bdiag #y) - (|. +/\ |. y * adiag #y)' nihuta =: 13 : '(suund = i.2) /:~ }. (suund =. {. /: abi ) { abi =. 2 3$ (nihu_yles y) , nihu_alla y' nihuta_ette =: 13 : '~. abi , I. -. (i. x) e. abi =. ( 0{ I. ( }. y ) >/ i. x ) , {. y' nihuta_taha =: 13 : '~. esiosa , I. -.(i. x) e. esiosa =. ( 0{ I. -.( {. y) = abi =. I. ( }. y ) >/ i. x ) , |. y' tour_1nihu =: 13 : '({. \: nihutus) {"1 ( (#y) nihuta_ette nihutus) ,. (#y) nihuta_taha nihutus =. nihuta y' tour_0nihu =: 13 : '({. \: nihutus) {"1 ( (#y) nihuta_ette nihutus) ,. (#y) nihuta_taha nihutus =. x' NB. tour_0nihu_alla =: 13 : 'x sort_table (y{4 $. $. (adiag #x) * 0 = nihu_alla_t x) tour_0nihu x' NB. 4 $. $. (adiag #p4) * 0 < nihu_alla_t p145 tour_0nihu_alla 23 NB. 4 $. $. (adiag #p4) * 0 < nihu_yles_t p145 tour_0nihu_alla 23 tour_0nihu_yles =: 13 : 'x sort_table (|. y{4 $. $. (adiag #x) * 0 = nihu_yles_t x) tour_0nihu x' NB. 4 $. $. (adiag #p4) * 0 < nihu_yles_t p145 tour_0nihu_yles 34 NB. 4 $. $. (adiag #p4) * 0 < nihu_alla_t p145 tour_0nihu_yles 34 nihu_alla_yles =: 13 : '4 $. $. (adiag #x) * 0 < nihu_alla_t x tour_0nihu_yles y' nihu_yles_yles =: 13 : '4 $. $. (adiag #x) * 0 < nihu_yles_t x tour_0nihu_yles y' NB. p73_13 nihu_alla_yles 0 NB. p73_13 nihu_yles_yles 0 NB. p145 subseq_tours 9 NB. p145 subseq_opt 9 NB. table reduction1 =: 13 : 'y sort_table (I. -.((i.#y) e. (I. 0 = +/ y)) +. (i.#y) e. (I. 0 = +/"1 y))' NB. reduced_t =: reduction1^:_ t rikkeid =: 13 : '+/+/ (bdiag #y) * y' nihu_alla_t =: 13 : '((+/\"1 |: y * bdiag #y) - (+/\"1 y * adiag #y))' nihu_yles_t =: 13 : '(|. |: +/\"1 |."1 y * bdiag #y) - (|. +/\ |. y * adiag #y)' remove_11_ties =: 13 : 'y * 1- y * |: y' tourankings =: 13 : 'y sort_table 0{touranking y' NB. =========================================== meetod G teine realisatsioon faults =: 13 : '+/+/ y * bdiag #y' move =: 13 : '((bdiag #y) * tb - (<"1 ,.~ i.#y) { tb =. |."1 +/\"1 |."1 (y - |:y)) + (adiag #y) * ta - (<"1 ,.~ i.#y) { ta =. +/\"1 y -~ |:y' NB. move t bestmoves =: 13 : '4 $. $. y = >./ , y' NB. bestmoves move t goodmoves =: 13 : '\:~ ((<"1 (4 $. $. 0 < y)) { y) ,. 4 $. $. 0 < y' NB. goodmoves move t NB. sisendiks nihutuste tabel, väljundi esimeses veerus rikete vähenemine nihutuse tulemusel, veergudes 2 ja 3 vahetamist vajavad objektid unique_byrows =: 13 : '~. /:"1~ y' NB. unique_byrows bestmoves move t change_x_from_y =: 13 : '(|. x { y) x } y' NB. parandatud, aga ikka vale (vahetab, mitte ei nihuta) sort_by_best_moves_list =: 13 : '(0{unique_byrows bestmoves move x sort_table y) change_x_from_y y' sort_by_best_moves =: 13 : 'y sort_table (0{unique_byrows bestmoves move y) change_x_from_y i.#y' NB. sort_by_best_moves^:(1) t839768 NB. tabel sort_table (0{unique_byrows bestmoves move tabel) change_x_from_y i.#tabel NB. tabel sort_by_best_moves_list^:( (i.3),_) i.#tabel NB. ============================== meetod G kolmas realisatsioon ======================== NB. peadiagonaali alune piirkond bdiag=: [: >/~ [: i. ] NB. 13 : '>/~ i.y' NB. sordi tabel x järjestuse y alusel ridu-veerge pidi sort_table =: 13 : 'y {"1 y { x' NB. tabeli peadiagonaali aluse piirkonna elementide summa rikkeid =: 13 : '+/+/ (bdiag #y) * y' NB. nihutus_tabel leiab turniiritabeli pealt üksiku objekti nihutamisel rikete arvu muutumise tabeli nihutus_tabel =: 13 : '(+/\ t2) + |. +/\ |. |: t2 =. (bdiag #y) * y - |:y' NB. nihutus_tabel tabel nihutamine =: 13 : '/: ( {. 0.5 + (}. paar) - {. /: paar) ( {.paar =. |. {. 4 $. $. ((x + |:x)) *. (* >./ ,nihutus_tabel x) *. (>./ ,nihutus_tabel x) = nihutus_tabel x) }y' NB. tabel nihutamine järjestus NB. leiab ühe nihutuse tulemuse (nihutatud tabeli) meetod_G_samm =: 13 : 'y sort_table y nihutamine i.#y' NB. rikkeid meetod_G_samm^:(0) tabel NB. iteratsioon 0, tulemuseks on algtabeli rikete arv NB. rikkeid meetod_G_samm^:(1) tabel NB. iteratsioon 1, meetod G ühe nihutuse järgne rikete arv NB. rikkeid meetod_G_samm^:(2) tabel NB. iteratsioon 2, meetod G kahe nihutuse järgne rikete arv NB. rikkeid meetod_G_samm^:(_) tabel NB. meetod G nihutuste koondumise järgne rikete arv meetod_G =: 13 : 'meetod_G_samm^:(_) y' NB. rikkeid meetod_G tabel NB. meetod G nihutuste koondumise järgne rikete arv