Swap between two sub array of an array
显示 更早的评论
Swap between two sub sequences. Position one and two are selected randomly first and then position three and four. Provided these selections do not overlap then element sequence between position one and two and element sequence between position three and four are swapped.
Example: idx1 = [2 4], idx2 = [7 10], A = [2 5 3 4 7 1 6 9 8 10 11 12] would become Anew=[2 6 9 8 10 7 1 5 3 4 11 12]
Thank you
采纳的回答
更多回答(1 个)
Amine Ne
2018-8-20
5 个评论
Stephan
2018-8-20
Nice,
but i guess it is a pretty expensive calculation if you use it for local search. I think about TSP for example to use it and how many times it has to be calculated to get a better result...
However, the code is working so far.
Amine Ne
2018-8-20
Amine Ne
2018-8-20
Stephan
2018-8-21
Do you have to write your own algorithm? If not i would suggest to use Global Optimization Toolbox (if you have access to it), since there are possibilities of parallelisation (if you have access to Parallel omputing Toolbox) and the code is optimized by professionals.
If you have or want to write your own code i would suggest to do the following:
I think it would be worthwhile to search the forum and the documentation for vectorization, parallelization and performance enhancement and related topics.
There are numerous contributions (accepted answers) specifically from the MVP contributers (e.g. Walter Roberson, Jan, Stephen Cobeldick, John D'Errico, Star Strider, Guillaume, dpb, KSSV ... and many others) in which people have asked for options on their code to optimize and speed up.
Especially James Tursa (according to his profile) is interested in speed and performance and has certainly given some good hints in his answers.
These are certainly good sources to get suggestions for your project.
Another way (you can do by yourself) is to check and improve your code by using the Profiler feature and the Analyze Code Button. These tools show you where in your code how much time is spent or where you have typical errors. This may provide evidence of improvement.
I suggest you to try these ways and in places where you have questions to come back with a new question here. It's always amazing to see how well some people can deal with Matlab and how much knowledge is available here.
As an example read this link where i asked for the possibilities of improvement from a matlab code. The answer John D'Errico gave me brought me a lot of insight to this topic.
Thats what i can suggest you.
Best regards
Stephan
Amine Ne
2018-8-22
类别
在 帮助中心 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!