MODEL:

SETS:

nodes:cnodes,yy;

arcs0(nodes,nodes):x01,x02,c0,cap01,cap02,v01,v02;
arcs1(nodes,nodes):x11, x12,c1,cap11,cap12,v11,v12;

subtours;
subin0(subtours,arcs0):aa01,aa02;
subin1(subtours,arcs1):aa11,aa12;

ENDSETS

DATA:

nodenumber=15;
nodes=1..nodenumber;

maxsubtours=30;
subtours=1..maxsubtours;

arcs0=
2 3    2 6    2 7    2 8
3 4    3 8
4 9
6 7    6 11
8 9    8 11  8 12   8 13
9 10   9 13  9 14   9 15
10 15
13 14
;

c0= 2    3    2     3 
    2    2 
    2
    2    2  
    2    5    3     2 
    2    3    2     3  
    2 
    2
;

arcs1=
1 2    1 6
4 5
5 9    5 10
7 8
11 12 
12 13
14 15
;

c1= 
2 2
2
3   2
2
2 
2
2
;

ENDDATA

SUBMODEL MASTER:

[MASTEROBJ]  min=@SUM(arcs0: c0*(x01+x02))+ @SUM(arcs1: c1*(x11+x12)) ;

@FOR(nodes(i): [n]  @SUM(arcs0(j,i): x01(j,i))+@SUM(arcs0(i,j): x02(i,j))+
                    @SUM(arcs1(j,i): x11(j,i))+@SUM(arcs1(i,j): x12(i,j))=
                    @SUM(arcs0(i,j): x01(i,j))+@SUM(arcs0(j,i): x02(j,i))+
                    @SUM(arcs1(i,j): x11(i,j))+@SUM(arcs1(j,i): x12(j,i))

);

@FOR(arcs1(i,j): [b2] x11(i,j)+x12(i,j) > 1  );

@FOR(subtours(h)|h#LE#cutnumb:   @SUM(arcs0(i,j):aa01(h,i,j)*x01(i,j)+aa02(h,i,j)*x02(i,j)  )+
                                 @SUM(arcs1(i,j):aa11(h,i,j)*x11(i,j)+aa12(h,i,j)*x12(i,j)  ) > 1
     );

ENDSUBMODEL

SUBMODEL INTEGER_MASTER:

[INTMASTEROBJ]  min=@SUM(arcs0: c0*(x01+x02))+ @SUM(arcs1: c1*(x11+x12)) ;

@FOR(nodes(i):      @SUM(arcs0(j,i): x01(j,i))+@SUM(arcs0(i,j): x02(i,j))+
                    @SUM(arcs1(j,i): x11(j,i))+@SUM(arcs1(i,j): x12(i,j))=
                    @SUM(arcs0(i,j): x01(i,j))+@SUM(arcs0(j,i): x02(j,i))+
                    @SUM(arcs1(i,j): x11(i,j))+@SUM(arcs1(j,i): x12(j,i))

);

@FOR(arcs1(i,j):    x11(i,j)+x12(i,j) > 1  );

@FOR(subtours(h)|h#LE#cutnumb:   @SUM(arcs0(i,j):aa01(h,i,j)*x01(i,j)+aa02(h,i,j)*x02(i,j)  )+
                                 @SUM(arcs1(i,j):aa11(h,i,j)*x11(i,j)+aa12(h,i,j)*x12(i,j)  ) > 1
     );

@FOR(arcs1(i,j): @GIN(x11(i,j)));
@FOR(arcs1(i,j): @GIN(x12(i,j)));

ENDSUBMODEL

SUBMODEL CUT_GENERATOR:

[mincut] MIN= @SUM(arcs0(i,j):v01(i,j)*cap01(i,j)+v02(i,j)*cap02(i,j))+
              @SUM(arcs1(i,j):v11(i,j)*cap11(i,j)+v12(i,j)*cap12(i,j));

@FOR(arcs0(i,j): v01(i,j) > yy(j)-yy(i); v02(i,j) > yy(i)-yy(j));
@FOR(arcs1(i,j): v11(i,j) > yy(j)-yy(i); v12(i,j) > yy(i)-yy(j));

yy(source)=0;
yy(sink)=1;

ENDSUBMODEL

CALC:

cutnumb=0;oldcutnumb=-1;
@FOR(nodes(i):cnodes(i)=0);
@FOR(arcs1(i,j):cnodes(i)=1;cnodes(j)=1);
count=1; 
@WHILE(cnodes(count)#EQ#0: count=count+1);
source=count;
integermode=0;
loopend=0;
@WHILE(loopend#EQ#0:
   	sink=source;
	@DIVERT( 'LINGO.LOG');
	@IFC(integermode#EQ#0:
       	@SOLVE(MASTER);
       	@DIVERT();
       	@WRITE('Master Problem value = ',MASTEROBJ,@NEWLINE(1));
   	@ELSE @SOLVE(INTEGER_MASTER);
     		@DIVERT();
    		@WRITE('Integer Master Problem value = ',INTMASTEROBJ,@NEWLINE(1));
       );
	@FOR(arcs0(i,j):cap01(i,j)=x01(i,j);cap02(i,j)=x02(i,j));
	@FOR(arcs1(i,j):cap11(i,j)=x11(i,j);cap12(i,j)=x12(i,j));
	notfound=1;
	oldcutnumb=cutnumb; 
	@WHILE((notfound#EQ#1) #AND#  
		  (sink#LT# nodenumber)  #AND#
            (cutnumb#LT#maxsubtours):  
		sink=sink+1;
		@WHILE((cnodes(sink)#EQ#0)  #AND#  
		       (sink#LT# nodenumber):
             	sink=sink+1 );
		@IFC( cnodes(sink)#EQ#1:
    			@DIVERT( 'LINGO.LOG');
    			@SOLVE(CUT_GENERATOR) ;
    			@DIVERT();
    			@IFC(mincut #LT# 1 :
                  	notfound=0;
                  	cutnumb = cutnumb + 1;
                  	@WRITE('mincut ',mincut,' between ',source,' and ',sink,@NEWLINE(1));
                 		@FOR(arcs0(i,j):aa01(cutnumb,i,j)=v01(i,j);aa02(cutnumb,i,j)=v02(i,j));
                  	@FOR(arcs1(i,j):aa11(cutnumb,i,j)=v11(i,j);aa12(cutnumb,i,j)=v12(i,j));
                 )
             )
);
	@IFC(oldcutnumb#EQ#cutnumb:
      	@IFC(integermode#EQ#0:
           		integermode=1;
      	@ELSE loopend=1
             );
 	@ELSE
      	@IFC(cutnumb#EQ#maxsubtours:
           		integermode=1)
  ));
@IFC(cutnumb#EQ#maxsubtours:
    @WRITE('more cuts maybe needed, solution is not guaranteed optimal nor connected');
  );
@WRITE(@NEWLINE(1));
@FOR(arcs0(i,j):@WRITE('(',i,',',j,')-> ',cap01(i,j),'--- ',cap02(i,j),@NEWLINE(1)));
@FOR(arcs1(i,j):@WRITE('(',i,',',j,')-> ',cap11(i,j),'--- ',cap12(i,j),@NEWLINE(1)));

ENDCALC

END