| |
To run the below Lua script, cd to the tutorial directory ./plugins/luafaudes/tutorial and enter ./luafaudes containers.lua at the command prompt. The script will read input data from ./plugins/luafaudes/tutorial/data/.
-- Test/demonstrate basic faudes containers -- ------------------------------------------ -- Plain index set (eg StateSet) -- ------------------------------------------ -- Announce print("################# Set of indicees"); -- Create plain set of indicess iset = faudes.IndexSet(); -- Have a name iset:Name("PlainIndexContainer"); -- Insert some indicees iset:Insert(2); iset:Insert(4); iset:Insert(8); iset:Insert(10); -- Print the set via lua string conversion print(iset); -- Access via iterator print("Iterating over IndexSet:",iset:Name()); iit=iset:Begin(); while iit~=iset:End() do -- Dereference iterator directly print(iit:Index()); -- Derefernce via [] operator of the set print(iset[iit]); -- Increment iterator iit:Inc(); end -- Create a copy of the set i2set = faudes.IndexSet(iset); -- ------------------------------------------ -- Set of indicees with symbolic names -- ------------------------------------------ -- Announce print("################# Set of symbols"); -- Create the set nset = faudes.NameSet(); -- Have a name nset:Name("SymbolicIndiceesContainer"); -- Insert some elements nset:Insert("alpha"); nset:Insert("beta"); -- Print the set print(nset); -- Symbol lookup idx=nset:Index("beta"); name=nset:SymbolicName(idx); print(name, " has index ", idx); -- Iterate print("Iterating over NameSet",nset:Name()); nit=nset:Begin(); while nit~=nset:End() do -- Variants of deref print("Element: ", nit:Index(), nset[nit], nit:Name(), nset:SymbolicName(nit), nset:Str(nit)); -- Increment nit:Inc(); end -- Erase an element nset:Erase("beta"); -- Create a copy of the set n2set = faudes.EventSet(nset); -- Write to file n2set:Write("tmp_nameset.txt"); -- ------------------------------------------ -- Set of events with control-system attribute -- ------------------------------------------ -- Announce print("################# Set of events with control-system attribute") -- Create the set eg from the above set eset = faudes.EventSet(nset); -- Have a name eset:Name("Alphabet"); -- Insert some more elements eset:Insert("beta"); eset:Insert("lambda"); -- Set event to be controllabel eset:Attribute("alpha"):SetControllable(); -- Insert with an attribute prepared cattr=faudes.AttributeCFlags(); cattr:SetControllable(); eset:Insert("mue",cattr); -- Print the set print(eset); -- Iterate print("Iterating over event set",eset:Name()); eit=eset:Begin(); while eit~=eset:End() do -- Variants of deref print("Element: ", eit:Index(), eset[eit], eit:Name(), eset:Str(eit), eset:Attribute(eit)); -- Increment eit:Inc(); end -- ------------------------------------------ -- Transitions relations -- ------------------------------------------ -- Announce print("################# Set of transitions") -- Create the set tset = faudes.TransSet(); -- Have a name tset:Name("TransitionRelation"); -- Insert some transitions: by component tset:Insert(1,"alpha",2); tset:Insert(2,"beta",1); tset:Insert(2,"mue",3); -- Insert some transitions: prepared trans = faudes.Transition(3,"lambda",1); tset:Insert(trans); -- Print the set tset:Write(); -- Iterate print("Iterating over transition set",tset:Name()); tit=tset:Begin(); while tit~=tset:End() do tt=tit:Transition(); tt=faudes.Transition(1,1,1); -- Variants of deref print("Element: ", tit:Transition(), tset[tit], tset:Str(tit)); -- Increment tit:Inc(); end -- Sort in X2-Ev-X1 order trset = faudes.TransSetX2EvX1(); trset:Name("ReverseTransitionSet"); tset:ReSort(trset); -- Print the set print("Transitionset in reverse order"); trset:Write();