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, ~, ~)
isAllowed = obj.mCurrentOccupancy <= obj.mCurrentCapacity;
end
function events = entry(obj, storage, ~, ~)
obj.mCurrentOccupancy = obj.mCurrentOccupancy + 1;
events = obj.eventForward('output', 1, obj.mServiceTime);
end
function events = exit(obj, ~, ~, ~)
obj.mCurrentOccupancy = obj.mCurrentOccupancy - 1;
if(obj.mCurrentOccupancy < obj.mCurrentCapacity)
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, ~, ~)
if storage == 1
obj.mCurrentOccupancy = obj.mCurrentOccupancy + 1;
events = obj.eventForward('output', 1, obj.mServiceTime);
elseif storage == 2
obj.mCurrentCapacity = entity.data;
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
Best Answer