% congctrl(t, x, options, N, bmax, c)
% RMM, 11 Jul 06
%
% Congestion control dynamics
%
% This model implements the congestion control dynamics described in
% the text. We assume that we have N identical sources and 1 router.
%
% To allow the model to be used in a variety of ways, we
% allow the number of states and the number of sources to be set
% independently. The length of the state vector, M+1, is used to determine
% the number of simulated sources, with each source representing N/M
% sources.
function dx = congctrl(t, x, options, N, rho, c)
% Figure out how many
M = length(x) - 1;
if (nargin < 4) N = M; end;
if (nargin < 5) rho = 2e-4; end;
if (nargin < 6) c = 10; end;
dx = zeros(M+1, 1);
% Loop over equations
for i = [1:M]
dx(i) = c / x(M+1) - (rho * c) * (1 + (x(i)^2) / 2);
% Sum up contributions to bdot on each interation
dx(M+1) = dx(M+1) + N/M * (x(i) * c / x(M+1)) - c/M;
end