Solved

# Create subsets

• 3 replies
• 255 views

• Newcomer
• 0 replies

Hello,

I have a set of 30 Customers, {1,2,...30}. I want to create subsets of these customers. Specifically, I want to get subsets with cardinality 1,2 and 3. These sets combined should then form the set ‘Routes’, such that the set ‘Routes’  looks as follows: {1}, {2}, … , {30}, {1,2}, {1,3},… { 29,30}, {1,2,3} , {1,2,4} ….. So the idea is to obtain routes containing 1,2 or 3 customers.

I would really appreciate some hints about implementing this in AIMMS.

icon

Best answer by deannezhang 6 April 2020, 13:07

View original

### 3 replies

Userlevel 4
+3

Hi, I’m wondering if you just want to use all the 1-3 cardinality routes as the possible candidate routes to solve your optimization problem, or you want to list them for other reasons.

If it is the first case, you do not need to list all of them. The follow constraint will do the work:

sum(i, v_route(r,i)) <= 3, for all r

r is the index for your resulting route, and i is a customer. v_route(r,i) is 1 if customer i is in route r, and the total number of customers in a route does not exceed 3.

Hi @ectrics98

Just checking in to see if Deanne’s suggestion helped you with your optimization problem?

Thanks

Userlevel 5
+5

@ectrics98

​Hope that the@deannezhang  suggestion have worked for your optimization problem. However, I also developed the ‘Route’ set exaclty how you were wondering to develop.

``empty s_calc_combinatedData;!add for #1for INIT do    SetElementAdd(s_calc_combinatedData, pe_calc_combinatedData, INIT);endfor;!add for #2for (INIT,INIT_AUX1) | ord(INIT) < ord(INIT_AUX1) do    ps_loc_newElement     :=  FormatString("%e - %e", INIT, INIT_AUX1);    SetElementAdd(s_calc_combinatedData, pe_calc_combinatedData, ps_loc_newElement);endfor;!add for #3for (INIT,INIT_AUX1,INIT_AUX2) |         ord(INIT) < ord(INIT_AUX1)        and ord(INIT_AUX1) < ord(INIT_AUX2) do    ps_loc_newElement     :=  FormatString("%e - %e - %e", INIT, INIT_AUX1, INIT_AUX2);    SetElementAdd(s_calc_combinatedData, pe_calc_combinatedData, ps_loc_newElement);endfor;raise warning "Output Cardinality: " + card(s_calc_combinatedData);``

The AIMMS project is here Example002.zip if you would like to debug the code. Obs: run proc_calculateCombinedSet