lingo sample code for a QP problem

model:

sets:
	P/0,1,2,3,10/: pSize;		
	P2P(P, P)/@file('e:/qali/pagesel/ham4.txt')/: distance;	
	F/@file('e:/qali/pagesel/004a.gf.out')/: fSize;		
	E(F, F, F): factor;
	F2P(F, P) | pSize(&1) #eq# 0 #or# &2 #ne# 0 : x,r;	
	E2P2P(E, P, P): z;	
	
endsets

data:
	pSize = 2048;	
	distance = @file('e:/qali/pagesel/ham4.txt');
	fSize = @file('e:/qali/pagesel/004a.gf.out');
	E, factor = @file('e:/qali/pagesel/004a.gf.out');	

	!output;
	@text('e:/qali/pagesel/004a.txt') = x;
enddata

!goal;
!min = @sum(E(f1, f2, f3):  @sum(P2P(p1,p2): x(f1,p1)*x(f2,p2)*distance(p1,p2)*factor(f1, f2, f3) ) );
min = @sum(E(f1,f2,i): @sum(P2P(p1,p2): z(f1,f2,i,p1,p2)*distance(p1,p2))) ;

!binary constraits;
@for( F2P: @bin(x));
@for( E2P2P: @bin(z));

!edge constraits;
@for(E(f1,f2,f3): @for(P2P(i,j): z(f1,f2,f3,i,j) > x(f1,i) + x(f2,j) - 1) );
@for( E(f1,f2,f3): @sum(P2P(i,j): z(f1,f2,f3,i,j) ) = 1);

@for(F2P(i,j): r(i,j) >= fSize(i) + @sum(E(f1,f2,i): @sum(P2P(p1,p2): z(f1,f2,i,p1,p2)*distance(p1,p2))) + (x(i,j)-1)*pSize(j) );

!allocate constraits;
@for( F(i): @sum(P(j): x(i,j)) = 1 );

@for( P(j): @sum(F(i): r(i,j) ) <= pSize(j) ); 
!@for( P(j): @sum(F(i): x(i,j)*(fSize(i) + @sum(E(f1, f2, i):  @sum(P2P(p1,p2):@floor((x(f1,p1) + x(f2,p2))/2) * distance(p1,p2)*factor(f1, f2, i)) ) ) ) <= pSize(j) );

你可能感兴趣的:(File,p2p,output,distance)