Borrar filtros
Borrar filtros

Allocation algorithm by "if-else structure"?

3 visualizaciones (últimos 30 días)
linhtuptit
linhtuptit el 21 de Feb. de 2017
Editada: Walter Roberson el 21 de Feb. de 2017
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Feb. de 2017
Editada: Walter Roberson el 21 de Feb. de 2017
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

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by