Partitioning Algorithm and Optimization Problem



Given a finite set X, for example, X={1 2 3}, the partition set Y consists of
{{1} {2} {3}},
{{1 2} {3}},
{{1} {2 3}},
{{1 3} {2}},
{{1 2 3}}.
Is there any existing Matlab code that takes X as input and output the above objects as output?

Also, I am looking for the problem of maximizing a cost function f:Y->R over all Y. Is there any basic textbook or state-of-the-art paper that you recommend?

Thanks!
CJLam
.