From ed0e1ef01c26bcd0b796b46547ab424507ebce76 Mon Sep 17 00:00:00 2001 From: kalashnikovni Date: Wed, 1 May 2024 23:40:35 -0300 Subject: [PATCH] Debugged topological sort --- sbg/multidim_inter.cpp | 1 - sbg/pw_map.cpp | 1 - sbg/sbg_algorithms.cpp | 173 +++++++++++++++++++++-------------------- sbg/sbg_algorithms.hpp | 14 ++-- test/rl1_matching.test | 30 +++---- test/rl1_scc.test | 40 +++++----- test/rl1_ts.test | 103 ++++++++++++++++++++++++ test/rl2_matching.test | 34 ++++---- test/rl2_scc.test | 40 +++++----- test/rl2_ts.test | 103 ++++++++++++++++++++++++ test/rl33_scc.test | 87 --------------------- test/rl3_scc.test | 2 +- test/test1_scc.test | 65 ++++++++++++++++ test/test1_ts.test | 2 +- test/topsort1.test | 42 +++++----- test/topsort2.test | 25 +++--- test/topsort5.test | 71 +++++++++++++++++ 17 files changed, 538 insertions(+), 295 deletions(-) create mode 100644 test/rl1_ts.test create mode 100644 test/rl2_ts.test delete mode 100644 test/rl33_scc.test create mode 100644 test/test1_scc.test create mode 100644 test/topsort5.test diff --git a/sbg/multidim_inter.cpp b/sbg/multidim_inter.cpp index d352cc3..bf75d82 100755 --- a/sbg/multidim_inter.cpp +++ b/sbg/multidim_inter.cpp @@ -17,7 +17,6 @@ ******************************************************************************/ -#include #include "sbg/multidim_inter.hpp" namespace SBG { diff --git a/sbg/pw_map.cpp b/sbg/pw_map.cpp index 49e84eb..96a8b25 100755 --- a/sbg/pw_map.cpp +++ b/sbg/pw_map.cpp @@ -17,7 +17,6 @@ ******************************************************************************/ -#include #include "sbg/pw_map.hpp" namespace SBG { diff --git a/sbg/sbg_algorithms.cpp b/sbg/sbg_algorithms.cpp index fe557a9..ccf1744 100755 --- a/sbg/sbg_algorithms.cpp +++ b/sbg/sbg_algorithms.cpp @@ -816,16 +816,15 @@ PWMap SBGSCC::calculate() template SBGTopSort::SBGTopSort() - : dsbg_(), smap_(), E_(), mapB_(), mapD_(), unordered_(), not_dependant_() - , visitedE_(), end_(), new_end_(), dom_(), exp_(), debug_(false) {} + : dsbg_(), smap_(), E_(), mapB_(), mapD_(), unordered_(), not_dependent_() + , visitedV_(), curr_(), debug_(false) {} template SBGTopSort::SBGTopSort(DSBGraph dsbg, bool debug) : dsbg_(dsbg), smap_(), E_(dsbg.E()), mapB_(dsbg.mapB()), mapD_(dsbg.mapD()) - , unordered_(dsbg.V()), not_dependant_(), visitedE_(), end_(), new_end_() - , dom_(), exp_(), debug_(debug) { - not_dependant_ = dsbg.V().difference(mapB().image()); - end_ = not_dependant_.minElem(); - new_end_ = end_; + , unordered_(dsbg.V()), not_dependent_(), visitedV_(), curr_() + , debug_(debug) { + not_dependent_ = dsbg.V().difference(mapB().image()); + curr_ = not_dependent_.minElem(); } member_imp_temp(template, SBGTopSort, DSBGraph, dsbg); @@ -834,97 +833,92 @@ member_imp_temp(template, SBGTopSort, Set, E); member_imp_temp(template, SBGTopSort, PWMap, mapB); member_imp_temp(template, SBGTopSort, PWMap, mapD); member_imp_temp(template, SBGTopSort, Set, unordered); -member_imp_temp(template, SBGTopSort, Set, not_dependant); -member_imp_temp(template, SBGTopSort, Set, visitedE); -member_imp_temp(template, SBGTopSort, Util::MD_NAT, end); -member_imp_temp(template, SBGTopSort, Util::MD_NAT, new_end); -member_imp_temp(template, SBGTopSort, Set, dom); -member_imp_temp(template, SBGTopSort, Exp, exp); +member_imp_temp(template, SBGTopSort, Set, not_dependent); +member_imp_temp(template, SBGTopSort, Set, visitedV); +member_imp_temp(template, SBGTopSort, Util::MD_NAT, curr); member_imp_temp(template, SBGTopSort, bool, debug); template -void SBGTopSort::calculateExp() +Exp SBGTopSort::calculateExp(Util::MD_NAT n1, Util::MD_NAT n2) { Exp res; - Util::MD_NAT aux_end = end(), aux_ne = new_end(); Util::RATIONAL one(1, 1); - for (unsigned int j = 0; j < end().size(); ++j) { - Util::RATIONAL x1(aux_end[j]), x2(aux_ne[j]); + for (unsigned int j = 0; j < n1.size(); ++j) { + Util::RATIONAL x1(n1[j]), x2(n2[j]); res.emplaceBack(LExp(1, x1 - x2)); } - set_exp(res); - - return; + return res; } template void SBGTopSort::topSortStep() { - Set end_set(end()); - set_dom(end_set); + Set nd = not_dependent(); + Util::MD_NAT next = nd.minElem(); + Set next_set(next), dom = next_set; + Exp exp = calculateExp(curr(), next); + set_curr(next); - Set nd = not_dependant(); - PW Vmap = dsbg().Vmap(); - Set vend = Vmap.preImage(Vmap.image(end_set)); - vend = nd.intersection(vend).difference(end_set); - if (vend.isEmpty()) { - Set ne_set(nd.minElem()); - set_dom(ne_set); - set_new_end(nd.minElem()); - Set vnew_end = Vmap.preImage(Vmap.image(ne_set)); - vnew_end = unordered().intersection(vnew_end); - if (!vnew_end.difference(nd).isEmpty()) - set_dom(vnew_end); - set_E(E().difference(mapD().preImage(ne_set))); - calculateExp(); - set_end(new_end()); - } - else { - set_dom(vend); - set_new_end(vend.minElem()); - calculateExp(); - set_end(vend.maxElem()); + if (debug()) { + Util::SBG_LOG << "curr: " << curr() << "\n"; + Util::SBG_LOG << "dom: " << dom << "\n"; + Util::SBG_LOG << "exp: " << exp << "\n\n"; } - - smap_ref().emplaceBack(SBGMap(dom(), exp())); + Set ingoing = mapD().preImage(dom); + updateStatus(dom, exp, ingoing); + return; } template -void SBGTopSort::updateStatus() +void SBGTopSort::updateStatus(Set dom, Exp exp, Set ingoing) { - Set ordv = smap().dom(); - Set ordB = mapB().preImage(ordv), ordD = mapD().preImage(ordv); - Set orde = ordB.intersection(ordD); - - ordv = mapB().image(orde).cup(mapD().image(orde)); - Set ingoing = mapD().preImage(ordv); - Set newE = E().difference(orde); - newE = newE.difference(ingoing); - set_E(newE); + PW Vmap = dsbg().Vmap(); - if (!orde.intersection(visitedE()).isEmpty()) - set_end(smap().dom().difference(smap().image()).minElem()); + Set newE = E(); + Set ith_dom = dom, new_unord = unordered(); + if (!dom.intersection(visitedV()).isEmpty()) { + Set dom_sv = Vmap.preImage(Vmap.image(dom)); + ith_dom = dom_sv.difference(smap().dom()); - PW subE = dsbg().subE_map(); - Set SE = subE.preImage(subE.image(newE)); - set_visitedE(visitedE().cup(SE)); - - set_mapB(mapB().restrict(newE)); - set_mapD(mapD().restrict(newE)); + smap_ref().emplaceBack(SBGMap(ith_dom, exp)); + + Set ordv = smap().dom(), ith_dom_succs = smap().image(ith_dom); + if (ith_dom_succs.difference(ordv).isEmpty()) { + new_unord = new_unord.difference(ith_dom); + newE = newE.difference(mapD().preImage(ith_dom)); + } + } + else { + smap_ref().emplaceBack(SBGMap(dom, exp)); + } + new_unord = new_unord.difference(dom); + newE = newE.difference(mapD().preImage(dom)); + + Set SV = Vmap.preImage(Vmap.image(ith_dom)); + set_visitedV(visitedV().cup(SV)); + + set_E(newE); + set_mapB(mapB().restrict(E())); + set_mapD(mapD().restrict(E())); - set_unordered(unordered().difference(dom())); - set_not_dependant(unordered().difference(mapB().image())); + set_unordered(new_unord); + set_not_dependent(unordered().difference(mapB().image())); + + Set start = smap().dom().difference(smap().image()); + if (start.cardinal() == 1) + set_curr(start.minElem()); if (debug()) { + Util::SBG_LOG << "curr: " << curr() << "\n"; Util::SBG_LOG << "smap: " << smap() << "\n"; - Util::SBG_LOG << "mapB: " << mapB() << "\n"; - Util::SBG_LOG << "mapD: " << mapD() << "\n"; - Util::SBG_LOG << "end: " << end() << "\n"; - Util::SBG_LOG << "new_end: " << new_end() << "\n\n"; + Util::SBG_LOG << "E: " << E() << "\n"; + Util::SBG_LOG << "unord: " << unordered() << "\n"; + Util::SBG_LOG << "nd: " << not_dependent() << "\n"; + Util::SBG_LOG << "visitedV: " << visitedV() << "\n\n"; } return; @@ -936,15 +930,18 @@ PWMap SBGTopSort::calculate() if (debug()) Util::SBG_LOG << "Topological sort dsbg:\n" << dsbg() << "\n\n"; - while (!unordered().isEmpty()) { + Util::MD_NAT aux_curr = curr(); + Set curr_set(curr()); + Exp exp = calculateExp(curr(), curr()); + updateStatus(curr_set, exp, mapD().preImage(curr_set)); + set_curr(aux_curr); + while (!unordered().isEmpty()) topSortStep(); - updateStatus(); - } if (debug()) - Util::SBG_LOG << "Topological sort result:\n" << smap() << "\n\n"; + Util::SBG_LOG << "Topological sort result:\n" << smap().compact() << "\n\n"; - return smap(); + return smap().compact(); } // Template instantiations ----------------------------------------------------- @@ -1035,12 +1032,31 @@ DSBGraph buildSortFromSCC( const SBGSCC &scc, const PWMap &rmap ) { + DSBGraph dsbg = scc.dsbg(); + Set Ediff = dsbg.E().difference(scc.E()); + PWMap subE_map = dsbg.subE_map().restrict(Ediff); + PWMap mapB = rmap.composition(dsbg.mapB().restrict(Ediff)); + mapB = mapB.compact(); + PWMap mapD = rmap.composition(dsbg.mapD().restrict(Ediff)); + mapD = mapD.compact(); + PWMap aux_rmap = rmap.compact(); PWMap reps_rmap = aux_rmap.filterMap([](const SBGMap &sbgmap) { return eqId(sbgmap); }); Set V = reps_rmap.dom(); + for (const SBGMap &map : subE_map) { + Set ith_dom = mapB.image(map.dom()).intersection(V); + V = V.difference(ith_dom); + V = V.concatenation(ith_dom); + } + for (const SBGMap &map : subE_map) { + Set ith_dom = mapD.image(map.dom()).intersection(V); + V = V.difference(ith_dom); + V = V.concatenation(ith_dom); + } + PWMap Vmap; unsigned int j = 1, dims = rmap.nmbrDims(); for (SetPiece mdi : V) { @@ -1049,13 +1065,6 @@ DSBGraph buildSortFromSCC( ++j; } - DSBGraph dsbg = scc.dsbg(); - Set Ediff = dsbg.E().difference(scc.E()); - PWMap mapB = rmap.composition(dsbg.mapB().restrict(Ediff)); - mapB = mapB.compact(); - PWMap mapD = rmap.composition(dsbg.mapD().restrict(Ediff)); - mapD = mapD.compact(); - j = 1; PWMap Emap; for (const SBGMap &map1 : Vmap) { @@ -1069,8 +1078,6 @@ DSBGraph buildSortFromSCC( ++j; } } - // TODO: partition subset-edge - PWMap subE_map = dsbg.subE_map().restrict(Ediff); DSBGraph res(V, Vmap, mapB, mapD, Emap); res.set_subE_map(subE_map); diff --git a/sbg/sbg_algorithms.hpp b/sbg/sbg_algorithms.hpp index b09d64b..505844b 100755 --- a/sbg/sbg_algorithms.hpp +++ b/sbg/sbg_algorithms.hpp @@ -241,14 +241,10 @@ struct SBGTopSort { member_class(PW, mapD); member_class(Set, unordered); - member_class(Set, not_dependant); - member_class(Set, visitedE); + member_class(Set, not_dependent); + member_class(Set, visitedV); - member_class(Util::MD_NAT, end); - member_class(Util::MD_NAT, new_end); - - member_class(Set, dom); - member_class(Exp, exp); + member_class(Util::MD_NAT, curr); member_class(bool, debug); @@ -258,9 +254,9 @@ struct SBGTopSort { PW calculate(); private: - void calculateExp(); + Exp calculateExp(Util::MD_NAT x1, Util::MD_NAT x2); void topSortStep(); - void updateStatus(); + void updateStatus(Set dom, Exp exp, Set ingoing); }; typedef SBGTopSort BaseTopSort; diff --git a/test/rl1_matching.test b/test/rl1_matching.test index 1d0e087..7fd8179 100644 --- a/test/rl1_matching.test +++ b/test/rl1_matching.test @@ -1,8 +1,8 @@ /* model testRL1 - //iR[i+1] must be computed out of iR[i] - //uL[i] must be computed out of uL[i+1] - + //iR[i] must be computed out of iR[i+1] + //uL[i+1] must be computed out of uL[i] + constant Integer N=10; Real iL[N],iR[N],uL[N]; parameter Real L=1,R=1,L1=1,I=1,R0=1; @@ -14,8 +14,8 @@ equation iR[i]-iR[i+1]-iL[i]=0; uL[i]-uL[i+1]-R*iR[i+1]=0; end for; - iR[1]=I; - uL[N]-(iR[N]-iL[N])*R0=0; + iR[N]-iL[N]+I=0; + uL[1]+(R+R0)*iR[1]=0; end testRL1; */ @@ -37,9 +37,9 @@ E4 = N-1+E3 // F2 - iR[i+1] E5 = N-1+E4 // F3 - iR[i+1] E6 = N-1+E5 // F3 - uL[i] E7 = N-1+E6 // F3 - uL[i+1] -E8 = 1+E7 // F4 - iR[1] -E9 = 1+E8 // F5 - iR[N] -E10 = 1+E9 // F5 - uL[N] +E8 = 1+E7 // F4 - iR[N] +E9 = 1+E8 // F5 - iR[1] +E10 = 1+E9 // F5 - uL[1] off1d = r(F1, 1)-r(E1, 1) off2d = r(F1, 1)-r(E2, 1) @@ -59,9 +59,9 @@ off4b = r(U2, 1)-r(E4, 1) off5b = r(U2, 1)-r(E5, 1) off6b = r(U3, 1)-r(E6, 1)-1 off7b = r(U3, 1)-r(E7, 1) -off8b = r(U2, 1)-r(E8, 1)-N+1 -off9b = r(U2, 1)-r(E9, 1) -off10b = r(U3, 1)-E10 +off8b = r(U2, 1)-r(E8, 1) +off9b = r(U2, 1)-r(E9, 1)-N+1 +off10b = r(U3, 1)-E10-N+1 V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; @@ -77,8 +77,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 - , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5]} -> 0*x+4 + , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; matching( @@ -96,8 +96,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 - , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5]} -> 0*x+4 + , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; , 1, 6 ) diff --git a/test/rl1_scc.test b/test/rl1_scc.test index a848e4b..985a938 100644 --- a/test/rl1_scc.test +++ b/test/rl1_scc.test @@ -1,25 +1,25 @@ /* model testRL1 - //iR[i+1] must be computed out of iR[i] - //uL[i] must be computed out of uL[i+1] - - constant Integer N=10; + //iR[i] must be computed out of iR[i+1] + //uL[i+1] must be computed out of uL[i] + + constant Integer N=10; Real iL[N],iR[N],uL[N]; parameter Real L=1,R=1,L1=1,I=1,R0=1; equation for i in 1:N loop - L*der(iL[i])=uL[i]; // der(iL[1:N]) + L*der(iL[i])=uL[i]; end for; for i in 1:N-1 loop - iR[i]-iR[i+1]-iL[i]=0; // iR[2:N] - uL[i]-uL[i+1]-R*iR[i+1]=0; // uL[1:N-1] + iR[i]-iR[i+1]-iL[i]=0; + uL[i]-uL[i+1]-R*iR[i+1]=0; end for; - iR[1]=I; // iR[1] - uL[N]-(iR[N]-iL[N])*R0=0; // uL[N] + iR[N]-iL[N]+I=0; + uL[1]+(R+R0)*iR[1]=0; end testRL1; */ -N = 1000000 +N = 100 F1 = N F2 = N-1+F1 @@ -37,9 +37,9 @@ E4 = N-1+E3 // F2 - iR[i+1] E5 = N-1+E4 // F3 - iR[i+1] E6 = N-1+E5 // F3 - uL[i] E7 = N-1+E6 // F3 - uL[i+1] -E8 = 1+E7 // F4 - iR[1] -E9 = 1+E8 // F5 - iR[N] -E10 = 1+E9 // F5 - uL[N] +E8 = 1+E7 // F4 - iR[N] +E9 = 1+E8 // F5 - iR[1] +E10 = 1+E9 // F5 - uL[1] off1d = r(F1, 1)-r(E1, 1) off2d = r(F1, 1)-r(E2, 1) @@ -59,9 +59,9 @@ off4b = r(U2, 1)-r(E4, 1) off5b = r(U2, 1)-r(E5, 1) off6b = r(U3, 1)-r(E6, 1)-1 off7b = r(U3, 1)-r(E7, 1) -off8b = r(U2, 1)-r(E8, 1)-N+1 -off9b = r(U2, 1)-r(E9, 1) -off10b = r(U3, 1)-E10 +off8b = r(U2, 1)-r(E8, 1) +off9b = r(U2, 1)-r(E9, 1)-N+1 +off10b = r(U3, 1)-E10-N+1 V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; @@ -77,8 +77,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 - , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5]} -> 0*x+4 + , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; matchSCC( @@ -96,8 +96,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 - , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5]} -> 0*x+4 + , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; , 1, 6 ) diff --git a/test/rl1_ts.test b/test/rl1_ts.test new file mode 100644 index 0000000..defacd5 --- /dev/null +++ b/test/rl1_ts.test @@ -0,0 +1,103 @@ +/* +model testRL1 + //iR[i] must be computed out of iR[i+1] + //uL[i+1] must be computed out of uL[i] + + constant Integer N=10; + Real iL[N],iR[N],uL[N]; + parameter Real L=1,R=1,L1=1,I=1,R0=1; +equation + for i in 1:N loop + L*der(iL[i])=uL[i]; + end for; + for i in 1:N-1 loop + iR[i]-iR[i+1]-iL[i]=0; + uL[i]-uL[i+1]-R*iR[i+1]=0; + end for; + iR[N]-iL[N]+I=0; + uL[1]+(R+R0)*iR[1]=0; +end testRL1; +*/ + +N = 100 + +F1 = N +F2 = N-1+F1 +F3 = N-1+F2 +F4 = 1+F3 +F5 = 1+F4 +U1 = N+F5 // der(iL) +U2 = N+U1 // iR +U3 = N+U2 // uL + +E1 = N // F1 - der(iL[i]) +E2 = N+E1 // F1 - uL[i] +E3 = N-1+E2 // F2 - iR[i] +E4 = N-1+E3 // F2 - iR[i+1] +E5 = N-1+E4 // F3 - iR[i+1] +E6 = N-1+E5 // F3 - uL[i] +E7 = N-1+E6 // F3 - uL[i+1] +E8 = 1+E7 // F4 - iR[N] +E9 = 1+E8 // F5 - iR[1] +E10 = 1+E9 // F5 - uL[1] + +off1d = r(F1, 1)-r(E1, 1) +off2d = r(F1, 1)-r(E2, 1) +off3d = r(F2, 1)-r(E3, 1) +off4d = r(F2, 1)-r(E4, 1) +off5d = r(F3, 1)-r(E5, 1) +off6d = r(F3, 1)-r(E6, 1) +off7d = r(F3, 1)-r(E7, 1) +off8d = r(F4, 1)-r(E8, 1) +off9d = r(F5, 1)-r(E9, 1) +off10d = r(F5, 1)-r(E10, 1) + +off1b = r(U1, 1)-r(E1, 1) +off2b = r(U3, 1)-r(E2, 1) +off3b = r(U2, 1)-r(E3, 1)-1 +off4b = r(U2, 1)-r(E4, 1) +off5b = r(U2, 1)-r(E5, 1) +off6b = r(U3, 1)-r(E6, 1)-1 +off7b = r(U3, 1)-r(E7, 1) +off8b = r(U2, 1)-r(E8, 1) +off9b = r(U2, 1)-r(E9, 1)-N+1 +off10b = r(U3, 1)-E10-N+1 + +V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] + , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; +Vmap %= <<{[1:1:F1]} -> 0*x+1, {[F1+1:1:F2]} -> 0*x+2, {[F2+1:1:F3]} -> 0*x+3 + , {[F3+1:1:F4]} -> 0*x+4, {[F4+1:1:F5]} -> 0*x+5 + , {[F5+1:1:U1]} -> 0*x+6, {[U1+1:1:U2]} -> 0*x+7, {[U2+1:1:U3]} -> 0*x+8>>; +map1 %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d + , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d + , {[E9+1:1:E10]} -> 1*x+off10d>>; +map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b + , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b + , {[E9+1:1:E10]} -> 1*x+off10b>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 + , {[E4+1:1:E5]} -> 0*x+4 + , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E9+1:1:E10]} -> 0*x+9>>; + +matchSCCTS( +V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] + , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; +Vmap %= <<{[1:1:F1]} -> 0*x+1, {[F1+1:1:F2]} -> 0*x+2, {[F2+1:1:F3]} -> 0*x+3 + , {[F3+1:1:F4]} -> 0*x+4, {[F4+1:1:F5]} -> 0*x+5 + , {[F5+1:1:U1]} -> 0*x+6, {[U1+1:1:U2]} -> 0*x+7, {[U2+1:1:U3]} -> 0*x+8>>; +map1 %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d + , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d + , {[E9+1:1:E10]} -> 1*x+off10d>>; +map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b + , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b + , {[E9+1:1:E10]} -> 1*x+off10b>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 + , {[E4+1:1:E5]} -> 0*x+4 + , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E9+1:1:E10]} -> 0*x+9>>; + , 1, 6 +) diff --git a/test/rl2_matching.test b/test/rl2_matching.test index 51fd5d7..c4d327f 100644 --- a/test/rl2_matching.test +++ b/test/rl2_matching.test @@ -1,9 +1,9 @@ /* model testRL2 - //iR[i] must be computed out of iR[i+1] - //uL[i+1] must be computed out of uL[i] - - constant Integer N=10; + //iR[i+1] must be computed out of iR[i] + //uL[i] must be computed out of uL[i+1] + + constant Integer N=10; Real iL[N],iR[N],uL[N]; parameter Real L=1,R=1,L1=1,I=1,R0=1; equation @@ -14,12 +14,12 @@ equation iR[i]-iR[i+1]-iL[i]=0; uL[i]-uL[i+1]-R*iR[i+1]=0; end for; - iR[N]-iL[N]+I=0; - uL[1]+(R+R0)*iR[1]=0; + iR[1]=I; + uL[N]-(iR[N]-iL[N])*R0=0; end testRL2; */ -N = 100000 +N = 100 F1 = N F2 = N-1+F1 @@ -37,9 +37,9 @@ E4 = N-1+E3 // F2 - iR[i+1] E5 = N-1+E4 // F3 - iR[i+1] E6 = N-1+E5 // F3 - uL[i] E7 = N-1+E6 // F3 - uL[i+1] -E8 = 1+E7 // F4 - iR[N] -E9 = 1+E8 // F5 - iR[1] -E10 = 1+E9 // F5 - uL[1] +E8 = 1+E7 // F4 - iR[1] +E9 = 1+E8 // F5 - iR[N] +E10 = 1+E9 // F5 - uL[N] off1d = r(F1, 1)-r(E1, 1) off2d = r(F1, 1)-r(E2, 1) @@ -59,9 +59,9 @@ off4b = r(U2, 1)-r(E4, 1) off5b = r(U2, 1)-r(E5, 1) off6b = r(U3, 1)-r(E6, 1)-1 off7b = r(U3, 1)-r(E7, 1) -off8b = r(U2, 1)-r(E8, 1) -off9b = r(U2, 1)-r(E9, 1)-N+1 -off10b = r(U3, 1)-E10-N+1 +off8b = r(U2, 1)-r(E8, 1)-N+1 +off9b = r(U2, 1)-r(E9, 1) +off10b = r(U3, 1)-E10 V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; @@ -77,8 +77,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5]} -> 0*x+4 - , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 + , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; matching( @@ -96,8 +96,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5]} -> 0*x+4 - , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 + , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; , 1, 6 ) diff --git a/test/rl2_scc.test b/test/rl2_scc.test index 4461234..7bdc4bb 100644 --- a/test/rl2_scc.test +++ b/test/rl2_scc.test @@ -1,25 +1,25 @@ /* model testRL2 - //iR[i] must be computed out of iR[i+1] - //uL[i+1] must be computed out of uL[i] - - constant Integer N=10; + //iR[i+1] must be computed out of iR[i] + //uL[i] must be computed out of uL[i+1] + + constant Integer N=10; Real iL[N],iR[N],uL[N]; parameter Real L=1,R=1,L1=1,I=1,R0=1; equation for i in 1:N loop - L*der(iL[i])=uL[i]; + L*der(iL[i])=uL[i]; // der(iL[1:N]) end for; for i in 1:N-1 loop - iR[i]-iR[i+1]-iL[i]=0; - uL[i]-uL[i+1]-R*iR[i+1]=0; + iR[i]-iR[i+1]-iL[i]=0; // iR[2:N] + uL[i]-uL[i+1]-R*iR[i+1]=0; // uL[1:N-1] end for; - iR[N]-iL[N]+I=0; - uL[1]+(R+R0)*iR[1]=0; + iR[1]=I; // iR[1] + uL[N]-(iR[N]-iL[N])*R0=0; // uL[N] end testRL2; */ -N = 1000000 +N = 100 F1 = N F2 = N-1+F1 @@ -37,9 +37,9 @@ E4 = N-1+E3 // F2 - iR[i+1] E5 = N-1+E4 // F3 - iR[i+1] E6 = N-1+E5 // F3 - uL[i] E7 = N-1+E6 // F3 - uL[i+1] -E8 = 1+E7 // F4 - iR[N] -E9 = 1+E8 // F5 - iR[1] -E10 = 1+E9 // F5 - uL[1] +E8 = 1+E7 // F4 - iR[1] +E9 = 1+E8 // F5 - iR[N] +E10 = 1+E9 // F5 - uL[N] off1d = r(F1, 1)-r(E1, 1) off2d = r(F1, 1)-r(E2, 1) @@ -59,9 +59,9 @@ off4b = r(U2, 1)-r(E4, 1) off5b = r(U2, 1)-r(E5, 1) off6b = r(U3, 1)-r(E6, 1)-1 off7b = r(U3, 1)-r(E7, 1) -off8b = r(U2, 1)-r(E8, 1) -off9b = r(U2, 1)-r(E9, 1)-N+1 -off10b = r(U3, 1)-E10-N+1 +off8b = r(U2, 1)-r(E8, 1)-N+1 +off9b = r(U2, 1)-r(E9, 1) +off10b = r(U3, 1)-E10 V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; @@ -77,8 +77,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5]} -> 0*x+4 - , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 + , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; matchSCC( @@ -96,8 +96,8 @@ map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b , {[E9+1:1:E10]} -> 1*x+off10b>>; Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 - , {[E4+1:1:E5]} -> 0*x+4 - , {[E5+1:1:E6], [E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 + , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 , {[E9+1:1:E10]} -> 0*x+9>>; , 1, 6 ) diff --git a/test/rl2_ts.test b/test/rl2_ts.test new file mode 100644 index 0000000..a340810 --- /dev/null +++ b/test/rl2_ts.test @@ -0,0 +1,103 @@ +/* +model testRL2 + //iR[i+1] must be computed out of iR[i] + //uL[i] must be computed out of uL[i+1] + + constant Integer N=10; + Real iL[N],iR[N],uL[N]; + parameter Real L=1,R=1,L1=1,I=1,R0=1; +equation + for i in 1:N loop + L*der(iL[i])=uL[i]; // der(iL[1:N]) + end for; + for i in 1:N-1 loop + iR[i]-iR[i+1]-iL[i]=0; // iR[2:N] + uL[i]-uL[i+1]-R*iR[i+1]=0; // uL[1:N-1] + end for; + iR[1]=I; // iR[1] + uL[N]-(iR[N]-iL[N])*R0=0; // uL[N] +end testRL2; +*/ + +N = 1000000 + +F1 = N +F2 = N-1+F1 +F3 = N-1+F2 +F4 = 1+F3 +F5 = 1+F4 +U1 = N+F5 // der(iL) +U2 = N+U1 // iR +U3 = N+U2 // uL + +E1 = N // F1 - der(iL[i]) +E2 = N+E1 // F1 - uL[i] +E3 = N-1+E2 // F2 - iR[i] +E4 = N-1+E3 // F2 - iR[i+1] +E5 = N-1+E4 // F3 - iR[i+1] +E6 = N-1+E5 // F3 - uL[i] +E7 = N-1+E6 // F3 - uL[i+1] +E8 = 1+E7 // F4 - iR[1] +E9 = 1+E8 // F5 - iR[N] +E10 = 1+E9 // F5 - uL[N] + +off1d = r(F1, 1)-r(E1, 1) +off2d = r(F1, 1)-r(E2, 1) +off3d = r(F2, 1)-r(E3, 1) +off4d = r(F2, 1)-r(E4, 1) +off5d = r(F3, 1)-r(E5, 1) +off6d = r(F3, 1)-r(E6, 1) +off7d = r(F3, 1)-r(E7, 1) +off8d = r(F4, 1)-r(E8, 1) +off9d = r(F5, 1)-r(E9, 1) +off10d = r(F5, 1)-r(E10, 1) + +off1b = r(U1, 1)-r(E1, 1) +off2b = r(U3, 1)-r(E2, 1) +off3b = r(U2, 1)-r(E3, 1)-1 +off4b = r(U2, 1)-r(E4, 1) +off5b = r(U2, 1)-r(E5, 1) +off6b = r(U3, 1)-r(E6, 1)-1 +off7b = r(U3, 1)-r(E7, 1) +off8b = r(U2, 1)-r(E8, 1)-N+1 +off9b = r(U2, 1)-r(E9, 1) +off10b = r(U3, 1)-E10 + +V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] + , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; +Vmap %= <<{[1:1:F1]} -> 0*x+1, {[F1+1:1:F2]} -> 0*x+2, {[F2+1:1:F3]} -> 0*x+3 + , {[F3+1:1:F4]} -> 0*x+4, {[F4+1:1:F5]} -> 0*x+5 + , {[F5+1:1:U1]} -> 0*x+6, {[U1+1:1:U2]} -> 0*x+7, {[U2+1:1:U3]} -> 0*x+8>>; +map1 %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d + , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d + , {[E9+1:1:E10]} -> 1*x+off10d>>; +map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b + , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b + , {[E9+1:1:E10]} -> 1*x+off10b>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 + , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 + , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E9+1:1:E10]} -> 0*x+9>>; + +matchSCCTS( +V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:F4], [F4+1:1:F5] + , [F5+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; +Vmap %= <<{[1:1:F1]} -> 0*x+1, {[F1+1:1:F2]} -> 0*x+2, {[F2+1:1:F3]} -> 0*x+3 + , {[F3+1:1:F4]} -> 0*x+4, {[F4+1:1:F5]} -> 0*x+5 + , {[F5+1:1:U1]} -> 0*x+6, {[U1+1:1:U2]} -> 0*x+7, {[U2+1:1:U3]} -> 0*x+8>>; +map1 %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d + , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d + , {[E9+1:1:E10]} -> 1*x+off10d>>; +map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b + , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b + , {[E9+1:1:E10]} -> 1*x+off10b>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3], [E3+1:1:E4]} -> 0*x+3 + , {[E4+1:1:E5], [E5+1:1:E6]} -> 0*x+4 + , {[E6+1:1:E7]} -> 0*x+6, {[E7+1:1:E8]} -> 0*x+7, {[E8+1:1:E9]} -> 0*x+8 + , {[E9+1:1:E10]} -> 0*x+9>>; + , 1, 6 +) diff --git a/test/rl33_scc.test b/test/rl33_scc.test deleted file mode 100644 index de8004c..0000000 --- a/test/rl33_scc.test +++ /dev/null @@ -1,87 +0,0 @@ -/* -model testRL3 - //iR[i] and iR[i+1] can be computed out of each other - //uL[i] and uL[i+1] can be computed out of each other - //All variables form a large algebraic loop - - constant Integer N=5; - Real iL[N],iR[N],uL[N]; - parameter Real L=1,R=1,L1=1,U=1,R0=1; -equation - for i in 1:N loop - L*der(iL[i])=uL[i]; // der(iL[1:N]) - end for; - for i in 1:N-1 loop - iR[i]-iR[i+1]-iL[i]=0; // iR[2:N] - uL[i]-uL[i+1]-R*iR[i+1]=0; // uL[1:N-1] - end for; - U-uL[1]-R*iR[1]=0; // iR[1] - uL[N]-(iR[N]-iL[N])*R0=0; // uL[N] -end testRL3; -*/ - -N = 100000 - -V1 = N -V2 = N-1+V1 -V3 = N-1+V2 -V4 = 1+V3 -V5 = 1+V4 - -E1 = N-1 // V1 - V3 -E2 = 1+E1 // V1 - V5 -E3 = N-2+E2 // V2 - V2 -E4 = 1+E3 // V2 - V4 -E5 = N-1+E4 // V3 - V2 -E6 = N-2+E5 // V3 - V3 -E7 = 1+E6 // V3 - V5 -E8 = 1+E7 // V4 - V3 -E9 = 1+E8 // V5 - V2 - -off1d = r(V3, 1)-r(E1, 1) -off2d = r(V5, 1)-r(E2, 1) -off3d = r(V2, 1)-r(E3, 1)-1 -off4d = r(V4, 1)-r(E4, 1) -off5d = r(V2, 1)-r(E5, 1) -off6d = r(V3, 1)-r(E6, 1) -off7d = r(V5, 1)-r(E7, 1) -off8d = r(V3, 1)-r(E8, 1)-N+2 -off9d = r(V2, 1)-r(E9, 1) - -off1b = r(V1, 1)-r(E1, 1)-1 -off2b = r(V1, 1)-r(E2, 1) -off3b = r(V2, 1)-r(E3, 1) -off4b = r(V2, 1)-r(E4, 1)-N+2 -off5b = r(V3, 1)-r(E5, 1) -off6b = r(V3, 1)-r(E6, 1)-1 -off7b = r(V3, 1)-r(E7, 1) -off8b = r(V4, 1)-r(E8, 1) -off9b = r(V5, 1)-r(E9, 1) - -V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3], [V3+1:1:V4], [V4+1:1:V5]}; -Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3]} -> 0*x+3 - , {[V3+1:1:V4]} -> 0*x+4, {[V4+1:1:V5]} -> 0*x+5>>; -mapB %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b - , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b - , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b>>; -mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d - , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d - , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d>>; -Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3]} -> 0*x+3 - , {[E3+1:1:E4]} -> 0*x+4, {[E4+1:1:E5]} -> 0*x+5, {[E5+1:1:E6]} -> 0*x+6 - , {[E6+1:1:E7]} -> 0*x+7, {[E7+1:1:E8]} -> 0*x+8, {[E8+1:1:E9]} -> 0*x+9>>; - -scc( -V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3], [V3+1:1:V4], [V4+1:1:V5]}; -Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3]} -> 0*x+3 - , {[V3+1:1:V4]} -> 0*x+4, {[V4+1:1:V5]} -> 0*x+5>>; -mapB %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b - , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b - , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b>>; -mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d - , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d - , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d>>; -Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3]} -> 0*x+3 - , {[E3+1:1:E4]} -> 0*x+4, {[E4+1:1:E5]} -> 0*x+5, {[E5+1:1:E6]} -> 0*x+6 - , {[E6+1:1:E7]} -> 0*x+7, {[E7+1:1:E8]} -> 0*x+8, {[E8+1:1:E9]} -> 0*x+9>>; -) diff --git a/test/rl3_scc.test b/test/rl3_scc.test index ea0ca6c..9af65d5 100644 --- a/test/rl3_scc.test +++ b/test/rl3_scc.test @@ -20,7 +20,7 @@ equation end testRL3; */ -N = 1000 +N = 2 F1 = N F2 = N-1+F1 diff --git a/test/test1_scc.test b/test/test1_scc.test new file mode 100644 index 0000000..79051d5 --- /dev/null +++ b/test/test1_scc.test @@ -0,0 +1,65 @@ +/* +model Test1 + constant Integer N = 100; + Real a[N], b[N], x[N]; +equation + for i in 1:N loop + a[i] = 2 * x[i] - b[i]; + a[i] = 2 * b[i] - x[i]; + der(x[i]) = 1 - a[i]; + end for; +end Test1; +*/ + +N = 10 + +F1 = N +F2 = N+F1 +F3 = N+F2 +U1 = N+F3 +U2 = N+U1 +U3 = N+U2 + +E1 = N // F1 - a[i] +E2 = N+E1 // F1 - b[i] +E3 = N+E2 // F2 - a[i] +E4 = N+E3 // F2 - b[i] +E5 = N+E4 // F3 - a[i] +E6 = N+E5 // F3 - der(x[i]) + +off1d = 0 +off2d = r(F1, 1)-r(E2, 1) +off3d = r(F2, 1)-r(E3, 1) +off4d = r(F2, 1)-r(E4, 1) +off5d = r(F3, 1)-r(E5, 1) +off6d = r(F3, 1)-r(E6, 1) + +off1b = r(U1, 1)-r(E1, 1) +off2b = r(U2, 1)-r(E2, 1) +off3b = r(U1, 1)-r(E3, 1) +off4b = r(U2, 1)-r(E4, 1) +off5b = r(U1, 1)-r(E5, 1) +off6b = r(U3, 1)-r(E6, 1) + +V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; +Vmap %= <<{[1:1:F1]} -> 0*x+1, {[F1+1:1:F2]} -> 0*x+2, {[F2+1:1:F3]} -> 0*x+3 + , {[F3+1:1:U1]} -> 0*x+10, {[U1+1:1:U2]} -> 0*x+11, {[U2+1:1:U3]} -> 0*x+12>>; +map1 %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d>>; +map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3]} -> 0*x+3 + , {[E3+1:1:E4]} -> 0*x+4, {[E4+1:1:E5]} -> 0*x+5, {[E5+1:1:E6]} -> 0*x+6>>; + +matchSCC( +V %= {[1:1:F1], [F1+1:1:F2], [F2+1:1:F3], [F3+1:1:U1], [U1+1:1:U2], [U2+1:1:U3]}; +Vmap %= <<{[1:1:F1]} -> 0*x+1, {[F1+1:1:F2]} -> 0*x+2, {[F2+1:1:F3]} -> 0*x+3 + , {[F3+1:1:U1]} -> 0*x+10, {[U1+1:1:U2]} -> 0*x+11, {[U2+1:1:U3]} -> 0*x+12>>; +map1 %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d>>; +map2 %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3]} -> 0*x+3 + , {[E3+1:1:E4]} -> 0*x+4, {[E4+1:1:E5]} -> 0*x+5, {[E5+1:1:E6]} -> 0*x+6>>; +, 1, 6 +) diff --git a/test/test1_ts.test b/test/test1_ts.test index 4435f3f..236b077 100644 --- a/test/test1_ts.test +++ b/test/test1_ts.test @@ -25,7 +25,7 @@ equation end Test1; */ -N = 100000 +N = 10 F1 = N F2 = N+F1 diff --git a/test/topsort1.test b/test/topsort1.test index 3110a7a..b068da7 100644 --- a/test/topsort1.test +++ b/test/topsort1.test @@ -1,33 +1,27 @@ -// Topological sort test, with a simple recursion, and a self recursion on the right +// Topological sort test, with two set vertices, with a bijective +// map from one to the other asa set-edge -N = 10000 +N = 10 -V1 = 1 -V2 = N-1+V1 -V3 = N+V2 +V1 = N +V2 = N+V1 -E1 = 1 -E2 = N-1+E1 -E3 = N-1+E2 +E1 = N -off3b = N-1 +off1b = r(V2, 1)-E1 -off1d = N -off2d = N-1 -off3d = 1 +off1d = r(V1, 1)-E1 -V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3]}; -Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3-1]} -> 0*x+3 - , {[V3:1:V3]} -> 0*x+4>>; -mapB %= <<{[1:1:E1]} -> 1*x+0, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x-off3b>>; -mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+0, {[E2+1:1:E3]} -> 1*x+off3d>>; -Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2>>; +V %= {[1:1:V1], [V1+1:1:V2]}; +Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2>>; +mapB %= <<{[1:1:E1]} -> 1*x+off1b>>; +mapD %= <<{[1:1:E1]} -> 1*x+off1d>>; +Emap %= <<{[1:1:E1]} -> 0*x+1>>; sort( - V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3]}; - Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3-1]} -> 0*x+3 - , {[V3:1:V3]} -> 0*x+4>>; - mapB %= <<{[1:1:E1]} -> 1*x+0, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x-off3b>>; - mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+0, {[E2+1:1:E3]} -> 1*x+off3d>>; - Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2>>; + V %= {[1:1:V1], [V1+1:1:V2]}; + Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2>>; + mapB %= <<{[1:1:E1]} -> 1*x+off1b>>; + mapD %= <<{[1:1:E1]} -> 1*x+off1d>>; + Emap %= <<{[1:1:E1]} -> 0*x+1>>; ) diff --git a/test/topsort2.test b/test/topsort2.test index 571fe6c..0781c4a 100644 --- a/test/topsort2.test +++ b/test/topsort2.test @@ -9,32 +9,25 @@ V3 = N+V2 E1 = 1 E2 = N-1+E1 E3 = N-1+E2 -E4 = N-1+E3 off3b = N-1 -off4b = r(V3, 1)-E4-1 off1d = N off2d = N-1 off3d = 1 -off4d = r(V3, 1)-E4 V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3]}; Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3-1]} -> 0*x+3 , {[V3:1:V3]} -> 0*x+4>>; -mapB %= <<{[1:1:E1]} -> 1*x+0, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x-off3b - , {[E3+1:1:E4]} -> 1*x+off4b>>; -mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+0, {[E2+1:1:E3]} -> 1*x+off3d - , {[E3+1:1:E4]} -> 1*x+off4d>>; -Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2, {[E3+1:1:E4]} -> 0*x+3>>; +mapB %= <<{[1:1:E1]} -> 1*x+0, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x-off3b>>; +mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+0, {[E2+1:1:E3]} -> 1*x+off3d>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2>>; sort( -V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3]}; -Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3-1]} -> 0*x+3 - , {[V3:1:V3]} -> 0*x+4>>; -mapB %= <<{[1:1:E1]} -> 1*x+0, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x-off3b - , {[E3+1:1:E4]} -> 1*x+off4b>>; -mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+0, {[E2+1:1:E3]} -> 1*x+off3d - , {[E3+1:1:E4]} -> 1*x+off4d>>; -Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2, {[E3+1:1:E4]} -> 0*x+3>>; + V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3]}; + Vmap %= <<{[1:1:V1]} -> 0*x+1, {[V1+1:1:V2]} -> 0*x+2, {[V2+1:1:V3-1]} -> 0*x+3 + , {[V3:1:V3]} -> 0*x+4>>; + mapB %= <<{[1:1:E1]} -> 1*x+0, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x-off3b>>; + mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+0, {[E2+1:1:E3]} -> 1*x+off3d>>; + Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2], [E2+1:1:E3]} -> 0*x+2>>; ) diff --git a/test/topsort5.test b/test/topsort5.test new file mode 100644 index 0000000..3e78c4b --- /dev/null +++ b/test/topsort5.test @@ -0,0 +1,71 @@ +// Topological sort test of RL1 + +N = 5 + +V1 = N +V2 = N-1+V1 +V3 = N-1+V2 +V4 = 1+V3 +V5 = 1+V4 + +E1 = N-1 +E2 = 1+E1 +E3 = N-2+E2 +E4 = 1+E3 +E5 = N-2+E4 +E6 = N-2+E5 +E7 = 1+E6 +E8 = 1+E7 +E9 = 1+E8 + +off1b = r(V1, 1)-r(E1, 1) +off2b = r(V1, 1)-r(E2, 1)-N+1 +off3b = r(V2, 1)-r(E3, 1)-1 +off4b = r(V2, 1)-r(E4, 1) +off5b = r(V3, 1)-r(E5, 1)-1 +off6b = r(V3, 1)-r(E6, 1) +off7b = r(V3, 1)-r(E7, 1) +off8b = r(V3, 1)-r(E8, 1)-N+2 +off9b = r(V5, 1)-r(E9, 1) + +off1d = r(V3, 1)-r(E1, 1) +off2d = r(V5, 1)-r(E2, 1) +off3d = r(V2, 1)-r(E3, 1) +off4d = r(V4, 1)-r(E4, 1) +off5d = r(V2, 1)-r(E5, 1) +off6d = r(V3, 1)-r(E6, 1)-1 +off7d = r(V4, 1)-r(E7, 1) +off8d = r(V5, 1)-r(E8, 1) +off9d = r(V2, 1)-r(E9, 1)-N+2 + +V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3], [V3+1:1:V4], [V4+1:1:V5]}; +Vmap %= <<{[1:1:1]} -> 0*x+1, {[2:1:V1]} -> 0*x+2, {[V1+1:1:V1+1]} -> 0*x+3 + , {[V1+2:1:V2-1]} -> 0*x+4, {[V2:1:V2]} -> 0*x+5, {[V2+1:1:V2+1]} -> 0*x+6 + , {[V2+2:1:V3-1]} -> 0*x+7, {[V3:1:V3]} -> 0*x+8, {[V4:1:V4]} -> 0*x+9 + , {[V5:1:V5]} -> 0*x+10>>; +mapB %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b + , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b>>; +mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d + , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d>>; +Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3]} -> 0*x+3 + , {[E3+1:1:E4]} -> 0*x+4, {[E4+1:1:E5]} -> 0*x+5, {[E5+1:1:E6]} -> 0*x+6 + , {[E6+1:1:E7]} -> 0*x+7, {[E7+1:1:E8]} -> 0*x+8, {[E8+1:1:E9]} -> 0*x+9>>; + +sort( + V %= {[1:1:V1], [V1+1:1:V2], [V2+1:1:V3], [V3+1:1:V4], [V4+1:1:V5]}; + Vmap %= <<{[1:1:1]} -> 0*x+1, {[2:1:V1]} -> 0*x+2, {[V1+1:1:V1+1]} -> 0*x+3 + , {[V1+2:1:V2-1]} -> 0*x+4, {[V2:1:V2]} -> 0*x+5, {[V2+1:1:V2+1]} -> 0*x+6 + , {[V2+2:1:V3-1]} -> 0*x+7, {[V3:1:V3]} -> 0*x+8, {[V4:1:V4]} -> 0*x+9 + , {[V5:1:V5]} -> 0*x+10>>; + mapB %= <<{[1:1:E1]} -> 1*x+off1b, {[E1+1:1:E2]} -> 1*x+off2b, {[E2+1:1:E3]} -> 1*x+off3b + , {[E3+1:1:E4]} -> 1*x+off4b, {[E4+1:1:E5]} -> 1*x+off5b, {[E5+1:1:E6]} -> 1*x+off6b + , {[E6+1:1:E7]} -> 1*x+off7b, {[E7+1:1:E8]} -> 1*x+off8b, {[E8+1:1:E9]} -> 1*x+off9b>>; + mapD %= <<{[1:1:E1]} -> 1*x+off1d, {[E1+1:1:E2]} -> 1*x+off2d, {[E2+1:1:E3]} -> 1*x+off3d + , {[E3+1:1:E4]} -> 1*x+off4d, {[E4+1:1:E5]} -> 1*x+off5d, {[E5+1:1:E6]} -> 1*x+off6d + , {[E6+1:1:E7]} -> 1*x+off7d, {[E7+1:1:E8]} -> 1*x+off8d, {[E8+1:1:E9]} -> 1*x+off9d>>; + Emap %= <<{[1:1:E1]} -> 0*x+1, {[E1+1:1:E2]} -> 0*x+2, {[E2+1:1:E3]} -> 0*x+3 + , {[E3+1:1:E4]} -> 0*x+4, {[E4+1:1:E5]} -> 0*x+5, {[E5+1:1:E6]} -> 0*x+6 + , {[E6+1:1:E7]} -> 0*x+7, {[E7+1:1:E8]} -> 0*x+8, {[E8+1:1:E9]} -> 0*x+9>>; +)