## sunsets of a set

## sunsets of a set

(OP)

Hello everyone,

I need to generate all the possible combinations of a set (in my case my set has 32 elements) and I need all possible subsets of 16 elements.

So, anyone have any idea how to do this?

There are subroutines and I have tried, however, documentation is not clear enough. So, if someone knows how to do this either by using a subroutine or by writing a code I would appreciate it.

Thanks and regards,

Ignacio

I need to generate all the possible combinations of a set (in my case my set has 32 elements) and I need all possible subsets of 16 elements.

So, anyone have any idea how to do this?

There are subroutines and I have tried, however, documentation is not clear enough. So, if someone knows how to do this either by using a subroutine or by writing a code I would appreciate it.

Thanks and regards,

Ignacio

## RE: sunsets of a set

## RE: sunsets of a set

I have not tried yet, I am a bit new in FORTRAN... so, if you could give me an example it would help me a lot.

Thanks and kind regards,

## RE: sunsets of a set

_{5}C_{3}where n = 5 and r = 3. Let us work it out manually. Always start with something small that you can work through manually. The combinations will be## CODE

## CODE

## CODE

So now you have your 3 loops.

## CODE

## CODE

## RE: sunsets of a set

First of all thank you so much for your reply and time.

I am going to check it and try to understand the meaning of these loops.

I know how to use loops but this is the very first time that I see this notation in loops.

Thanks again, I really appreciate it.

## RE: sunsets of a set

First of all, the code works perfectly and thanks for that. I just have some doubts due to my lack of experience in FORTRAN.

1.The 'i1' that you used in the loop, it is not specified in the variables section, and as far as I know it should be declared as an integer. It's clear that the code works but I don't get why you did not declared it.

2. Is there a way to storage every output (subset) into a separate file?

3. Could you give me a brief explanation of this: (comb(ii), ii = 1, r, 1). I am completely lost in this statement (of course, I know that you are printing out the results, but the reason of had used ii=1,r,1 is completely out of my understanding right now).

Sincerely,

Ignacio

## RE: sunsets of a set

2) Yes, you need to look at the open, write and close statements. Try https://www.tutorialspoint.com/fortran/fortran_fil...

3) That is an implied do loop which prints elements comb(1) to comb(r). If you just look up implied do loop, there are lots of hits.

## RE: sunsets of a set

For example, for n = 5 and r = 3 it generates combinations starting from

## CODE

## CODE

combination(3) = combination(3) + 1 until combination(3) = 5, i.e. we generate:

## CODE

combination(2) = combination(2) + 1 and set

combination(3) = combination(2) + 1 i.e.

## CODE

## CODE

combination(2) = combination(2) + 1

## CODE

combination(1) = combination(1) + 1 and for i = 2, 3 we set

combination(i) = combination(i - 1) + 1

## CODE

## CODE

## CODE

combination(1) = combination(1) + 1 and get finally

## CODE

Here is the program:

combinations.f95## CODE

You could get the resulting combination into the file using redirection:

## CODE

For bigger n, r use first rather

## CODE

For example for n = 32, r = 16 it computes C(32,16) = 601080390. Creating the file with all combinations took very long time and the file has 28 GB. I cannot open it in editor, only display it's head and tail:

## CODE

## RE: sunsets of a set

Thanks for the detailed explanation, I appreciate it.

Regarding the file size, Yes it is huge. I need this code because I am writing a Monte Carlo Simulated Annealing (MC-SA) and I need to explore the arrangements of a particular crystal and each arrangement of 16 numbers [between 1-32] represent the indices of a set of 3D coordinates. Basically after generate an arrangement I need to pass it to another particular array, then explore/study it (By using MC-SA) and then do the same with the next array, so, technically speaking I don't need to store them in a file.

I've got one last question and it is about MPI: Is it possible to use MPI in a code like this?

As far as I know I would make the code run faster... Right?

I am sort of new in this "FORTRAN world", so I know how to implement some tasks but definitely some task surpass by much my skills... So, I am trying learn and understand as much as I can. So, If you know any book/manual or YouTube channel that you can recommend, it would be really helpful.

Once again, thank you so much.

Kind regards,

ignacio