MATLAB: Allocation algorithm by “if-else structure”

I am building an algorithm wherein some servers is setup for serving many users. The algorithm is programmed to control the assignment of server to serve incoming users. During start-up, all servers are available. When the first user arrives, the algorithm assigns the first server to serve him, and then labels that this server as being busy. When busy, this server becomes unavailable for the constant time (t). When subsequent user arrive, the algorithm steps through the status of each server and assigns the first one that is not busy. However, in some cases, users that arrive when all server are currently busy do not get served. I have tried to use "if-else structure" but it isn't a good choice to illustrate this algorithm. Please help me other ways to implement it. Many thank for all.

Best Answer

num_servo = 5;
servo_hold_time = 8;
timestep = 0;
servo_busy = zeros(1, num_servo);
while true
timestep = timestep + 1;
mask = servo_busy > 0;
servo_busy(mask) = servo_busy(mask) - 1;
if user_request()
servo_to_use = find(servo_busy == 0, 1, 'first');
if isempty(servo_to_use)
fprintf('Tough luck, request dropped\n');
else
servo_busy(servo_to_use) = servo_hold_time;
end
end
biz = sum(servo_busy > 0);
fprintf('%d servers busy\n', biz);
sleep(1);
end