LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Fork.m
1classdef Fork < Node
2 % Fork Job splitting node for parallel processing models
3 %
4 % Fork is a specialized node that splits incoming jobs into multiple sibling
5 % tasks that can be processed in parallel by downstream nodes. Each job
6 % arriving at a Fork node is replicated into multiple parallel tasks that
7 % must later be synchronized using a corresponding Join node.
8 %
9 % @brief Job splitting node that creates parallel sibling tasks from incoming jobs
10 %
11 % Key characteristics:
12 % - Splits each job into multiple parallel tasks
13 % - Works in conjunction with Join nodes for synchronization
14 % - Supports different fork strategies and task distributions
15 % - Essential for modeling parallel processing systems
16 % - No service delay - instantaneous job splitting
17 %
18 % Fork nodes are commonly used for:
19 % - Parallel processing models
20 % - Fork-join queueing networks
21 % - Multi-threaded system modeling
22 % - Task decomposition scenarios
23 % - Distributed computing models
24 %
25 % Example:
26 % @code
27 % fork = Fork(model, 'TaskSplitter');
28 % % Jobs entering this fork will be split into parallel tasks
29 % % Must be paired with a Join node for proper synchronization
30 % @endcode
31 %
32 % Copyright (c) 2012-2026, Imperial College London
33 % All rights reserved.
34
35 properties
36 schedStrategy;
37 cap;
38 end
39
40 properties (Hidden)
41 % state-carrying slots used only on FJ tag-augmented model copies
42 % (ModelAdapter.fjtag), where the Fork is treated as a stateful
43 % node holding the parent job for one vanishing state; they mirror
44 % the StatefulNode API without changing the class ancestry
45 state = [];
46 statePrior = [];
47 space = {};
48 end
49
50 methods(Hidden)
51 function prior = getStatePrior(self)
52 % PRIOR = GETSTATEPRIOR()
53 prior = self.statePrior;
54 end
55
56 function self = setStatePrior(self, prior)
57 % SELF = SETSTATEPRIOR(PRIOR)
58 self.statePrior = prior(:);
59 end
60
61 function self = setState(self, state)
62 % SELF = SETSTATE(STATE)
63 self.state = state;
64 end
65
66 function state = getState(self)
67 % STATE = GETSTATE()
68 state = self.state;
69 end
70
71 function state = getStateSpace(self)
72 % STATE = GETSTATESPACE()
73 state = self.space;
74 end
75
76 function self = setStateSpace(self, space)
77 % SELF = SETSTATESPACE(SPACE)
78 self.space = space;
79 end
80
81 function self = resetStateSpace(self)
82 % SELF = RESETSTATESPACE()
83 self.space = {};
84 end
85 end
86
87 methods
88 %Constructor
89 function self = Fork(model, name)
90 % FORK Create a Fork node instance
91 %
92 % @brief Creates a Fork node for splitting jobs into parallel tasks
93 % @param model Network model to add the fork to
94 % @param name String identifier for the fork node
95 % @return self Fork instance configured for the given model
96 %
97 % The constructor initializes the Fork node with appropriate buffers,
98 % service tunnels, and forker output components. Fork nodes have no
99 % service delay and immediately split incoming jobs into parallel tasks.
100
101 self@Node(name);
102 if model.isMatlabNative()
103 if(model ~= 0)
104 classes = model.getClasses();
105 self.cap = Inf;
106 self.input = Buffer(classes);
107 self.schedStrategy = SchedStrategy.FORK;
108 self.server = ServiceTunnel();
109 self.output = Forker(classes);
110 self.setModel(model);
111 model.addNode(self);
112 end
113 elseif model.isJavaNative()
114 self.setModel(model);
115 self.obj = jline.lang.nodes.Fork(model.obj, name);
116 self.index = model.obj.getNodeIndex(self.obj);
117 end
118 end
119
120 function setTasksPerLink(self, nTasks)
121 % SETTASKSPERLINK Configure number of tasks per output link
122 %
123 % Sets the number of tasks sent out on each outgoing link. By default,
124 % a Fork node sends exactly one task per outgoing link. This method
125 % allows configuring the Fork to send multiple identical tasks on each
126 % link. The total number of tasks created will be:
127 % (number of outgoing links) × tasksPerLink.
128 %
129 % Solver compatibility for tasksPerLink > 1:
130 % - SolverJMT: Fully supported - simulation handles multiple tasks correctly
131 % - SolverLDES: Fully supported - simulation handles multiple tasks correctly
132 % - SolverMVA (H-T method): Not supported - throws error
133 % - SolverMVA (MMT method): Supported - analytical approximation
134 %
135 % @param nTasks Number of tasks per link (default: 1)
136
137 if nTasks ~= 1
138 line_warning(mfilename, 'The setTasksPerLink feature is experimental and results may be inaccurate for analytical solvers.');
139 end
140 self.output.tasksPerLink = nTasks;
141 end
142
143 function summary(self)
144 % SUMMARY Display fork node configuration summary
145 %
146 % @brief Prints a summary of the fork node's routing configuration
147
148 line_printf('\nNode: <strong>%s</strong>',self.getName);
149 for r=1:length(self.output.outputStrategy)
150 classes = self.model.getClasses();
151 line_printf('Routing %s: %s',classes{r}.name,self.output.outputStrategy{r}{2});
152 end
153 end
154 end
155
156end
Definition fjtag.m:157
Definition Station.m:245