from Metarouting.Algebra.Matrix import * from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.ShortestR import * from Metarouting.Policy.Routing.WidestShortest import * from Metarouting.Policy.Routing.Tapping import * from Metarouting.Algorithms.APSP import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * R0 = ShortestR.zeroElt mSP = RoutingMatrix(5, 5, [ (R0, 'a'), ( 1, 'a'), (R0, 'a'), ( 2, 'a'), ( 6, 'a') , ( 1, 'b'), (R0, 'b'), ( 3, 'b'), ( 5, 'b'), ( 4, 'b') , (R0, 'c'), ( 3, 'c'), (R0, 'c'), ( 4, 'c'), (R0, 'c') , ( 2, 'd'), ( 5, 'd'), ( 4, 'd'), (R0, 'd'), (R0, 'd') , ( 6, 'e'), ( 4, 'e'), (R0, 'e'), (R0, 'e'), (R0, 'e')], cast=TappingSP) W0 = WidestShortest.zeroElt mWS = RoutingMatrix(5, 5, [ (( 0,W0), '1'), ((5, 1), '1'), ((0,W0), '1'), ((0,W0), '1'), (( 0,W0), '1') , (( 0,W0), '2'), ((0,W0), '2'), ((0,W0), '2'), ((0,W0), '2'), (( 0,W0), '2') , (( 0,W0), '3'), ((5, 4), '3'), ((0,W0), '3'), ((5, 1), '3'), (( 0,W0), '3') , (( 5, 1), '4'), ((0,W0), '4'), ((0,W0), '4'), ((0,W0), '4'), ((10, 1), '4') , ((10, 5), '5'), ((0,W0), '5'), ((5, 1), '5'), ((0,W0), '5'), (( 0,W0), '5')], cast=TappingWSP) mNH = RoutingMatrix(5, 5, [ (R0, 'a'), ( 1, 'b'), (R0, 'c'), ( 2, 'd'), ( 6, 'e') , ( 1, 'a'), (R0, 'b'), ( 3, 'c'), ( 5, 'd'), ( 4, 'e') , (R0, 'a'), ( 3, 'b'), (R0, 'c'), ( 4, 'd'), (R0, 'e') , ( 2, 'a'), ( 5, 'b'), ( 4, 'c'), (R0, 'd'), (R0, 'e') , ( 6, 'a'), ( 4, 'b'), (R0, 'c'), (R0, 'd'), (R0, 'e')], cast=TappingNH)
U = WidestShortest.unitElt B = RoutingMatrix(1, 5, [Z, Z, Z, U, Z], cast=WidestShortest) def statusString(): global count, total sstr = str(round(100.0 * (count/total),1)).rjust(6) + "% (" + str(int(count)) + "/" + str(int(total)) + ")" sys.stdout.write("\r" + sstr) sys.stdout.flush() vcount = 0 count = 0.0 total = len(bdcart)**5 A = RoutingMatrix(5, 5, [ Z , (1,1), Z , Z , Z , Z , Z , Z , Z , Z , Z , (1,4), Z , (1,1), Z , (1,1), Z , Z , Z , (2,1) , (2,5), Z , (1,1), Z , Z ], cast=WidestShortest) R = A.rightLocalOptimum() X = RoutingMatrix(1, 5, [ R(4,1), R(4,2), R(4,3), R(4,4), R(4,5) ]) for y1 in bdcart: for y2 in bdcart: for y3 in bdcart: for y4 in bdcart: for y5 in bdcart: Y = RoutingMatrix(1, 5, [y1, y2, y3, y4, y5], cast=WidestShortest) if (Y == Y*A + B and X != Y): print("Y\n" + str(Y)) if ((X+Y) != (X+Y)*A + B): print
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # imitations under the License. from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.ShortestOnShortest import * from Metarouting.Algorithms.APSP import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * R0 = ShortestR.zeroElt m = RoutingMatrix(5, 5, [ (R0, R0), (R0, 2), (R0, R0), ( 2, 4), ( 1, R0) , (R0, 2), (R0, R0), (R0, 1), ( 3, 3), ( 1, R0) , (R0, R0), (R0, 1), (R0, R0), ( 4, 1), ( 1, 1) , ( 2, 4), ( 3, 3), ( 4, 1), (R0, R0), ( 1, 3) , ( 1, R0), ( 1, R0), ( 1, 1), ( 1, 3), (R0, R0)], cast=ShortestOnShortest) print "Input matrix:\n" + str(m) + "\n" llo = m.leftLocalOptimum() rlo = m.rightLocalOptimum() print "LLO:\n" + str(llo) + "\n" print "RLO:\n" + str(rlo) + "\n" solveAPSP(dijkstraR, "Dijkstra R ( D)", m) print solveAPSP(dijkstraNDR, "Dijkstra R (ND)", m) print
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # imitations under the License. import sys from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.Diamond import * from Metarouting.Policy.Routing.WidestShortest import * B = RoutingMatrix(1, 4, [1.0, 0.0, 0.0, 0.0], cast=Diamond) def statusString(): global count, total sstr = str(round(100.0 * (count/total),1)).rjust(6) + "% (" + str(int(count)) + "/" + str(int(total)) + ")" sys.stdout.write("\r" + sstr) sys.stdout.flush() def createA(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12): return RoutingMatrix(4, 4, [Diamond.zeroElt, a1, a2, a3, a4, Diamond.zeroElt, a5, a6, a7, a8, Diamond.zeroElt, a9, a10, a11, a12, Diamond.zeroElt], cast=Diamond) dvalues0 = [ 0.0, 0.2, 0.5, 0.8 ] vcount = 0 count = 0.0 total = len(dvalues0)**12
def createA(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12): return RoutingMatrix(4, 4, [Diamond.zeroElt, a1, a2, a3, a4, Diamond.zeroElt, a5, a6, a7, a8, Diamond.zeroElt, a9, a10, a11, a12, Diamond.zeroElt], cast=Diamond)
from Metarouting.Algebra.MappingMatrix import * from Metarouting.Policy.Routing.ShortestR import * from Metarouting.Policy.Mapping.ShortestM import * from Metarouting.Algorithms.APSP import * from Metarouting.Algorithms.Mohri import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * R0 = ShortestR.zeroElt R1 = ShortestR.unitElt FI = ShortestM.zeroElt m1 = RoutingMatrix(4, 4, [R0, 1, 2, 4, 1, R0, 2, 4, 2, 2, R0, 1, 4, 4, 1, R0], cast=ShortestR) m2 = RoutingMatrix(5, 5, [ R0, 2, 1, 6, R0, 2, R0, 5, R0, 4, 1, 5, R0, 4, 3, 6, R0, 4, R0, R0, R0, 4, 3, R0, R0 ], cast=ShortestR) mAsub = RoutingMatrix(4, 4, [R0, 2, R0, 4, 2, R0, 1, 3, R0, 1, R0, 1, 4, 3, 1, R0], cast=ShortestR) mAsubstar = RoutingMatrix(5,
from Metarouting.Policy.Routing.ShortestR import * from Metarouting.Policy.Routing.Bottleneck import * from Metarouting.Policy.Forwarding.OSPF import * from Metarouting.Algorithms.Dijkstra import * from Metarouting.Algorithms.APSP import * def toOSPF(v): return OSPF( v, squeeze=Bottleneck ) SI = ShortestR.zeroElt BI = Bottleneck.unitElt a = RoutingMatrix(5, 5, [ SI, 2, 1, 6, SI , 2, SI, 5, SI, 4 , 1, 5, SI, 4, 3 , 6, SI, 4, SI, SI , SI, 4, 3, SI, SI], cast=ShortestR) m0 = ForwardingMatrix(5, 2, [ None, None , None, None , None, None , None, None , ((0,BI),2), None], cast=toOSPF) m1 = ForwardingMatrix(5, 2, [ None, None , ((1,BI),3), None , None, None , None, None , ((1,BI),17), None], cast=toOSPF)
i = 0 n = matrix.order() while (i < n): (pi, nh) = algo(matrix, i) print algoName + " [s=" + str(i) + "]: pi: " + str( pi) + " nh: " + nhStr(nh) i += 1 Z = BGP.zeroElt U = BGP.unitElt C = BGP.CUST R = BGP.PEER P = BGP.PROV bRoutingMatrix = [ Z, R, P, Z, Z, R, Z, Z, Z, Z, C, Z, Z, R, P, Z, Z, R, Z, Z, Z, Z, C, Z, Z ] m = RoutingMatrix(5, 5, bRoutingMatrix, cast=BGPt1) print "Input matrix:\n" + str(m) + "\n" llo = m.leftLocalOptimum() rlo = m.rightLocalOptimum() print "LLO:\n" + str(llo) + "\n" print "RLO:\n" + str(rlo) + "\n" solveAPSP(dijkstraR, "DijkstraR", m)
from Metarouting.Algorithms.Dijkstra import * from Metarouting.Algorithms.APSP import * def toHotPotato(v): return HotPotato(v, castS=ShortestR, castT=ShortestR) def toColdPotato(v): return ColdPotato(v, castS=ShortestR, castT=ShortestR) I = ShortestR.zeroElt m = RoutingMatrix(5, 5, [ I, 2, 1, 6, I, 2, I, 5, I, 4, 1, 5, I, 4, 3, 6, I, 4, I, I, I, 4, 3, I, I ], cast=ShortestR) I = ShortestM.zeroElt fSimple = MappingMatrix(5, 2, [I, I, 3, I, I, I, I, 1, 2, 3], cast=ShortestM) fHot = MappingMatrix( 5, 2, [None, None, (0, 3), None, None, None, None, (0, 1), (0, 2), (0, 3)], cast=toHotPotato) fCold = MappingMatrix( 5, 2, [None, None, (0, 3), None, None, None, None, (0, 1), (0, 2), (0, 3)], cast=toColdPotato)
from Metarouting.Policy.Mapping.OSPF import * from Metarouting.Algorithms.Dijkstra import * from Metarouting.Algorithms.APSP import * def toOSPF(v): return OSPF(v, squeeze=Bottleneck) SI = ShortestR.zeroElt BI = Bottleneck.unitElt a = RoutingMatrix(5, 5, [ SI, 2, 1, 6, SI, 2, SI, 5, SI, 4, 1, 5, SI, 4, 3, 6, SI, 4, SI, SI, SI, 4, 3, SI, SI ], cast=ShortestR) m0 = MappingMatrix( 5, 2, [None, None, None, None, None, None, None, None, ((0, BI), 2), None], cast=toOSPF) m1 = MappingMatrix(5, 2, [ None, None, ((1, BI), 3), None, None, None, None, None, ((1, BI), 17), None ], cast=toOSPF)
# See the License for the specific language governing permissions and # imitations under the License. from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.ShortestR import * from Metarouting.Policy.Routing.WidestShortest import * #from Metarouting.Algorithms.APSP import * #from Metarouting.Algorithms.Bellman import * #from Metarouting.Algorithms.Dijkstra import * I = ShortestR.zeroElt m = RoutingMatrix(5, 5, [(0, I), (5, 1), (0, I), (0, I), (0, I), (0, I), (0, I), (0, I), (0, I), (0, I), (0, I), (5, 4), (0, I), (5, 1), (0, I), (5, 1), (0, I), (0, I), (0, I), (10, 1), (10, 5), (0, I), (5, 1), (0, I), (0, I)], cast=WidestShortest) print("Input matrix:\n" + str(m) + "\n") llo = m.leftLocalOptimum2() rlo = m.rightLocalOptimum() print(str(m.rightLocalOptimum()) + "\n") print(str(m.rightLocalOptimum2())) #solveAPSP(dijkstraR, "Dijkstra R ( D)", m) #print #solveAPSP(dijkstraNDR, "Dijkstra R (ND)", m) #print
from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.ShortestR import * from Metarouting.Policy.Routing.WidestShortest import * from Metarouting.Policy.Routing.Tapping import * from Metarouting.Algorithms.APSP import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * R0 = ShortestR.zeroElt mSP = RoutingMatrix(5, 5, [(R0, 'a'), (1, 'a'), (R0, 'a'), (2, 'a'), (6, 'a'), (1, 'b'), (R0, 'b'), (3, 'b'), (5, 'b'), (4, 'b'), (R0, 'c'), (3, 'c'), (R0, 'c'), (4, 'c'), (R0, 'c'), (2, 'd'), (5, 'd'), (4, 'd'), (R0, 'd'), (R0, 'd'), (6, 'e'), (4, 'e'), (R0, 'e'), (R0, 'e'), (R0, 'e')], cast=TappingSP) W0 = WidestShortest.zeroElt mWS = RoutingMatrix(5, 5, [((0, W0), '1'), ((5, 1), '1'), ((0, W0), '1'), ((0, W0), '1'), ((0, W0), '1'), ((0, W0), '2'), ((0, W0), '2'), ((0, W0), '2'), ((0, W0), '2'), ((0, W0), '2'), ((0, W0), '3'), ((5, 4), '3'), ((0, W0), '3'), ((5, 1), '3'), ((0, W0), '3'), ((5, 1), '4'), ((0, W0), '4'), ((0, W0), '4'), ((0, W0), '4'), ((10, 1), '4'), ((10, 5), '5'), ((0, W0), '5'), ((5, 1), '5'), ((0, W0), '5'), ((0, W0), '5')],
# imitations under the License. from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.Bottleneck import * from Metarouting.Algorithms.Dijkstra import * from Metarouting.Algorithms.APSP import * #m = RoutingMatrix(4, 4, [ 0, 1, 2, 3 # , 1, 0, 2, 3 # , 2, 2, 0, 1 # , 3, 3, 1, 0], cast=Bottleneck) m = RoutingMatrix(5, 5, [ 0, 1, 0, 2, 6, 1, 0, 3, 5, 4, 0, 3, 0, 4, 0, 2, 5, 4, 0, 0, 6, 4, 0, 0, 0 ], cast=Bottleneck) print "Input matrix:\n" + str(m) + "\n" llo = m.leftLocalOptimum() rlo = m.rightLocalOptimum() print "LLO:\n" + str(llo) + "\n" print "RLO:\n" + str(rlo) + "\n" solveAPSP(dijkstraR, "DijkstraR", m)
from Metarouting.Algorithms.Mohri import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * R0 = ShortestR.zeroElt R1 = ShortestR.unitElt FI = ShortestM.zeroElt m1 = RoutingMatrix(4, 4, [ R0, 1, 2, 4 , 1, R0, 2, 4 , 2, 2,R0, 1 , 4, 4, 1,R0], cast=ShortestR) m2 = RoutingMatrix(5, 5, [ R0, 2, 1, 6, R0 , 2, R0, 5, R0, 4 , 1, 5, R0, 4, 3 , 6, R0, 4, R0, R0 , R0, 4, 3, R0, R0], cast=ShortestR) mAsub = RoutingMatrix(4, 4, [ R0, 2, R0, 4 , 2, R0, 1, 3 , R0, 1, R0, 1 , 4, 3, 1, R0], cast=ShortestR) mAsubstar = RoutingMatrix(5, 5, [ R1, 2, 3, 4, R0 , 2, R1, 1, 2, R0 , 3, 1, R1, 1, 1 , 4, 2, 1, R1, 3 , R0, R0, 1, 3, R0], cast=ShortestR) mA = RoutingMatrix(5, 5, [ R0, 2, R0, 4, R0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # imitations under the License. import sys from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.Diamond import * from Metarouting.Policy.Routing.WidestShortest import * bdcart = [(b, d) for b in [0, 5, 10] for d in [1, 2, 3, 4, 5, 6]] Z = WidestShortest.zeroElt U = WidestShortest.unitElt B = RoutingMatrix(1, 5, [Z, Z, Z, U, Z], cast=WidestShortest) def statusString(): global count, total sstr = str(round(100.0 * (count / total), 1)).rjust(6) + "% (" + str( int(count)) + "/" + str(int(total)) + ")" sys.stdout.write("\r" + sstr) sys.stdout.flush() vcount = 0 count = 0.0 total = len(bdcart)**5 A = RoutingMatrix(5,
# See the License for the specific language governing permissions and # imitations under the License. from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.ShortestR import * from Metarouting.Policy.Routing.WidestShortest import * from Metarouting.Algorithms.APSP import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * I = ShortestR.zeroElt m = RoutingMatrix(5, 5, [ (0, I), (5, 1), (0, I), (0, I), (0, I) , (0, I), (0, I), (0, I), (0, I), (0, I) , (0, I), (5, 4), (0, I), (5, 1), (0, I) , (5, 1), (0, I), (0, I), (0, I), (10, 1) , (10, 5), (0, I), (5, 1), (0, I), (0, I)], cast=WidestShortest) print "Input matrix:\n" + str(m) + "\n" llo = m.leftLocalOptimum2() rlo = m.rightLocalOptimum() print str(m.rightLocalOptimum()) + "\n" print str(m.rightLocalOptimum2()) #print "LLO:\n" + str(llo) + "\n" #print "RLO:\n" + str(rlo) + "\n"
from Metarouting.Policy.Mapping.ShortestM import * from Metarouting.Policy.Mapping.Potatoes import * from Metarouting.Algorithms.Dijkstra import * from Metarouting.Algorithms.APSP import * def toHotPotato(v): return HotPotato(v, castS = ShortestR, castT = ShortestR) def toColdPotato(v): return ColdPotato(v, castS = ShortestR, castT = ShortestR) I = ShortestR.zeroElt m = RoutingMatrix(5, 5, [ I, 2, 1, 6, I , 2, I, 5, I, 4 , 1, 5, I, 4, 3 , 6, I, 4, I, I , I, 4, 3, I, I], cast = ShortestR) I = ShortestM.zeroElt fSimple = MappingMatrix(5, 2, [ I, I , 3, I , I, I , I, 1 , 2, 3], cast = ShortestM) fHot = MappingMatrix(5, 2, [ None, None , (0,3), None , None, None , None, (0,1) , (0,2), (0,3)], cast = toHotPotato)
# See the License for the specific language governing permissions and # imitations under the License. from Metarouting.Algebra.RoutingMatrix import * from Metarouting.Policy.Routing.ShortestOnShortest import * from Metarouting.Algorithms.APSP import * from Metarouting.Algorithms.Bellman import * from Metarouting.Algorithms.Dijkstra import * R0 = ShortestR.zeroElt m = RoutingMatrix(5, 5, [(R0, R0), (R0, 2), (R0, R0), (2, 4), (1, R0), (R0, 2), (R0, R0), (R0, 1), (3, 3), (1, R0), (R0, R0), (R0, 1), (R0, R0), (4, 1), (1, 1), (2, 4), (3, 3), (4, 1), (R0, R0), (1, 3), (1, R0), (1, R0), (1, 1), (1, 3), (R0, R0)], cast=ShortestOnShortest) print "Input matrix:\n" + str(m) + "\n" llo = m.leftLocalOptimum() rlo = m.rightLocalOptimum() print "LLO:\n" + str(llo) + "\n" print "RLO:\n" + str(rlo) + "\n" solveAPSP(dijkstraR, "Dijkstra R ( D)", m) print solveAPSP(dijkstraNDR, "Dijkstra R (ND)", m)