Error : Failure in initial user-supplied nonlinear constraint function evaluation.
Mostra commenti meno recenti
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()
12 Commenti
Walter Roberson
il 12 Ago 2024
Variable N is not known.
Maria
il 12 Ago 2024
N = 4;
numNodes = 4;
Devices = 3;
MyProblem()
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
il 12 Ago 2024
Modificato: Torsten
il 12 Ago 2024
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
il 12 Ago 2024
Torsten
il 12 Ago 2024
I put all posted functions in the code above. It seems complete now.
Walter Roberson
il 12 Ago 2024
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.
Maria
il 12 Ago 2024
Walter Roberson
il 12 Ago 2024
It is a useless expression, because it does not assign to any output variable!
Maria
il 13 Ago 2024
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.
Risposte (1)
Walter Roberson
il 13 Ago 2024
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 Commenti
Maria
il 13 Ago 2024
Torsten
il 13 Ago 2024
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
il 13 Ago 2024
Torsten
il 13 Ago 2024
And the code works now ?
Maria
il 13 Ago 2024
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);
Maria
il 13 Ago 2024
Torsten
il 13 Ago 2024
As said: we need the code to reproduce the error message in order to say anything.
Maria
il 13 Ago 2024
Maria
il 13 Ago 2024
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);
Maria
il 13 Ago 2024
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
il 13 Ago 2024
Torsten
il 14 Ago 2024
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" ?
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
il 14 Ago 2024
Torsten
il 14 Ago 2024
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
Maria
il 14 Ago 2024
Categorie
Scopri di più su Solver Outputs and Iterative Display in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
