現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Error : Failure in initial user-supplied nonlinear constraint function evaluation.
4 ビュー (過去 30 日間)
古いコメントを表示
Maria
2024 年 8 月 12 日
Hello everyone!
I'm encountering an issue with my MATLAB code and could use some assistance. Specifically, I'm getting the following error message:
[sol, fval, exitflag, output] = solve(prob);
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
It seems to be related to the evaluation of the nonlinear constraint function. I've attached the relevant part of my code below. I'm particularly confused because I linearised all my constraint terms, so I wasn't expecting any non-linearity.
Could you please help me identify the issue and suggest any potential fixes?
Thank you!
best Regards!
MyProblem()
Unrecognized function or variable 'N'.
Error in MyProblem (line 2)
A = optimvar('A', N, numNodes, Devices, 'Type', 'integer', 'LowerBound', 0, 'UpperBound', 1);
12 件のコメント
Maria
2024 年 8 月 12 日
Hello @Walter Roberson
N,numNodes,Devices are variables, we can set them (4,4,3) as example
Walter Roberson
2024 年 8 月 12 日
N = 4;
numNodes = 4;
Devices = 3;
MyProblem()
Unrecognized function or variable 'tasks_generated'.
Error in MyProblem (line 5)
SR = sum(chi .* sum(tasks_generated, 2)) / sum(tasks_generated(:));
Torsten
2024 年 8 月 12 日
編集済み: Torsten
2024 年 8 月 12 日
We must be able to reproduce the error - otherwise we can't help.
Please add the missing routines @Walter Roberson listed to the code above and use the >RUN button to check whether the data and functions are complete.
Walter Roberson
2024 年 8 月 12 日
編集済み: Torsten
2024 年 8 月 12 日
We are missing:
- Compute_data_rate
- Compute_uplink_time_linear
Also, the lines
if dependency_matrix(k, prev_subtask, m) == 1
t_wait_aux >= Completion_Time(prev_subtask, prev_node, m) - uplink_time(k, n, m);
end
are not doing anything useful
Maria
2024 年 8 月 12 日
@Walter Roberson i've used this
if dependency_matrix(k, prev_subtask, m) == 1
t_wait_aux >= Completion_Time(prev_subtask, prev_node, m) - uplink_time(k, n, m);
end
because i have this non linear expression (max function)
Walter Roberson
2024 年 8 月 12 日
t_wait_aux >= Completion_Time(prev_subtask, prev_node, m) - uplink_time(k, n, m);
calculates the result of the >= comparison, and assigns the result to the variable ans and surpresses display of ans because of the semi-colon.
Notice that you do not assign any output.
Walter Roberson
2024 年 8 月 12 日
It is a useless expression, because it does not assign to any output variable!
Torsten
2024 年 8 月 13 日
編集済み: Torsten
2024 年 8 月 13 日
No. You just didn't set how t_wait_aux is defined.
Further, it's not necessarily true that setting
m >= x(1),m >= x(2),...,m >= x(n)
will give m = max(x) in an optimization. All values for "m" that are bigger than max(x) also satisfy the constraints.
It must be the case that "m" influences the objective function such that the lower its value the lower the value of the objective function (if your aim is to minimize). If this is the case, "m" will be chosen as max(x) by the optimizer.
回答 (1 件)
Walter Roberson
2024 年 8 月 13 日
assigned_node = find(A(sb, :, v), 1);
covering_uav = find(zeta_m_n(v, :), 1);
if assigned_node == covering_uav
That code has a problem: assigned_node can come out empty. That leads to problems with the statement
arg2_covering_to_assigned(k) = arg2(covering_uav, assigned_node, k)
as arg2() comes out empty when assigned_node is empty, but an empty result cannot be assigned to a definite output location.
When I add in some tracing lines, I get
no assigned node at v = 1, sb = 4, node = 1
no assigned node at v = 1, sb = 4, node = 2
no assigned node at v = 1, sb = 4, node = 3
no assigned node at v = 1, sb = 4, node = 4
no assigned node at v = 2, sb = 1, node = 1
no assigned node at v = 2, sb = 1, node = 2
no assigned node at v = 2, sb = 1, node = 3
no assigned node at v = 2, sb = 1, node = 4
repeated over and over again.
20 件のコメント
Maria
2024 年 8 月 13 日
When i call find on A, it's looking for actual binary values (0 or 1), but since it's an optimization variable, it doesn’t contain concrete values until after the optimization is solved(that's why i used fcn2optimexpr).
Here is the reformulated SNR calculation without using find and instead directly express the SNR in terms of A.
function SNR_matrix = Compute_SNR(N, numNodes, Devices, A, zeta_m_n, h0, distances, alpha, RIS_elements, arg1, arg2, Theta_node, P_v, Noise_up)
SNR_matrix = optimexpr(N, numNodes, Devices);
for v = 1:Devices
for sb = 1:N
for node = 1:numNodes
for node1 = 1:numNodes-1
direct_SNR = sqrt(h0 * distances(v, node1)^(-alpha));
direct_SNR = P_v * norm(direct_SNR)^2 / Noise_up;
effective_power_sum = optimexpr(1);
for k = 1:RIS_elements
effective_channel = Theta_node{node1} * arg1(v, node1, k) .* arg2(node1, node, k);
effective_power_sum = effective_power_sum + norm(effective_channel)^2;
end
ris_SNR = P_v * effective_power_sum / Noise_up;
% Combine both contributions based on assignment and covering UAV
SNR_matrix(sb, node, v) = A(sb, node, v) * (zeta_m_n(v, node1) * direct_SNR + (1 - zeta_m_n(v, node1)) * ris_SNR);
end
end
end
end
end
Torsten
2024 年 8 月 13 日
As far as I know, in an "fcn2optimexpr", you can do all computations as if they were numerical. So no need to define the two "optimexpr" for "SNR_matrix" and "effective_power_sum".
Maria
2024 年 8 月 13 日
in this case i didn't use "fcn2optimexpr". I removed 'find' and i call the function as above .
Torsten
2024 年 8 月 13 日
編集済み: Torsten
2024 年 8 月 13 日
Please supply the complete code you are using.
Are you sure to define SNR_matrix after computing it ?
SNR_matrix = Compute_SNR(N, numNodes, Devices, A, zeta_m_n, h0, distances, alpha, RIS_elements, arg1, arg2, Theta_node, P_v, Noise_up)
SNR_matrix = optimexpr(N, numNodes, Devices);
Torsten
2024 年 8 月 13 日
As said: we need the code to reproduce the error message in order to say anything.
Torsten
2024 年 8 月 13 日
編集済み: Torsten
2024 年 8 月 13 日
Data_rate must be an optimvar, not an optimexpr, I guess.
And be careful:
In the loop over i, it could happen that you assign conflicting constraints to Data_rate(sb, node, v).
Or you only want to assign an optimexpr to Data_rate(sb,node,v).
Then simply use
Data_rate(sb, node, v) = B_Uplink_MHz * (slope * SNR_matrix(sb, node, v) + intercept);
instead of imposing constraints:
prob.Constraints.(['approximation_', num2str(v), '_', num2str(sb), '_', num2str(node), '_', num2str(i)]) = ...
Data_rate(sb, node, v) == B_Uplink_MHz * (slope * SNR_matrix(sb, node, v) + intercept);
Torsten
2024 年 8 月 13 日
編集済み: Torsten
2024 年 8 月 13 日
You must think about which equalities in your model are simple definitions of new variables and what are real constraints for optimization. I could bet that Data_rate(sb,node,v)=..., e.g., is a simple definition of a new variable as a combination of optimvars.
I changed the setting in the code above and MATLAB tells you that you got a nonlinear problem with equality constraints that ga cannot solve (besides other strange constraints of the form 0 <= 1).
Maria
2024 年 8 月 13 日
I don't know if this can work, for example i solve nonlinear problem related to uplink time using fmincon and use the result to solve the original problem.
Torsten
2024 年 8 月 14 日
I don't know if this can work, for example i solve nonlinear problem related to uplink time using fmincon and use the result to solve the original problem.
What do you mean by "this" ?
Torsten
2024 年 8 月 14 日
編集済み: Torsten
2024 年 8 月 14 日
I thought I could use different solvers to solve different parts of my problem, but it doesn't seem possible.
Usually it's possible, but I don't see an attempt where you try it in the code above.
And what is the problem with the code ? "intlinprog" claims having found the optimal solution.
Maria
2024 年 8 月 14 日
There is no calculation done for SNR, Data rate and uplink time , so it was 0.
subject to uplinkConstraint:
0 <= 0.3039
0 <= 0.31376
0 <= 0.40509
Torsten
2024 年 8 月 14 日
If you define
Vehicle_Data = zeros(N, numNodes, Devices); % Ensure Vehicle_Data is defined
you automatically get uplink_time = 0, thus T_off = 0 and finally the constraints
subject to uplinkConstraint:
0 <= 0.3039
0 <= 0.31376
0 <= 0.40509
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)