val graph:(int*int*int) list=[(1,2,20),(1,3,23),(1,4,1),(2,4,4), (2,5,15),(3,4,36),(3,6,28),(4,5,9), (4,7,16),(4,6,25),(5,7,3),(6,7,17)]; val visited:bool list=[false,false,false,false,false,false,false]; val actmin:int=20000; fun isintup (k1,k2:int) (ti1,ti2,ti3:int)= if ((k1=ti1) andalso (k2=ti2)) orelse ((k1=ti2) andalso (k2=ti1)) then true else false; fun istverb (i1,i2:int) (li:(int*int*int) list)= if isintup (i1,i2) (nth(li,0)) then (true,#3(nth(li,0))) else if isintup (i1,i2) (nth(li,1)) then (true,#3(nth(li,1))) else if isintup (i1,i2) (nth(li,2)) then (true,#3(nth(li,2))) else if isintup (i1,i2) (nth(li,3)) then (true,#3(nth(li,3))) else if isintup (i1,i2) (nth(li,4)) then (true,#3(nth(li,4))) else if isintup (i1,i2) (nth(li,5)) then (true,#3(nth(li,5))) else if isintup (i1,i2) (nth(li,6)) then (true,#3(nth(li,6))) else if isintup (i1,i2) (nth(li,7)) then (true,#3(nth(li,7))) else if isintup (i1,i2) (nth(li,8)) then (true,#3(nth(li,8))) else if isintup (i1,i2) (nth(li,9)) then (true,#3(nth(li,9))) else if isintup (i1,i2) (nth(li,10)) then (true,#3(nth(li,10))) else if isintup (i1,i2) (nth(li,11)) then (true,#3(nth(li,11))) else (false,0); fun allebesucht (li:bool list)= if li=[true,true,true,true,true,true,true] then true else false; fun update (n:int) (wertact:int)= if n<wertact then n else wertact; fun erste (f: 'a list,pos:int)= if pos=0 then [] else if pos=1 then hd(f)::nil else hd(f)::nil@erste(tl(f),pos-1); (* Diese Funktion entfernt die ersten Elemente bis einschliesslich *) (* Position 'pos' einer beliegen Liste *) fun letzte (f: 'a list,pos:int)= if pos=0 then f else if pos=1 then tl(f) else letzte(tl(f),pos-1); fun markkno (n:int) (li:bool list)=erste(li,n-1)@[true]@letzte(li,n); fun unmarkkno (n:int) (li:bool list)=erste(li,n-1)@[false]@letzte(li,n); fun ismarked (n:int) (li:bool list)=if nth(li,n-1) then true else false; fun co (sk:int) (i:int) (li:(int*int*int) list) (bli:bool list)= if (#1(istverb (sk,i) graph) andalso not(nth(bli,i-1))) then #2(istverb (sk,i) graph) else 22000; fun checkstate (n:int) (li:(int*int*int) list) (bli:bool list)= (((co n 1 li bli),1)::((co n 2 li bli),2)::((co n 3 li bli),3)::((co n 4 li bli),4):: ((co n 5 li bli),5)::((co n 6 li bli),6)::((co n 7 li bli),7)::nil); fun revco (sk:int) (i:int) (li:(int*int*int) list) (bli:bool list)= if (#1(istverb (sk,i) graph) andalso nth(bli,i-1)) then #2(istverb (sk,i) graph) else 22000; fun revcheckstate (n:int) (li:(int*int*int) list) (bli:bool list)= (((revco n 1 li bli),1)::((revco n 2 li bli),2)::((revco n 3 li bli),3)::((revco n 4 li bli),4):: ((revco n 5 li bli),5)::((revco n 6 li bli),6)::((revco n 7 li bli),7)::nil); fun del22000 (n:(int*int))=if #1(n)<>22000 then true else false; fun delmap f nil = nil | delmap f (hd::tl)=if f(hd) then hd::(delmap f tl) else delmap f tl; fun map22000 (li:(int*int) list)=delmap del22000 li; fun auswahl (li:(int*int) list)= if length(li)=1 then li else if (#1(hd(li)))>=(#1(hd(tl(li)))) then auswahl (tl(li)) else auswahl (tl(li)@[hd(li)]); fun geherunter (kn:int) (gr:(int*int*int) list) (bli:bool list)= ((hd(auswahl(map22000(checkstate kn gr bli)))),(markkno kn bli)); fun gehehoch (kn:int) (gr:(int*int*int) list) (bli:bool list)= ((hd(auswahl(map22000(revcheckstate kn gr bli)))),(unmarkkno kn bli)); (* fun bewege (kns:int) (kne:int) (gr:(int*int*int) list) (bli:bool list)= let val weg:(int*int) list=[] in if ((allebesucht(markkno kns bli)) andalso (#1(istverb(kns,kne) gr))) then weg else (val weg=weg@[(#1(geherunter kns gr bli))]); (bewege (#2(#1(geherunter kns gr (#2(geherunter kns graph bli))))) kne gr (#2(geherunter kns graph bli))) end; *)