can someone help me regarding my code and error?
Show older comments
we have to find;
{Objective fuction:throughput maximisation in 5g networks
Constraints:using outer approximation algorithm to solve mixed integer non linear programming problem
Variables:No of users, base station, channels, macro and microcell(pico, femto, relay nodes) each of them are connected to each other. (Making a heterogeneous network)
In the output using SNR formulae for results}
here's my code containig error in line 31
% Define the problem parameters
numMacrocells = 4; % Number of macrocells
numMicrocells = 6; % Number of microcells
numBaseStations = numMacrocells + numMicrocells; % Total number of base stations
% Define the power budget and power limits
totalPowerBudget = 200; % Total power budget in watts
macrocellPowerLimit = 50; % Macrocell power limit in watts
microcellPowerLimit = 30; % Microcell power limit in watts
% Define the channels and bandwidths for each base station
channels = [12, 10, 8, 11, 13, 15, 14, 9, 7, 12]; % Channel gain for each base station
bandwidths = [20, 25, 15, 20, 15, 20, 15, 10, 25, 20]; % Bandwidth for each base station
% Define the optimization problem
problem = optimproblem('ObjectiveSense', 'maximize');
% Define the decision variables
powerAlloc = optimvar('powerAlloc', numBaseStations, 'LowerBound', 0, 'UpperBound', totalPowerBudget);
size(powerAlloc)
size(bandwidths)
size(channels)
throughput = optimvar('throughput');
% Define the objective function
problem.Objective = -throughput; % Minimize negative throughput
% Define the constraints
problem.Constraints.PowerBudget = sum(powerAlloc) <= totalPowerBudget;
problem.Constraints.MacrocellPower = powerAlloc(1:numMacrocells) <= macrocellPowerLimit;
problem.Constraints.MicrocellPower = powerAlloc(numMacrocells+1:end) <= microcellPowerLimit;
% Calculate the individual throughput values for each base station
baseStationThroughputs = channels .* log2(1 + (powerAlloc .* channels) ./ bandwidths.');
% Define the total throughput constraint
problem.Constraints.Throughput = throughput == sum(baseStationThroughputs);
% Solve the optimization problem
[solution, fval] = solve(problem);
% Extract the optimal power allocation and throughput
optimalPowerAlloc = solution.powerAlloc;
optimalThroughput = solution.throughput;
% Display the results
disp("Optimal Power Allocation:");
disp(optimalPowerAlloc);
disp("Optimal Throughput:");
disp(optimalThroughput);
Error in the code;
Error in optim.internal.problemdef.Times.getTimesOperator
Error in .*
Error in Untitled786 (line 31)
baseStationThroughputs = channels .* log2(1 + (powerAlloc .* channels) ./ bandwidths.');
Answers (2)
Adjust the sizes of the arrays involved in the calculation of "baseStationThroughputs" (see above).
Further, use "fcn2optimexpr" to define "baseStationThroughputs" - log2 makes a problem to define it directly.
It looks like you have a dimension misalignment. Create both your variables to be either row or column vectors. However, this does lead to a new error because log2 does not accept optimization variables as valid inputs.
% Define the problem parameters
numMacrocells = 4; % Number of macrocells
numMicrocells = 6; % Number of microcells
numBaseStations = numMacrocells + numMicrocells; % Total number of base stations
% Define the power budget and power limits
totalPowerBudget = 200; % Total power budget in watts
macrocellPowerLimit = 50; % Macrocell power limit in watts
microcellPowerLimit = 30; % Microcell power limit in watts
% Define the channels and bandwidths for each base station
channels = [12, 10, 8, 11, 13, 15, 14, 9, 7, 12].'; % Channel gain for each base station
bandwidths = [20, 25, 15, 20, 15, 20, 15, 10, 25, 20].'; % Bandwidth for each base station
% Define the optimization problem
problem = optimproblem('ObjectiveSense', 'maximize');
% Define the decision variables
powerAlloc = optimvar('powerAlloc', numBaseStations, 'LowerBound', 0, 'UpperBound', totalPowerBudget);
throughput = optimvar('throughput');
% Define the objective function
problem.Objective = -throughput; % Minimize negative throughput
% Define the constraints
problem.Constraints.PowerBudget = sum(powerAlloc) <= totalPowerBudget;
problem.Constraints.MacrocellPower = powerAlloc(1:numMacrocells) <= macrocellPowerLimit;
problem.Constraints.MicrocellPower = powerAlloc(numMacrocells+1:end) <= microcellPowerLimit;
% Calculate the individual throughput values for each base station
baseStationThroughputs = channels .* log2(1 + (powerAlloc .* channels) ./ bandwidths);
% Define the total throughput constraint
problem.Constraints.Throughput = throughput == sum(baseStationThroughputs);
% Solve the optimization problem
[solution, fval] = solve(problem);
% Extract the optimal power allocation and throughput
optimalPowerAlloc = solution.powerAlloc;
optimalThroughput = solution.throughput;
% Display the results
disp("Optimal Power Allocation:");
disp(optimalPowerAlloc);
disp("Optimal Throughput:");
disp(optimalThroughput);
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!