Transforming Optimization Code from Problem-Based to Solver-Based Approach in MATLAB

Hello,
I have successfully implemented an ILP problem using MATLAB's problem-based optimization approach. However, I am now looking to switch to the solver-based approach to take advantage of its flexibility and efficiency.
In the problem-based approach, I defined binary decision variables, constraints, and an objective function using optimvar, optimconstr, and optimexpr. The code works well, but I need guidance on how to transform this code into a solver-based format using intlinprog.
Here’s a summary of what I have:
Decision Variables:
A 3D binary matrix A(N, numNodes, num_vehicles) for task assignment.
A binary vector chi(num_vehicles) for satisfaction.
Other binary variables like z, t_wait_aux, etc.
Constraints:
Assignment constraints, dependency constraints, and time-based constraints.
I linearized expressions using auxiliary variables and max constraints.
Objective Function:
The objective is to maximize the satisfaction rate, expressed as a linear function of chi.
Could you provide guidance or directions how to systematically convert my existing problem-based variables and constraints into the matrix form required by intlinprog
Here is the code
the problem is attached.
Thank you for your continued help!
run('MyProblem.m')
Unrecognized function or variable 'Compute_uplink_time_linear'.

Error in MyProblem (line 38)
uplink_time = Compute_uplink_time_linear(A,all_subtasks,Data_rate);

Error in run (line 112)
evalin('caller', strcat(scriptStem, ';'));

6 Comments

Didn't you have this problem in solver-based form approximately a year ago ? My guess was you wanted to try the problem-based approach starting from the solver-based formulation now ...
It will be hard to change or add anything in the solver-based formulation after applying "prob2struct" for a complex model. So I doubt you will profit from a conversion.
Yes it doesn't work ‘prob2struct’, I've already updated the attached code, it works but I don't know why it gives me the same result for the assignment matrix A and I've changed the constraints and the objective function but in general it gives the same assignment, I doubt it's a problem with the dimension of the matrices (3D) that the solver can't handle.
If your problem works in the problem-based formulation, "prob2struct" should work because it's exactly this formulation that is used to solve the problem within the MATLAB environment. Simply speaking: "prob2struct" translates your problem-based commands in MATLAB code that can be used with optimization solvers like "intlinprog", "fmincon", "ga" ,etc.
What I meant to say is that your problem is so complicated that you won't profit from the answer you get from "prob2struct" because you won't understand it.
Yes it doesn't work ‘prob2struct’,
What specifically does "doesn't work" mean in this context?
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
I see you posted an error message, but that doesn't seem to me to be related to a call to prob2struct. You just didn't provide the definition of that function in your MyProblem.m file.
Hello @Steven Lord sorry for my late reply, I hadn't seen your comment.
prob2struct is just a suggestion to switch to solver mode. I didn't get an error but the result was weird and didn't fit the purpose. I used the problem based on the structure attached above in myProblem but I don't know if it is possible to convert the expressions into ILP statements, so I solved my problem as follows
% Solve the ILP problem
[x, fval, exitflag, output] = intlinprog(prob);

Sign in to comment.

Answers (1)

3 Comments

Hi @Matt J thanks for your suggestion but as @Torsten said my problem is quite complex so it can't be converted using prob2struct.
@Maria That's not what @Torsten said. He said that he doesn't recommend moving to solver-based form at all because it is hard to make changes once the problem is in that form.
If solve() works on the problem-based formulation then prob2struct has to work. All that solve() really does internally is convert to solver-based form for you (probably using prob2struct) and then run a traditional solver.
@Matt J Yes, I understand. I also wanted to say that it doesn't work because it didn't give the result I wanted because the problem has different variables.
My problem for the solver based is related to the objective function because same result was display for different constraints.

Sign in to comment.

Categories

Asked:

on 16 Aug 2024

Commented:

on 16 Aug 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!