! vengono generate tutte  le cliques di 3 nodi ;

MODEL:

SETS:

nodes:x;
arcs(nodes,nodes):y;
nodnod(nodes,nodes):adjmat;

cliques;
triples/1..3/;

clsets(cliques,triples):cs;

ENDSETS

DATA:

!nodenumber = 11;
nodenumber =25;
!nodenumber=50;
nodes=1..nodenumber;
maxcliques=3000;
cliques=1..maxcliques;

!arcs=
1 2  1 11 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11
;

arcs=1, 2, 1, 5, 1, 6, 1, 7, 1, 8, 1, 10, 1, 11, 1, 12, 1, 14, 1, 15, 1, 16, 1, 
17, 1, 19, 1, 24, 1, 25, 2, 5, 2, 6, 2, 7, 2, 11, 2, 12, 2, 13, 2, 14, 2, 16, 
2, 19, 2, 21, 2, 22, 2, 23, 2, 24, 2, 25, 3, 6, 3, 8, 3, 9, 3, 11, 3, 13, 3, 
17, 3, 23, 4, 5, 4, 6, 4, 7, 4, 9, 4, 10, 4, 12, 4, 13, 4, 14, 4, 15, 4, 16, 
4, 19, 4, 22, 4, 23, 4, 25, 5, 8, 5, 10, 5, 16, 5, 17, 5, 18, 5, 20, 5, 24, 
5, 25, 6, 8, 6, 9, 6, 10, 6, 13, 6, 14, 6, 15, 6, 17, 6, 21, 6, 22, 6, 23, 7, 
8, 7, 9, 7, 10, 7, 12, 7, 14, 7, 15, 7, 16, 7, 19, 7, 21, 7, 24, 8, 15, 8, 
16, 8, 18, 8, 19, 8, 25, 9, 13, 9, 14, 9, 18, 9, 20, 9, 25, 10, 17, 10, 19, 
10, 21, 10, 22, 10, 23, 10, 24, 11, 14, 11, 15, 11, 16, 11, 24, 11, 25, 12, 
13, 12, 17, 12, 18, 12, 21, 12, 23, 12, 24, 12, 25, 13, 14, 13, 16, 13, 20, 
13, 22, 13, 24, 13, 25, 14, 15, 14, 17, 14, 19, 15, 17, 15, 19, 15, 20, 16, 
17, 16, 18, 16, 19, 16, 20, 16, 23, 17, 18, 17, 20, 17, 21, 17, 24, 17, 25, 
18, 19, 18, 21, 18, 22, 18, 24, 19, 21, 19, 22, 19, 25, 20, 25, 21, 24, 21, 
25, 23, 25, 24, 25;

!arcs=1, 2, 1, 8, 1, 14, 1, 18, 1, 19, 1, 23, 1, 27, 1, 28, 1, 32, 1, 37, 1, 39, 1, 
43, 1, 47, 1, 49, 1, 50, 2, 7, 2, 11, 2, 14, 2, 15, 2, 17, 2, 19, 2, 20, 2, 
22, 2, 23, 2, 27, 2, 29, 2, 30, 2, 31, 2, 33, 2, 38, 2, 41, 2, 43, 2, 48, 2, 
49, 3, 5, 3, 6, 3, 11, 3, 13, 3, 14, 3, 16, 3, 17, 3, 18, 3, 19, 3, 20, 3, 
24, 3, 27, 3, 30, 3, 32, 3, 37, 3, 38, 3, 40, 3, 41, 3, 42, 3, 45, 4, 7, 4, 
8, 4, 13, 4, 14, 4, 15, 4, 16, 4, 17, 4, 18, 4, 19, 4, 22, 4, 27, 4, 28, 4, 
29, 4, 31, 4, 32, 4, 33, 4, 39, 4, 43, 4, 47, 4, 49, 5, 6, 5, 8, 5, 9, 5, 11, 
5, 14, 5, 16, 5, 19, 5, 21, 5, 26, 5, 30, 5, 31, 5, 37, 5, 38, 5, 39, 5, 41, 
5, 42, 5, 43, 5, 45, 5, 48, 5, 50, 6, 7, 6, 13, 6, 14, 6, 15, 6, 17, 6, 18, 
6, 20, 6, 22, 6, 24, 6, 28, 6, 33, 6, 37, 6, 40, 6, 41, 6, 43, 6, 44, 6, 47, 
6, 49, 7, 10, 7, 11, 7, 13, 7, 15, 7, 23, 7, 25, 7, 26, 7, 28, 7, 29, 7, 30, 
7, 31, 7, 36, 7, 37, 7, 38, 7, 44, 7, 47, 8, 10, 8, 11, 8, 18, 8, 21, 8, 22, 
8, 23, 8, 26, 8, 27, 8, 28, 8, 29, 8, 37, 8, 38, 8, 40, 8, 43, 8, 47, 8, 48, 
8, 49, 9, 14, 9, 15, 9, 16, 9, 17, 9, 21, 9, 23, 9, 24, 9, 25, 9, 26, 9, 27, 
9, 30, 9, 31, 9, 33, 9, 35, 9, 37, 9, 38, 9, 41, 9, 43, 9, 46, 9, 47, 10, 11, 
10, 13, 10, 15, 10, 16, 10, 17, 10, 18, 10, 19, 10, 23, 10, 28, 10, 33, 10, 
34, 10, 35, 10, 37, 10, 40, 10, 41, 10, 46, 10, 50, 11, 15, 11, 17, 11, 23, 
11, 26, 11, 27, 11, 31, 11, 32, 11, 34, 11, 35, 11, 37, 11, 38, 11, 39, 11, 
41, 11, 42, 11, 43, 11, 44, 11, 45, 12, 15, 12, 17, 12, 18, 12, 19, 12, 28, 
12, 30, 12, 32, 12, 37, 12, 38, 12, 40, 12, 41, 12, 43, 12, 45, 12, 47, 12, 
48, 12, 49, 13, 16, 13, 18, 13, 24, 13, 27, 13, 28, 13, 29, 13, 32, 13, 34, 
13, 41, 13, 43, 13, 44, 13, 45, 13, 46, 13, 49, 14, 15, 14, 17, 14, 23, 14, 
30, 14, 31, 14, 36, 14, 38, 14, 43, 14, 44, 14, 46, 14, 47, 14, 49, 14, 50, 
15, 18, 15, 19, 15, 20, 15, 27, 15, 29, 15, 30, 15, 33, 15, 41, 15, 42, 15, 
43, 15, 45, 15, 48, 16, 19, 16, 23, 16, 24, 16, 26, 16, 27, 16, 30, 16, 31, 
16, 33, 16, 39, 16, 42, 16, 43, 16, 44, 16, 45, 16, 49, 16, 50, 17, 19, 17, 
22, 17, 25, 17, 27, 17, 28, 17, 29, 17, 30, 17, 32, 17, 33, 17, 34, 17, 36, 
17, 38, 17, 43, 17, 46, 17, 47, 17, 48, 18, 19, 18, 21, 18, 25, 18, 31, 18, 
33, 18, 34, 18, 35, 18, 37, 18, 38, 18, 47, 18, 48, 18, 49, 19, 24, 19, 29, 
19, 32, 19, 38, 19, 40, 19, 43, 19, 45, 19, 46, 19, 47, 19, 49, 19, 50, 20, 
21, 20, 23, 20, 25, 20, 28, 20, 30, 20, 35, 20, 37, 20, 38, 20, 39, 20, 41, 
20, 43, 20, 50, 21, 22, 21, 25, 21, 28, 21, 29, 21, 30, 21, 34, 21, 35, 21, 
38, 21, 42, 21, 43, 21, 44, 21, 49, 21, 50, 22, 25, 22, 26, 22, 29, 22, 35, 
22, 36, 22, 37, 22, 39, 22, 40, 22, 45, 22, 48, 22, 49, 23, 24, 23, 26, 23, 
28, 23, 30, 23, 32, 23, 33, 23, 34, 23, 35, 23, 36, 23, 37, 23, 39, 23, 42, 
23, 47, 23, 49, 24, 26, 24, 32, 24, 35, 24, 38, 24, 39, 24, 41, 24, 47, 24, 
49, 25, 27, 25, 28, 25, 30, 25, 31, 25, 32, 25, 40, 25, 41, 25, 42, 25, 43, 
25, 44, 25, 45, 25, 46, 25, 48, 26, 27, 26, 29, 26, 31, 26, 32, 26, 33, 26, 
38, 26, 40, 26, 41, 26, 45, 26, 49, 26, 50, 27, 29, 27, 30, 27, 32, 27, 34, 
27, 37, 27, 42, 27, 44, 27, 46, 27, 47, 28, 33, 28, 38, 28, 47, 28, 48, 29, 
30, 29, 31, 29, 33, 29, 34, 29, 36, 29, 37, 29, 39, 29, 41, 29, 44, 29, 46, 
29, 47, 29, 49, 29, 50, 30, 32, 30, 33, 30, 37, 30, 42, 30, 46, 30, 47, 30, 
48, 30, 49, 30, 50, 31, 32, 31, 36, 31, 39, 31, 45, 31, 46, 31, 47, 32, 33, 
32, 35, 32, 37, 32, 41, 32, 42, 32, 43, 32, 45, 32, 47, 33, 38, 33, 39, 33, 
40, 33, 41, 33, 46, 33, 47, 33, 49, 33, 50, 34, 38, 34, 41, 34, 42, 34, 43, 
34, 44, 34, 45, 34, 48, 34, 49, 35, 36, 35, 37, 35, 43, 35, 44, 35, 45, 35, 
47, 35, 48, 36, 37, 36, 38, 36, 39, 36, 40, 36, 41, 36, 42, 36, 43, 36, 44, 
36, 45, 36, 46, 36, 47, 36, 48, 36, 50, 37, 41, 37, 43, 37, 46, 37, 48, 38, 
39, 38, 40, 38, 43, 38, 49, 38, 50, 39, 40, 39, 41, 39, 42, 39, 46, 39, 47, 
39, 48, 39, 50, 40, 41, 40, 42, 42, 44, 42, 49, 43, 44, 43, 45, 43, 47, 43, 
48, 44, 45, 45, 46, 45, 47, 45, 49, 46, 48, 46, 50, 47, 48, 47, 49, 49, 50;

ENDDATA

SUBMODEL MAXCUT:

max=@SUM(arcs:y);

@FOR(cliques(h)|h#LE#clcnt: y(cs(h,1),cs(h,2)) < y(cs(h,1),cs(h,3)) + y(cs(h,2),cs(h,3)) ;
                            y(cs(h,1),cs(h,3)) < y(cs(h,1),cs(h,2)) + y(cs(h,2),cs(h,3)) ;
                            y(cs(h,2),cs(h,3)) < y(cs(h,1),cs(h,3)) + y(cs(h,1),cs(h,2)) ;
                            y(cs(h,1),cs(h,2)) + y(cs(h,1),cs(h,3)) + y(cs(h,2),cs(h,3)) < 2 ;
                            );

!@FOR(nodes:@BIN(x));
@FOR(arcs:@BIN(y));
@FOR(arcs:@BND(0,y,1));

ENDSUBMODEL

CALC:

@FOR(nodnod(i,j):adjmat(i,j)=0);
@FOR(arcs(i,j): adjmat(i,j)=1;adjmat(j,i)=1);
clcnt=0;
@FOR(arcs(i,j):
     @FOR(nodes(k):
           @IFC((adjmat(i,k)#GT#0) #AND# (adjmat(j,k)#GT#0) #AND# (i#LT#j) #AND# (j#LT#k):
                clcnt=clcnt+1;@WRITE('clique n. ',clcnt,' ->',i,',',j,',',k,@NEWLINE(1));
                cs(clcnt,1)=i; cs(clcnt,2)=j;cs(clcnt,3)=k;
               )
         )
     );
@SOLVE(MAXCUT);

ENDCALC

END