Hello. Can everyone please help me to solve the problem with my code. When I tried to add parameters to my block, but when I run the code I get this error:
Error using test_3 (line 139)
EntityGenerator block does not have a parameter named 'InterarrivalTime'
clear all;close all;clc;
% Initialize the parameters
n = 300; % total number of elements
p9 = randi([5, 10])/100; % probability of 9
p6_8 = randi([10, 20])/100; % probability of 6 to 8
p3_5 = randi([35, 60])/100; % probability of 3 to 5
p1_2 = randi([40, 50])/100; % probability of 1 to 2
% Generate a random vector with the given probabilities
x = randsample(1:9, n, true, [p1_2/2 p1_2/2 p3_5/3 p3_5/3 p3_5/3 p6_8/3 p6_8/3 p6_8/3 p9]);
% Display the results
disp(x); % show the vector
disp(sum(x)); % show the sum
disp(histcounts(x)/n); % show the frequencies
% Customers Arrival Time
% The peak time starts from 6pm to 9pm. So we will have 180 minutes.
customer_arrival_times=randi(180,[1 300]);
customer_booking_time=randi(300,[1 300]);
customer_booked_time=randi(180, [1 300]);
% Classify the customers into three groups
two_seats = x == 1 | x == 2; % customers with 1 or 2 people
five_seats = x >= 3 & x <= 5; % customers with 3 to 5 people
ten_seats = x >= 6 & x <= 9; % customers with 6 to 9 people
% Initialize the number of available tables for each type
two_seats_table = 30;
five_seats_table = 30;
ten_seats_table = 10;
% Initialize an empty vector to store the table type for each customer
table_type = zeros(1, n);
% Use a loop to assign a table type to each customer
for i = 1:n
% Check the group of the customer
if two_seats(i)
% Check if there is any available two-seats table
if two_seats_table > 0
% Assign a two-seats table to the customer
table_type(i) = 2;
% Decrease the number of available two-seats table by one
two_seats_table = two_seats_table - 1;
else
% No available two-seats table, assign a five-seats table instead
table_type(i) = 5;
% Decrease the number of available five-seats table by one
five_seats_table = five_seats_table - 1;
end
elseif five_seats(i)
% Check if there is any available five-seats table
if five_seats_table > 0
% Assign a five-seats table to the customer
table_type(i) = 5;
% Decrease the number of available five-seats table by one
five_seats_table = five_seats_table - 1;
else
% No available five-seats table, assign a ten-seats table instead
table_type(i) = 10;
% Decrease the number of available ten-seats table by one
ten_seats_table = ten_seats_table - 1;
end
elseif ten_seats(i)
% Check if there is any available ten-seats table
if ten_seats_table > 0
% Assign a ten-seats table to the customer
table_type(i) = 10;
% Decrease the number of available ten-seats table by one
ten_seats_table = ten_seats_table - 1;
else
% No available ten-seats table, cannot serve the customer
table_type(i) = NaN;
end
end
end
% Display the assigned table type for each customer
disp(table_type);
% Sort the customers by their booking time in ascending order
[sorted_booking_time, sorted_index] = sort(customer_booking_time);
% Sort the other variables according to the sorted index
sorted_x = x(sorted_index);
sorted_arrival_time = customer_arrival_times(sorted_index);
sorted_booked_time = customer_booked_time(sorted_index);
sorted_table_type = table_type(sorted_index);
% Use a loop to rearrange the customers within each group according to their group size in descending order
% Initialize an empty vector to store the rearranged index
rearranged_index = [];
% Initialize a variable to store the current group start index
group_start = 1;
% Use a loop to iterate through the sorted customers
for i = 1:n
% Check if it is the last customer or if the next customer has a different booking time than the current one
if i == n || sorted_booking_time(i+1) ~= sorted_booking_time(i)
% It is the end of a group, sort the customers within the group by their group size in descending order
[sorted_group_size, sorted_group_index] = sort(sorted_x(group_start:i), 'descend');
% Append the sorted group index to the rearranged index
rearranged_index = [rearranged_index sorted_index(group_start:i) (sorted_group_index)];
% Update the group start index to the next customer
group_start = i + 1;
end
end
% Sort the variables according to the rearranged index
rearranged_x = x(rearranged_index);
rearranged_arrival_time = customer_arrival_times(rearranged_index);
rearranged_booked_time = customer_booked_time(rearranged_index);
rearranged_table_type = table_type(rearranged_index);
% Create a discrete-event model
model = 'QueuingSystem';
open_system(new_system(model));
% Add an entity generator block for each table type
two_seats_generator = [model '/Two-Seats Generator'];
add_block('built-in/EntityGenerator', two_seats_generator); % use built-in instead of simeventslib
five_seats_generator = [model '/Five-Seats Generator'];
add_block('built-in/EntityGenerator', five_seats_generator); % use built-in instead of simeventslib
ten_seats_generator = [model '/Ten-Seats Generator'];
add_block('built-in/EntityGenerator', ten_seats_generator); % use built-in instead of simeventslib
% Set the parameters of the entity generator blocks
% set_param('model/Entity Generator','InterarrivalTime','exprnd(5)')
set_param(two_seats_generator, 'InterarrivalTime', 'rearranged_arrival_time(rearranged_table_type == 2)');
set_param(two_seats_generator, 'EntitiesPerInterval', '1');
set_param(two_seats_generator, 'EntityGeneration', 'Limited number of entities');
set_param(two_seats_generator, 'TotalEntities', 'sum(rearranged_table_type == 2)');
set_param(two_seats_generator, 'EntityType', 'Customer');
set_param(two_seats_generator, 'AttributeNames', 'BookedTime');
set_param(two_seats_generator, 'AttributeTypes', 'double');
set_param(two_seats_generator, 'AttributeInitialValues', 'rearranged_booked_time(rearranged_table_type == 2)');
set_param(five_seats_generator, 'InterarrivalTime', 'rearranged_arrival_time(rearranged_table_type == 5)');
set_param(five_seats_generator, 'EntitiesPerInterval', '1');
set_param(five_seats_generator, 'EntityGeneration', 'Limited number of entities');
set_param(five_seats_generator, 'TotalEntities', 'sum(rearranged_table_type == 5)');
set_param(five_seats_generator, 'EntityType', 'Customer');
set_param(five_seats_generator, 'AttributeNames', 'BookedTime');
set_param(five_seats_generator, 'AttributeTypes', 'double');
set_param(five_seats_generator, 'AttributeInitialValues', 'rearranged_booked_time(rearranged_table_type == 5)');
set_param(ten_seats_generator, 'InterarrivalTime', 'rearranged_arrival_time(rearranged_table_type == 10)');
set_param(ten_seats_generator, 'EntitiesPerInterval', '1');
set_param(ten_seats_generator, 'EntityGeneration', 'Limited number of entities');
set_param(ten_seats_generator, 'TotalEntities', 'sum(rearranged_table_type == 10)');
set_param(ten_seats_generator, 'EntityType', 'Customer');
set_param(ten_seats_generator, 'AttributeNames', 'BookedTime');
set_param(ten_seats_generator, 'AttributeTypes', 'double');
set_param(ten_seats_generator, 'AttributeInitialValues', 'rearranged_booked_time(rearranged_table_type == 10)');
% Add a queue block for each table type
two_seats_queue = [model '/Two-Seats Queue'];
add_block('built-in/Queue', two_seats_queue); % use built-in instead of simeventslib
five_seats_queue = [model '/Five-Seats Queue'];
add_block('built-in/Queue', five_seats_queue); % use built-in instead of simeventslib
ten_seats_queue = [model '/Ten-Seats Queue'];
add_block('built-in/Queue', ten_seats_queue); % use built-in instead of simeventslib
% Set the parameters of the queue blocks
set_param(two_seats_queue, ...
'QueueName', 'Two-Seats Queue', ...
'Capacity', 'inf', ...
'QueueingStrategy', 'FIFO', ...
'Statistics', 'on', ...
'OutputStatistics', 'Waiting time in queue');
set_param(five_seats_queue, ...
'QueueName', 'Five-Seats Queue', ...
'Capacity', 'inf', ...
'QueueingStrategy', 'FIFO', ...
'Statistics', 'on', ...
'OutputStatistics', 'Waiting time in queue');
set_param(ten_seats_queue, ...
'QueueName', 'Ten-Seats Queue', ...
'Capacity', 'inf', ...
'QueueingStrategy', 'FIFO', ...
'Statistics', 'on', ...
'OutputStatistics', 'Waiting time in queue');
% Add a server block for each table type
two_seats_server = [model '/Two-Seats Server'];
add_block('built-in/Server', two_seats_server); % use built-in instead of simeventslib
five_seats_server = [model '/Five-Seats Server'];
add_block('built-in/Server', five_seats_server); % use built-in instead of simeventslib
ten_seats_server = [model '/Ten-Seats Server'];
add_block('built-in/Server', ten_seats_server); % use built-in instead of simeventslib
% Set the parameters of the server blocks
set_param(two_seats_server, ...
'ServiceTime', '#BookedTime * 60'); % convert minutes to seconds
set_param(five_seats_server, ...
'ServiceTime', '#BookedTime * 60'); % convert minutes to seconds
set_param(ten_seats_server, ...
'ServiceTime', '#BookedTime * 60'); % convert minutes to seconds
% Add an entity terminator block for each table type
two_seats_terminator = [model '/Two-Seats Terminator'];
add_block('built-in/Terminator (SimEvents)', two_seats_terminator); % use built-in instead of simeventslib
five_seats_terminator = [model '/Five-Seats Terminator'];
add_block('built-in/Terminator (SimEvents)', five_seats_terminator); % use built-in instead of simeventslib
ten_seats_terminator = [model '/Ten-Seats Terminator'];
add_block('built-in/Terminator (SimEvents)', ten_seats_terminator); % use built-in instead of simeventslib
% Connect the blocks
add_line(model, [two_seats_generator '/1'], [two_seats_queue '/1']);
add_line(model, [two_seats_queue '/1'], [two_seats_server '/1']);
add_line(model, [two_seats_server '/1'], [two_seats_terminator '/1']);
add_line(model, [five_seats_generator '/1'], [five_seats_queue '/1']);
add_line(model, [five_seats_queue '/1'], [five_seats_server '/1']);
add_line(model, [five_seats_server '/1'], [five_seats_terminator '/1']);
add_line(model, [ten_seats_generator '/1'], [ten_seats_queue '/1']);
add_line(model, [ten_seats_queue '/1'], [ten_seats_server '/1']);
add_line(model, [ten_seats_server '/1'], [ten_seats_terminator '/1']);
% Add scopes to display the results
waiting_time_scope = [model '/Waiting Time Scope'];
add_block('simulink/Commonly Used Blocks/Scope', waiting_time_scope);
server_utilization_scope = [model '/Server Utilization Scope'];
add_block('simulink/Commonly Used Blocks/Scope', server_utilization_scope);
% Connect the scopes to the queue and server blocks
add_line(model, [two_seats_queue '/2'], [waiting_time_scope '/1']);
add_line(model, [five_seats_queue '/2'], [waiting_time_scope '/2']);
add_line(model, [ten_seats_queue '/2'], [waiting_time_scope '/3']);
add_line(model, [two_seats_server '/2'], [server_utilization_scope '/1']);
add_line(model, [five_seats_server '/2'], [server_utilization_scope '/2']);
add_line(model, [ten_seats_server '/2'], [server_utilization_scope '/3']);
% Save and run the model
save_system(model);
sim(model);
% Display the scope windows
open_system([model '/' waiting_time_scope]);
open_system([model '/' server_utilization_scope]);