1classdef Router < StatefulNode
2 % Router Probabilistic job routing node
for queueing networks
4 % Router
is a stateful node that routes jobs towards other
nodes based on
5 % probabilistic routing strategies. Unlike service stations, jobs
do not
6 % queue inside a Router node but are immediately routed to downstream
nodes
7 % according to configured routing probabilities or strategies.
9 % @brief Probabilistic routing node that directs jobs to downstream destinations
11 % Key characteristics:
12 % - Jobs flow through without queueing or service delays
13 % - Supports probabilistic routing matrices
14 % - Maintains state
for routing decisions
15 % - Can implement complex routing strategies (random, round-robin, etc.)
16 % - Essential
for modeling load balancing and traffic distribution
18 % Router
nodes are commonly used in:
19 % - Load balancing scenarios
20 % - Multi-path routing
21 % - Traffic distribution models
22 % - Complex network topologies with branching
26 % router = Router(model,
'LoadBalancer');
27 % model.addNode(router);
28 % % Set routing probabilities in routing matrix
31 % Copyright (c) 2012-2026, Imperial College London
32 % All rights reserved.
43 function self = Router(model, name)
44 % ROUTER Create a Router node instance
46 % @brief Creates a Router node
for probabilistic job routing
47 % @param model Network model to add the router to
48 % @param name String identifier
for the router node
49 % @
return self Router instance configured
for the given model
51 % Note: This
is a node and not a Station because jobs cannot queue
52 % inside it - they flow through immediately to downstream
nodes.
54 self@StatefulNode(name);
56 if isa(model,
'Network')
57 % Handle the
new delegation pattern
58 if model.isMatlabNative()
60 self.schedPolicy = SchedStrategyType.NP;
61 self.schedStrategy = SchedStrategy.FCFS;
63 self.output = Dispatcher(
classes);
65 self.schedPolicy = SchedStrategyType.NP;
66 self.server = ServiceTunnel();
67 self.numberOfServers = 1;
68 if ~model.addNode(self) %
if not a replacement
70 self.setRouting(RoutingStrategy.RAND,
classes{r});
74 % Java implementation through delegation
75 self.obj = jline.lang.nodes.Router(model.implementation.obj, name);
76 self.index = model.implementation.obj.getNodeIndex(self.obj);
78 elseif model.isMatlabNative()
80 self.schedPolicy = SchedStrategyType.NP;
81 self.schedStrategy = SchedStrategy.FCFS;
83 self.output = Dispatcher(
classes);
85 self.schedPolicy = SchedStrategyType.NP;
86 self.server = ServiceTunnel();
87 self.numberOfServers = 1;
88 if ~self.model.addNode(self) %
if not a replacement
90 self.setRouting(RoutingStrategy.RAND,
classes{r});
93 elseif model.isJavaNative()
94 self.obj=jline.lang.nodes.Router(model.obj, name);
98 function setProbRouting(self,
class, destination, probability)
99 % SETPROBROUTING(CLASS, DESTINATION, PROBABILITY)
101 setRouting(self,
class, RoutingStrategy.PROB, destination, probability);
104 function setService(self,
class, distribution)
105 % SETSERVICE(CLASS, DISTRIBUTION)
107 self.server.serviceProcess{1,
class.index}{2} = ServiceStrategy.LI;
108 self.server.serviceProcess{1,
class.index}{3} = distribution;