In this program, I want to update an array of task_table(M) dynamically, i.e. I search the whole min_dist array exhaustively and if min_dist_p(n,k) is the minimum among min_dist(n,k,p), of which I do not know the value, I increment task_table(p) by one. Specifically, because I don’t know the value of a(n,k,p) before optimization, I want to increment it as a cvx object. However, I get this error when I write “task_table(last_node) = task_table(last_node) + a(n,k,p);”:
Incorrect number or types of inputs
or outputs for function sign.
Error in brute_force (line 124)
a(n,k,p) = ~sign(min_dist(n,k,p) - min_dist_p(n,k));
Do you know another way to write this program? Thanks….
cvx_begin
% --- Recursive Helper (Propagation Logic) ---
function path_data = build_propagation_paths(n, dist_matrix, task_table, r_max, L, M, depth, acc_dist, prev_uav, current_seq)
%if
expr = (depth > 1 && task_table(prev_uav) < r_max)
node.total_dist = acc_dist * ~expr;
node.last_uav = prev_uav * ~expr;
node.sequence = current_seq * ~expr;
if ~expr
path_data = node;
return;
end
%end
if depth > L
node.total_dist = acc_dist;
node.last_uav = prev_uav;
node.sequence = current_seq;
path_data = node;
return;
end
path_data = [];
for uav_idx = 1:M
if uav_idx == prev_uav, continue; end
step_dist = dist_matrix(prev_uav, uav_idx);
child_paths = build_propagation_paths(n, dist_matrix, task_table, r_max, L, M, ...
depth + 1, acc_dist + step_dist, ...
uav_idx, [current_seq, uav_idx]);
path_data = [path_data, child_paths];
end
end
cvx_begin
variable alpha_switch(M,N,K)
variable node_val
variable beta_switch(N,M,M)
clear rate_raw_first
variable min_dist_p(N,num_tasks)
variable index_min(N,num_tasks)
variable task_table(M)
expression a(N, num_tasks)
total_sum_time_n = 0.0;
for n=1:N
for i = 1:M
for j = 1:M
[trans_time rate]= transfer_time(M, n, i, j, sigma_squ, rho_0, P, H, Q, w, D);
dist_matrix(n,i,j) = trans_time * GREAT_NUMBER * (1 - beta_switch(n,i,j));
trans_time_x_x(n,i,j) = trans_time;
end
end
end
for n=1:N
trans_x_time = squeeze(trans_time_x_x(n,:,:));
for k = 1:num_tasks
% 2. Discovery: Enumerate valid propagation paths
paths = build_propagation_paths(n, squeeze(dist_matrix(n,:,:)), task_table, r_max, L, M, 1, 0, 1, 1);
total_sum_time = 0.0;
first_uav = 1;
r_max = 1;
f=1e+9;
C = 1e+7;
num_paths(n,k) = length(paths);
% clear min_dist
% variable min_dist(N,num_tasks,num_paths)
D_travel = [];
last_node = 0;
for p = 1:num_paths(n,k)
min_dist(n,k,p) = paths(p).total_dist;
min_sequence = paths(p).sequence;
last_node = min_sequence(end);
task_table(last_node) = task_table(last_node) + a(n,k,p);
end
total_sum_time = total_sum_time + min_dist_p(n,k);
end
total_sum_time_n = total_sum_time_n + total_sum_time;
end
minimize( total_sum_time_n)
subject to
for n=1:N
for k = 1:num_tasks
for p = 1:num_paths
min_dist(n,k,p) - min_dist_p(n,k) >= 0
a(n,k,p) = ~sign(min_dist(n,k,p) - min_dist_p(n,k));
end
end
end
for n=1:N
%total_beta = 0.0;
for i=1:M
sum(transpose(squeeze(beta_switch(n,i,:)))) <= 1;
%total_beta = total_beta + transpose(squeeze(beta_switch(n,i,:)));
for j=1:M
0<= beta_switch(n,i,j)<=1;
end
end
%total_beta <= 1;
end
cvx_end