Linear programming for simulink code generation

5 views (last 30 days)
I'm trying to do TSP problem in simulink and use it to generate a ROS package. However, when I calculating minimum weight perfect matching, I use linear programming to find the best prefect match, but linprog function is not supported for code generation. I tried with a few other ways such as OPTI tool box and fminsearchcon but none of them works, the first one also not supporting code generation and the second one can't give me a proper result when there is more than 16 nodes and cost too much time. (BTW all the block in my simulink models are matlab function blocks)
So how should I fix the problem? I can't use linprog as an external function since I have to pack it into a ROS package so everything in my model should be able to generate code.
I'm thinking about using C++ to add another block solving the minimum weight perfect matching and transfer the data back to matlab function blocks. Will that works? Is there any better option that I could do? Or is there any tutorial vedio for similar problem that I can go through?
zihui lang
zihui lang on 24 Aug 2021
@Jonathan Ries Thanks, for your reply, I do make some progress but it is in a different way. I first try to play with matlab S-function, which means I replaced my minimum weight perfect matching block into a C++ code. There are some tutorial about S-function on youtube but those are all some very easy examples without calling in between source file. And the weird things happens, I try to include all header and source file in the S-function but it won't work, I also tried assemble all the source file and header into a single .cpp and .h but it still not working. However, if I copy the c_wapper file generated by Matlab into my Visual studio, the main function is working properly. Since I got a poor background in C++, I decide to give up building a S-function.
I believe this is due to some of the output or input signal for this S-function block have variable size. If you also got variable size situation, I'll suggest you not try with S-function.
As for my problem, I just give up the christofied method and using genetic method to solve the TSP. That method is very straight forward and doesn't ask for complex matlab function.
In your case, I might suggest you looking at OPTI toolbox, I don't remeber the detail but that tool box should have .mex or .cpp file that you could use to build your S-function.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by