how to make a loop to run a model with a specific sequence?
9 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am making a cost minimization model, but I want to run the model many times with different data, therefore, I was thinking to put all the data and create a loop to go choosing with certain sequence the data and run until complete all the sequences. With respect to the sequence that must follow the loop this is going to depend on the set O and the quantity of iterations that must be done are "(2^N)-1" where N is the quantity of elements that has the set O. I am going to give an example so that it is understood as it must be the sequence:
If I have that:
Set O := O1 O2 O3;
The number of iterations will be:
(2^3)-1=7
So the model will be run 7 times and each time it will have a different configuration in the data, these 7 times represent all the possible combinations of the elements of the set O, that would be:
1. O1
2. O2
3. O3
4. O1 O2
5. O1 O3
6. O2 O3
7. O1 O2 O3
But the data would not only be changed in set O, the data would be changed in all the sets and parameters where there is subindex "o", for example in my data, the subindex "o" is present in set O, set Links_oa, set Links_oc, parameter CT_oap, parameter CTocp and parameter supply_op. Initially the sets and parameters have data of all the elements of the set O, but the idea is that if you are for example in iteration 1, the model only runs with the data of O1 and yields the result of minimizing the model, then go to iteration 2 where it only runs with data from O2 until it reaches iteration 7 where it runs with all the data of this example that are O1 O2 and O3. If you want to see the data I am using, I am attaching a .dat file which is my test data and .png file which is my mathematical formulation of my model.
I am new to using Matlab, if someone can guide me on what to do or reference where to find what I need I would be very grateful.
Thank you for your attention and I remain attentive to your answers.
0 个评论
回答(1 个)
Shadaab Siddiqie
2021-4-12
From my understanding you want to run a loop with specific sequence (like subsets in this case). For subset you can do it using bit map.
S = dec2bin(0:2^3-1) - '0'; % Create all the bits
Then you can use this to run a loop and here you select O1 if x = 0 0 1 ; O1 O2 if x = 0 1 1 and so on
for x = S'
disp(x)
% your code goes here
% get data based on the x value accordingly
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!