LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Router.m
1classdef Router < StatefulNode
2 % Router Probabilistic job routing node for queueing networks
3 %
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.
8 %
9 % @brief Probabilistic routing node that directs jobs to downstream destinations
10 %
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
17 %
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
23 %
24 % Example:
25 % @code
26 % router = Router(model, 'LoadBalancer');
27 % model.addNode(router);
28 % % Set routing probabilities in routing matrix
29 % @endcode
30 %
31 % Copyright (c) 2012-2026, Imperial College London
32 % All rights reserved.
33
34 properties
35 cap;
36 numberOfServers;
37 schedPolicy;
38 schedStrategy;
39 end
40
41 methods
42 % Constructor
43 function self = Router(model, name)
44 % ROUTER Create a Router node instance
45 %
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
50 %
51 % Note: This is a node and not a Station because jobs cannot queue
52 % inside it - they flow through immediately to downstream nodes.
53
54 self@StatefulNode(name);
55 self.setModel(model);
56 if isa(model,'Network')
57 % Handle the new delegation pattern
58 if model.isMatlabNative()
59 classes = model.getClasses();
60 self.schedPolicy = SchedStrategyType.NP;
61 self.schedStrategy = SchedStrategy.FCFS;
62 self.input = Buffer(classes);
63 self.output = Dispatcher(classes);
64 self.cap = Inf;
65 self.schedPolicy = SchedStrategyType.NP;
66 self.server = ServiceTunnel();
67 self.numberOfServers = 1;
68 if ~model.addNode(self) % if not a replacement
69 for r=1:length(classes)
70 self.setRouting(RoutingStrategy.RAND,classes{r});
71 end
72 end
73 else
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);
77 end
78 elseif model.isMatlabNative()
79 classes = model.getClasses();
80 self.schedPolicy = SchedStrategyType.NP;
81 self.schedStrategy = SchedStrategy.FCFS;
82 self.input = Buffer(classes);
83 self.output = Dispatcher(classes);
84 self.cap = Inf;
85 self.schedPolicy = SchedStrategyType.NP;
86 self.server = ServiceTunnel();
87 self.numberOfServers = 1;
88 if ~self.model.addNode(self) % if not a replacement
89 for r=1:length(classes)
90 self.setRouting(RoutingStrategy.RAND,classes{r});
91 end
92 end
93 elseif model.isJavaNative()
94 self.obj=jline.lang.nodes.Router(model.obj, name);
95 end
96 end
97
98 function setProbRouting(self, class, destination, probability)
99 % SETPROBROUTING(CLASS, DESTINATION, PROBABILITY)
100
101 setRouting(self, class, RoutingStrategy.PROB, destination, probability);
102 end
103
104 function setService(self, class, distribution)
105 % SETSERVICE(CLASS, DISTRIBUTION)
106
107 self.server.serviceProcess{1, class.index}{2} = ServiceStrategy.LI;
108 self.server.serviceProcess{1, class.index}{3} = distribution;
109 end
110
111 end
112
113end
Definition mmt.m:92