Unable to perform assignment because value of type ‘optim.problemdef.OptimizationExpression’ is not convertible to ‘double’.
Hello!
I’m working on an optimization problem where I need to manage the availability of multiple cores for task execution. My current approach involves finding the earliest available core and updating its availability after assigning a task. However, I’m encountering an issue when trying to update the hapsCoreAvailability array with the new start time and execution time.
the error is
Unable to perform assignment because value of type ‘optim.problemdef.OptimizationExpression’ is not convertible to
‘double’.
Error in Solve_Linear_Problem (line 355)
hapsCoreAvailability(coreIdx) = T_start + execTime;
Caused by:
Error using double
Conversion to double from optim.problemdef.OptimizationExpression is not possible.
here is the code
% Initialize the queue time matrix
Queue_time = optimexpr(N, numNodes, num_vehicles);
% Define variables
T_start = optimvar(‘T_start’, 1, ‘Type’, ‘continuous’, ‘LowerBound’, 0);
% Constraints
Queue_constraints1 = [];
Queue_constraints2 = [];
% Track availability of each HAPS core
hapsCoreAvailability = zeros(1, hapsCapacity);
nodeQueues = cell(numNodes, 1); % Queue times for each node
% Process tasks by generation time
for taskIdx = 1:num_vehicles
for subtaskIdx = 1:N
for nodeIdx = 1:numNodes
% Extract generation time, execution time, and uplink time
taskGenTime = generation_times_matrix(subtaskIdx, nodeIdx, taskIdx);
execTime = Execution_time(subtaskIdx, nodeIdx, taskIdx);
uplinkTime = uplink_time(subtaskIdx, nodeIdx, taskIdx);
% Calculate task arrival time considering uplink time
taskArrivalTime = taskGenTime + uplinkTime;
if nodeIdx == 4 % If assigned to HAPS
% Find the earliest available core
% [earliestCoreTime, coreIdx] = min(hapsCoreAvailability);
coreIdx = -1;
earliestCoreTime = inf;
% Iterate through each core’s availability time
for i = 1:length(hapsCoreAvailability)
% Check if the current core’s availability is earlier than the current earliest time
if hapsCoreAvailability(i) < earliestCoreTime
% Update earliest core time and index
earliestCoreTime = hapsCoreAvailability(i);
coreIdx = i;
end
end
% Start time is the maximum of arrival time and core availability
% T_start should be greater than or equal to both T_arrival and T_core
Queue_constraints1 = [Queue_constraints1, T_start >= taskArrivalTime];
Queue_constraints1 = [Queue_constraints1, T_start >= earliestCoreTime];
Queue_time(subtaskIdx, nodeIdx, taskIdx) = T_start – taskArrivalTime;
% Update the core availability time
hapsCoreAvailability(coreIdx) = T_start + execTime; %% here is the error
else % For UAVs
% Queue tasks based on previous completion
if isempty(nodeQueues{nodeIdx})
startTime = taskArrivalTime;
else
T_queue = nodeQueues{nodeIdx}(end);
% T_start should be greater than or equal to both T_arrival and T_queue
Queue_constraints2 = [Queue_constraints2, T_start >= taskArrivalTime];
Queue_constraints2 = [Queue_constraints2, T_start >= T_queue];
end
% Calculate the queue time for the current subtask
Queue_time(subtaskIdx, nodeIdx, taskIdx) = T_start – taskArrivalTime;
% Update departure time for the current subtask
departureTime = T_start + execTime;
nodeQueues{nodeIdx} = [nodeQueues{nodeIdx}, departureTime];
end
end
end
end
prob.Constraints.queue_time_constraints = Queue_constraints1;
prob.Constraints.queue_time_constraints = Queue_constraints2;
How can I correctly update the hapsCoreAvailability array with the new start time and execution time in the context of my optimization problem? Is there an alternative way to manage and update core availability when dealing with OptimizationExpression objects?
Any advice or suggestions would be greatly appreciated!
Thank you!Hello!
I’m working on an optimization problem where I need to manage the availability of multiple cores for task execution. My current approach involves finding the earliest available core and updating its availability after assigning a task. However, I’m encountering an issue when trying to update the hapsCoreAvailability array with the new start time and execution time.
the error is
Unable to perform assignment because value of type ‘optim.problemdef.OptimizationExpression’ is not convertible to
‘double’.
Error in Solve_Linear_Problem (line 355)
hapsCoreAvailability(coreIdx) = T_start + execTime;
Caused by:
Error using double
Conversion to double from optim.problemdef.OptimizationExpression is not possible.
here is the code
% Initialize the queue time matrix
Queue_time = optimexpr(N, numNodes, num_vehicles);
% Define variables
T_start = optimvar(‘T_start’, 1, ‘Type’, ‘continuous’, ‘LowerBound’, 0);
% Constraints
Queue_constraints1 = [];
Queue_constraints2 = [];
% Track availability of each HAPS core
hapsCoreAvailability = zeros(1, hapsCapacity);
nodeQueues = cell(numNodes, 1); % Queue times for each node
% Process tasks by generation time
for taskIdx = 1:num_vehicles
for subtaskIdx = 1:N
for nodeIdx = 1:numNodes
% Extract generation time, execution time, and uplink time
taskGenTime = generation_times_matrix(subtaskIdx, nodeIdx, taskIdx);
execTime = Execution_time(subtaskIdx, nodeIdx, taskIdx);
uplinkTime = uplink_time(subtaskIdx, nodeIdx, taskIdx);
% Calculate task arrival time considering uplink time
taskArrivalTime = taskGenTime + uplinkTime;
if nodeIdx == 4 % If assigned to HAPS
% Find the earliest available core
% [earliestCoreTime, coreIdx] = min(hapsCoreAvailability);
coreIdx = -1;
earliestCoreTime = inf;
% Iterate through each core’s availability time
for i = 1:length(hapsCoreAvailability)
% Check if the current core’s availability is earlier than the current earliest time
if hapsCoreAvailability(i) < earliestCoreTime
% Update earliest core time and index
earliestCoreTime = hapsCoreAvailability(i);
coreIdx = i;
end
end
% Start time is the maximum of arrival time and core availability
% T_start should be greater than or equal to both T_arrival and T_core
Queue_constraints1 = [Queue_constraints1, T_start >= taskArrivalTime];
Queue_constraints1 = [Queue_constraints1, T_start >= earliestCoreTime];
Queue_time(subtaskIdx, nodeIdx, taskIdx) = T_start – taskArrivalTime;
% Update the core availability time
hapsCoreAvailability(coreIdx) = T_start + execTime; %% here is the error
else % For UAVs
% Queue tasks based on previous completion
if isempty(nodeQueues{nodeIdx})
startTime = taskArrivalTime;
else
T_queue = nodeQueues{nodeIdx}(end);
% T_start should be greater than or equal to both T_arrival and T_queue
Queue_constraints2 = [Queue_constraints2, T_start >= taskArrivalTime];
Queue_constraints2 = [Queue_constraints2, T_start >= T_queue];
end
% Calculate the queue time for the current subtask
Queue_time(subtaskIdx, nodeIdx, taskIdx) = T_start – taskArrivalTime;
% Update departure time for the current subtask
departureTime = T_start + execTime;
nodeQueues{nodeIdx} = [nodeQueues{nodeIdx}, departureTime];
end
end
end
end
prob.Constraints.queue_time_constraints = Queue_constraints1;
prob.Constraints.queue_time_constraints = Queue_constraints2;
How can I correctly update the hapsCoreAvailability array with the new start time and execution time in the context of my optimization problem? Is there an alternative way to manage and update core availability when dealing with OptimizationExpression objects?
Any advice or suggestions would be greatly appreciated!
Thank you! Hello!
I’m working on an optimization problem where I need to manage the availability of multiple cores for task execution. My current approach involves finding the earliest available core and updating its availability after assigning a task. However, I’m encountering an issue when trying to update the hapsCoreAvailability array with the new start time and execution time.
the error is
Unable to perform assignment because value of type ‘optim.problemdef.OptimizationExpression’ is not convertible to
‘double’.
Error in Solve_Linear_Problem (line 355)
hapsCoreAvailability(coreIdx) = T_start + execTime;
Caused by:
Error using double
Conversion to double from optim.problemdef.OptimizationExpression is not possible.
here is the code
% Initialize the queue time matrix
Queue_time = optimexpr(N, numNodes, num_vehicles);
% Define variables
T_start = optimvar(‘T_start’, 1, ‘Type’, ‘continuous’, ‘LowerBound’, 0);
% Constraints
Queue_constraints1 = [];
Queue_constraints2 = [];
% Track availability of each HAPS core
hapsCoreAvailability = zeros(1, hapsCapacity);
nodeQueues = cell(numNodes, 1); % Queue times for each node
% Process tasks by generation time
for taskIdx = 1:num_vehicles
for subtaskIdx = 1:N
for nodeIdx = 1:numNodes
% Extract generation time, execution time, and uplink time
taskGenTime = generation_times_matrix(subtaskIdx, nodeIdx, taskIdx);
execTime = Execution_time(subtaskIdx, nodeIdx, taskIdx);
uplinkTime = uplink_time(subtaskIdx, nodeIdx, taskIdx);
% Calculate task arrival time considering uplink time
taskArrivalTime = taskGenTime + uplinkTime;
if nodeIdx == 4 % If assigned to HAPS
% Find the earliest available core
% [earliestCoreTime, coreIdx] = min(hapsCoreAvailability);
coreIdx = -1;
earliestCoreTime = inf;
% Iterate through each core’s availability time
for i = 1:length(hapsCoreAvailability)
% Check if the current core’s availability is earlier than the current earliest time
if hapsCoreAvailability(i) < earliestCoreTime
% Update earliest core time and index
earliestCoreTime = hapsCoreAvailability(i);
coreIdx = i;
end
end
% Start time is the maximum of arrival time and core availability
% T_start should be greater than or equal to both T_arrival and T_core
Queue_constraints1 = [Queue_constraints1, T_start >= taskArrivalTime];
Queue_constraints1 = [Queue_constraints1, T_start >= earliestCoreTime];
Queue_time(subtaskIdx, nodeIdx, taskIdx) = T_start – taskArrivalTime;
% Update the core availability time
hapsCoreAvailability(coreIdx) = T_start + execTime; %% here is the error
else % For UAVs
% Queue tasks based on previous completion
if isempty(nodeQueues{nodeIdx})
startTime = taskArrivalTime;
else
T_queue = nodeQueues{nodeIdx}(end);
% T_start should be greater than or equal to both T_arrival and T_queue
Queue_constraints2 = [Queue_constraints2, T_start >= taskArrivalTime];
Queue_constraints2 = [Queue_constraints2, T_start >= T_queue];
end
% Calculate the queue time for the current subtask
Queue_time(subtaskIdx, nodeIdx, taskIdx) = T_start – taskArrivalTime;
% Update departure time for the current subtask
departureTime = T_start + execTime;
nodeQueues{nodeIdx} = [nodeQueues{nodeIdx}, departureTime];
end
end
end
end
prob.Constraints.queue_time_constraints = Queue_constraints1;
prob.Constraints.queue_time_constraints = Queue_constraints2;
How can I correctly update the hapsCoreAvailability array with the new start time and execution time in the context of my optimization problem? Is there an alternative way to manage and update core availability when dealing with OptimizationExpression objects?
Any advice or suggestions would be greatly appreciated!
Thank you! optimization, multiple cores, parallel processing MATLAB Answers — New Questions