how to make a loop to run a model with a specific sequence?

2 views (last 30 days)
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:
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.

Answers (1)

Shadaab Siddiqie
Shadaab Siddiqie on 12 Apr 2021
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'
% your code goes here
% get data based on the x value accordingly
  1 Comment
Jennifer Arellana
Jennifer Arellana on 14 Apr 2021
I understood you but I don't know how to select the elements of the Set O so that they are chosen according to the result of S, for example if:
S = 0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
How do I make Matlab understand that the first row does not form groups, that in the second row as it is 0 0 1 must take only O3, that in the third row 0 1 0 is only take O2 and so usesivamente until completing everything?

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!