Simevents: change the server capacity during simulation
3 次查看(过去 30 天)
显示 更早的评论
I know that server capacity and initial resource amount can not be changed during simulation (the question has been asked before here and here, where someguidelines and solutions can be found). I recently started using MATLAB discrete-event system and I realized that those parameters are defined as nontunable parameters and as they name suggest, they cannot change during simulation. However, I noticed that parameters can also be defined as tunable. My question is thath can we define server capacity or initial resource amount as tunable parameters to change them dynamically during simultion or further for optimization purposes? Thanks.
0 个评论
采纳的回答
Krishna Akella
2019-6-25
Hi Kar,
You are correct, Entity Server does not allow for changing the capacity at run-time. Resource Pool block allows changing the resource amount at run-time through a signal port, but it only allows incrementing the available resources in the pool. And not the other way around.
For the variable capacity server, you can try using a MATLAB discrete-event system block and try including a queue of infinite capacity. You can then control whether to allow or disallow an entity from entering the queue by implementing the testEntry method. That way you can control the capacity at run-time. For example you can do something like the following:
function isAllowed = testEntry(obj, storage, ~, ~)
% Specifies whether entities are allowed into the storage
isAllowed = obj.mCurrentOccupancy <= obj.mCurrentCapacity;
end
function events = entry(obj, storage, ~, ~)
% Increment the current occupancy
obj.mCurrentOccupancy = obj.mCurrentOccupancy + 1;
% Post a forward event after service-time
events = obj.eventForward('output', 1, obj.mServiceTime);
end
function events = exit(obj, ~, ~, ~)
% Decrement the current occupancy
obj.mCurrentOccupancy = obj.mCurrentOccupancy - 1;
if(obj.mCurrentOccupancy < obj.mCurrentCapacity)
% Since there is room for entities, check if any entity
% wishes to enter the block.
events = [events obj.eventTestEntry(1)];
end
end
In the above example, you can define mCurrentCapacity as a tunable parameter (not recommended). If the capacity decreases, then the new capacity would kick in only after the delta amount of entities would have left the block. You can have a more complex policy based on your particular use-case.
One caveat with the above piece of code is that, when the capacity of the server changes (increases), we need to test for entry (by posting a testEntry event), as there might be entities that were previously blocked out. But there is no way to do that since, we cannot associate an event when a tunable parameter changes. The best way would be to increment the server capacity by using another entity port. This other port would accept an entity that specifies the new capacity. This would enable us to return a testEntry event from the entry method.
function events = entry(obj, storage, ~, ~)
% Increment the current occupancy
if storage == 1
% Book-keeping
obj.mCurrentOccupancy = obj.mCurrentOccupancy + 1;
% Post a forward event after service-time
events = obj.eventForward('output', 1, obj.mServiceTime);
elseif storage == 2
obj.mCurrentCapacity = entity.data; % Assuming anonymous entity
% Omitting checks for brevity
events = [events obj.eventTestEntry(1)];
end
end
An alternative to using DES block would be to use an infinite capacity server and use an entity gate to control the number of entities entering the server. The gate could be operated by adding some logic which would be driven by the statistics ports of the Entity Server.
Hope this helps!
- Krishna
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete-Event Simulation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!