Skip to content

Commit f05220d

Browse files
author
bbriscoe
committed
Incremented t along a range, not incremental addition
1 parent fcdb3c7 commit f05220d

1 file changed

Lines changed: 61 additions & 36 deletions

File tree

papers/working/blameshift_unresp.m

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
# with implicit denominators lambdas, betas & phis, resp.
3434
# (except after setup, when beta is cast to double and downscaled),
3535
lambdas = 16; # no. of divisions of capacity share, lambda, if lambdaSum=1
36-
betas = 400; # no. of divisions of normalized burst delay, beta, if betaSum=1
37-
phis = 8; # no. of divisions of phase shift, phi, in 360deg
36+
betas = 32; # no. of divisions of normalized burst delay, beta, if betaSum=1
37+
phis = 4; # no. of divisions of phase shift, phi, in 360deg
3838
smidgen = 0.123456789; # To avoid unrealistic degree of exact phase lock
3939

4040

4141
# set qt_mode to true(1) to produce one time series of the queue
4242
# set qt_mode to false(1) to scan parameter space and produce marking statistics
4343
qt_mode = false(1);
4444
if (qt_mode)
45-
i_lambda = 1; # index of lambda to plot if in qt_mode
46-
i_beta = 2; # index of beta to plot if in qt_mode
45+
i_lambda = 2; # index of lambda to plot if in qt_mode
46+
i_beta = 6; # index of beta to plot if in qt_mode
4747
i_phi = 1; # index of phi to plot if in qt_mode
4848
endif
4949

@@ -193,7 +193,7 @@
193193
# t : current time
194194
# i_head : which flow is at the head of the queue
195195
# t_burst[2] : start time of next burst from each flow
196-
# i_next_burst : which burst is next
196+
# i_bnxt : which burst is next
197197

198198
# Time is scanned in two passes:
199199
# 1) to find where the q will be shortest
@@ -238,26 +238,37 @@
238238
# Whether q=0 at the start or end of the min phase shift from freq to rare
239239
# depends on whether the freq burst is large enough to keep the queue
240240
# busy over t_delta_min.
241-
# In each case, i_next_burst and i_head are pointed to the flow that
241+
# In each case, i_bnxt and i_head are pointed to the flow that
242242
# bursts at the origin and the time until the next burst for each flow,
243243
# t_burst[2], is set.
244244
if (t_delta_min4 < t_delta_min5)
245+
## ToDo: Try using ranges
245246
# q=0 at freq burst before min phase shift
246-
t_burst(i_freq) = 0;
247-
t_burst(i_rare) = t_delta(1,i_4);
248-
if (t_burst(i_rare) <= 0) # <= for robustness
249-
[~, i_head] = min(beta(:,j));
250-
else
247+
t_burst{i_freq} = 0 : ti(i,j,i_freq) : t_max(i,j);
248+
t_burst{i_rare} = t_delta(1,i_4) : ti(i,j,i_rare) : t_max(i,j) ...
249+
+ t_delta(1,i_4); # Past t_max to prevent overflow
250+
## t_burst(i_freq) = 0;
251+
## t_burst(i_rare) = t_delta(1,i_4);
252+
if (t_burst{i_rare}(1) > 0)
251253
i_head = i_freq;
254+
else
255+
# Tie-break if initial bursts coincide
256+
[~, i_head] = min(beta(:,j));
252257
endif
253-
i_next_burst = i_head;
254258
else
259+
## ToDo: Try using ranges
255260
# q=0 at rare burst after min phase shift
256-
t_burst(i_rare) = 0;
257-
t_burst(i_freq) = ti(i,j,i_freq) - t_delta(1,i_5); # >= 0
258-
i_next_burst = i_head = i_rare;
261+
t_burst{i_rare} = 0 : ti(i,j,i_rare) : t_max(i,j);
262+
t_burst{i_freq} = ti(i,j,i_freq) - t_delta(1,i_5) ... # >= 0
263+
: ti(i,j,i_freq) : t_max(i,j) ...
264+
+ ti(i,j,i_freq) - t_delta(1,i_5); # Past t_max to prevent overflow
265+
## t_burst(i_rare) = 0;
266+
## t_burst(i_freq) = ti(i,j,i_freq) - t_delta(1,i_5); # >= 0
267+
i_head = i_rare;
259268
endif
260-
t_next_burst = 0;
269+
i_bnxt = i_head;
270+
i_tb = ones(2,1);
271+
## t_next_burst = 0;
261272

262273
# #2 time scan
263274
t = 0;
@@ -271,7 +282,6 @@
271282
# * qt_out(:,4) : which flow is at the head of the q; 0:1 means q(1:2);
272283
# * qt_out(:,5) : whether queue is above threshold (q>=1) after t.
273284
while (t < t_max(i,j))
274-
275285
# The contributions from each flow to the queue are piecewise linear
276286
# between 'events', where an 'event' is a discontinuity in one of the
277287
# contributions or when the queue crosses the marking threshold
@@ -281,8 +291,8 @@
281291
# Check whether combined q falls below threshold
282292
# before head q empties or burst arrives
283293
if ( (ott) && ...
284-
( ((t_next_empty <= t_next_burst) && (q_xs <= q(i_head))) || ...
285-
((t_next_empty > t_next_burst) && (q_xs <= t_next_burst - t)) ...
294+
( ((t_next_empty <= t_burst{i_bnxt}(i_tb(i_bnxt))) && (q_xs <= q(i_head))) || ...
295+
((t_next_empty > t_burst{i_bnxt}(i_tb(i_bnxt))) && (q_xs <= t_burst{i_bnxt}(i_tb(i_bnxt)) - t)) ...
286296
) ...
287297
)
288298
# Combined queue has fallen below threshold before any other event
@@ -292,7 +302,7 @@
292302
q(i_head) -= q_xs;
293303
qt_mode && (qt_out(++i_event,:) = [t, q(1), q(2), i_head-1, ott]);
294304
ott = 0;
295-
# The earlier condition (q_xs <= t_next_burst - t) could have been
305+
# The earlier condition (q_xs <= t_burst{i_bnxt}(i_tb(i_bnxt)) - t) could have been
296306
# changed to < to suppress the following qt_out in the case when it
297307
# seems redundant when q drains exactly to the threshold just
298308
# before a burst. But, for robustness, if (q==1) ott=0, even if q
@@ -309,7 +319,7 @@
309319
endif
310320
endif
311321
else
312-
if ((q(i_head) > 0) && (t_next_empty <= t_next_burst))
322+
if ((q(i_head) > 0) && (t_next_empty <= t_burst{i_bnxt}(i_tb(i_bnxt))))
313323
# q(i_head) has emptied (defer any simultaneous burst to next event)
314324
t = t_next_empty;
315325
if (ott)
@@ -326,52 +336,67 @@
326336
# No need to update i_other - not read elsewhere
327337
else
328338
# Both q's empty
329-
i_head = i_next_burst;
339+
i_head = i_bnxt;
330340
endif
331341
qt_mode && (qt_out(++i_event,:) = [t, q(1), q(2), i_head-1, ott]);
332342
else
333343
# Burst has arrived
334344
if (q(i_head) > 0)
335345
# Drain head queue since last event
336-
q(i_head) -= t_next_burst - t; # resulting q(i_head) will be >0
346+
q(i_head) -= t_burst{i_bnxt}(i_tb(i_bnxt)) - t; # resulting q(i_head) will be >0
337347
if (ott)
338348
# Add to p_e
339-
p(k, i_head, 2) += t_next_burst - t;
349+
p(k, i_head, 2) += t_burst{i_bnxt}(i_tb(i_bnxt)) - t;
340350
endif
341351
q_xs = sum(q) - 1;
342352
endif
343-
t = t_next_burst;
353+
t = t_burst{i_bnxt}(i_tb(i_bnxt));
344354
qt_mode && (qt_out(++i_event,:) = [t, q(1), q(2), i_head-1, ott]);
345355
## ToDo: more elegantly, increment t to pre-determined matrix
346-
if (t >= t_max(i,j) - 8*eps(t_max(1,j)))
356+
## if (i_tb(i_bnxt) >= size(t_burst{i_bnxt},2))
357+
# The precision of t is 1 eps 'cos it is assigned from a range.
358+
# However, an octave bug loses another eps when within a script
359+
# The alternative of testing for the end of the vector led to very
360+
# complex code
361+
if (t >= t_max(i,j) - 2*eps(t))
362+
## if (t >= t_max(i,j) - 8*eps(t_max(1,j)))
347363
break
348364
endif
349365
# Add burst to tail
350366
# but first check whether combined queue rises above threshold
351-
delta_q = beta(i_next_burst,j);
352-
if ( (ott == 0) && (q_xs + beta(i_next_burst,j) > 0) )
367+
delta_q = beta(i_bnxt,j);
368+
if ( (ott == 0) && (q_xs + beta(i_bnxt,j) > 0) )
353369
# Take care! if (q_xs + beta == tiny), e.g tiny = 1.1102e-16
354370
# after q incremented as below, q_xs = (sum(q) - 1) == 0;
355-
q(i_next_burst) -= q_xs;
371+
q(i_bnxt) -= q_xs;
356372
delta_q += q_xs;
357373
qt_mode && (qt_out(++i_event,:) = [t, q(1), q(2), i_head-1, ott]);
358374
ott = 1;
359375
endif
360-
q(i_next_burst) += delta_q;
376+
q(i_bnxt) += delta_q;
361377
if (ott)
362378
# Add to p_s
363-
p(k, i_next_burst, 1) += delta_q;
379+
p(k, i_bnxt, 1) += delta_q;
364380
endif
365381
qt_mode && (qt_out(++i_event,:) = [t, q(1), q(2), i_head-1, ott]);
366382
# Prepare for next burst
367383
# Set t_burst for next burst from this flow
368384
## ToDo: increment a pointer along a range for precision
369-
t_burst(i_next_burst) += ti(i,j,i_next_burst);
385+
## if (i_tb(i_bnxt) >= size(t_burst{i_bnxt},2))
386+
# Earlier size test prevents overflow here
387+
## # Reached end of one flow's bursts without reaching t_max
388+
## # Force the next burst index to point to the other flow
389+
## i_bnxt = !(i_bnxt-1) + 1;
390+
## else
391+
i_tb(i_bnxt)++;
392+
## t_burst(i_bnxt) += ti(i,j,i_bnxt);
370393
# Calc arrival time and flow id of next burst, handling tie if nec.
371-
[t_next_burst, i_next_burst] = min(t_burst);
372-
if (t_burst(1) == t_burst(2))
373-
[~, i_next_burst] = min(beta(:,j));
394+
[~, i_bnxt] = min([t_burst{1}(i_tb(1)), t_burst{2}(i_tb(2))]);
395+
## [t_next_burst, i_bnxt] = min(t_burst);
396+
if (t_burst{1}(i_tb(1)) == t_burst{2}(i_tb(2)))
397+
[~, i_bnxt] = min(beta(:,j));
374398
endif
399+
## endif
375400
endif
376401
endif
377402
endwhile
@@ -465,7 +490,7 @@
465490
## i_rare
466491
## i_head
467492
## i_other
468-
## i_next_burst
493+
## i_bnxt
469494
##
470495
## # Time intervals
471496
## t

0 commit comments

Comments
 (0)