x^2+2*y^2 = 22;
3*x-5*y = (-9);
@free(x);
@free(y);
max = 2*x+3*y;
4*x+3*y<=10;
3*x+5*y<=12;
model:
max = 98*x1+277*x2-x1^2-0.3*x1*x2-2*x2^2;
x1+x2<=100;
x1<=2*x2;
@gin(x1);
@gin(x2);
end
(修改第三问为1/2,1/6....)
model:
sets:
number/1..6/:x;
endsets
@for(number(I):x(I)=I^2);
end
model:
sets:
number/1..6/:x;
endsets
data:
x = 1 3 0.5 7 5 2;
enddata
s=@sum(number(I)|I#le#5:x );
end
model:
sets:
quarters/1..8/:dem,rp,op,inv;
endsets
data:
dem = 40,60,75,25,30,65,50,20;
enddata
min = @sum(quarters:400*rp+450*op+20*inv);
@for(quarters(i):rp(i)<40);
@for(quarters(i)|i#gt#1:
inv(i)=inv(i-1)+rp(i)+op(i)-dem(i));
inv(1)=10+rp(1)+op(1)-dem(1);
end
solution report:
Global optimal solution found.
Objective value: 145750.0
Infeasibilities: 0.000000
Total solver iterations: 15
Variable Value Reduced Cost
DEM( 1) 40.00000 0.000000
DEM( 2) 60.00000 0.000000
DEM( 3) 75.00000 0.000000
DEM( 4) 25.00000 0.000000
DEM( 5) 30.00000 0.000000
DEM( 6) 65.00000 0.000000
DEM( 7) 50.00000 0.000000
DEM( 8) 20.00000 0.000000
RP( 1) 40.00000 0.000000
RP( 2) 40.00000 0.000000
RP( 3) 40.00000 0.000000
RP( 4) 40.00000 0.000000
RP( 5) 40.00000 0.000000
RP( 6) 40.00000 0.000000
RP( 7) 40.00000 0.000000
RP( 8) 20.00000 0.000000
OP( 1) 0.000000 20.00000
OP( 2) 10.00000 0.000000
OP( 3) 35.00000 0.000000
OP( 4) 0.000000 40.00000
OP( 5) 0.000000 20.00000
OP( 6) 0.000000 0.000000
OP( 7) 10.00000 0.000000
OP( 8) 0.000000 50.00000
INV( 1) 10.00000 0.000000
INV( 2) 0.000000 20.00000
INV( 3) 0.000000 60.00000
INV( 4) 15.00000 0.000000
INV( 5) 25.00000 0.000000
INV( 6) 0.000000 20.00000
INV( 7) 0.000000 70.00000
INV( 8) 0.000000 420.0000
Row Slack or Surplus Dual Price
1 145750.0 -1.000000
2 0.000000 30.00000
3 0.000000 50.00000
4 0.000000 50.00000
5 0.000000 10.00000
6 0.000000 30.00000
7 0.000000 50.00000
8 0.000000 50.00000
9 20.00000 0.000000
10 0.000000 450.0000
11 0.000000 450.0000
12 0.000000 410.0000
13 0.000000 430.0000
14 0.000000 450.0000
15 0.000000 450.0000
16 0.000000 400.0000
17 0.000000 430.0000
model:
sets:
students/s1..s8/;
parts(students, students)| &2 #gt# &1:
benefit, match;
endsets
data:
benefit =
9 3 4 2 1 5 6
1 7 3 5 2 1
4 4 2 9 2
1 5 5 2
8 7 6
2 3
4;
enddata
max = @sum(parts(i, j): benefit(i ,j) * match(i, j));
@for(students(i):[constraints]
@sum(parts(j,k) | j #eq# i #or# k #eq# i: match(j,k))=1);
@for(parts(i,j): @bin(match(i,j)));
end
Solution Report:
Global optimal solution found.
Objective value: 30.00000
Objective bound: 30.00000
Infeasibilities: 0.000000
Extended solver steps: 0
Total solver iterations: 0
Variable Value Reduced Cost
BENEFIT( S1, S2) 9.000000 0.000000
BENEFIT( S1, S3) 3.000000 0.000000
BENEFIT( S1, S4) 4.000000 0.000000
BENEFIT( S1, S5) 2.000000 0.000000
BENEFIT( S1, S6) 1.000000 0.000000
BENEFIT( S1, S7) 5.000000 0.000000
BENEFIT( S1, S8) 6.000000 0.000000
BENEFIT( S2, S3) 1.000000 0.000000
BENEFIT( S2, S4) 7.000000 0.000000
BENEFIT( S2, S5) 3.000000 0.000000
BENEFIT( S2, S6) 5.000000 0.000000
BENEFIT( S2, S7) 2.000000 0.000000
BENEFIT( S2, S8) 1.000000 0.000000
BENEFIT( S3, S4) 4.000000 0.000000
BENEFIT( S3, S5) 4.000000 0.000000
BENEFIT( S3, S6) 2.000000 0.000000
BENEFIT( S3, S7) 9.000000 0.000000
BENEFIT( S3, S8) 2.000000 0.000000
BENEFIT( S4, S5) 1.000000 0.000000
BENEFIT( S4, S6) 5.000000 0.000000
BENEFIT( S4, S7) 5.000000 0.000000
BENEFIT( S4, S8) 2.000000 0.000000
BENEFIT( S5, S6) 8.000000 0.000000
BENEFIT( S5, S7) 7.000000 0.000000
BENEFIT( S5, S8) 6.000000 0.000000
BENEFIT( S6, S7) 2.000000 0.000000
BENEFIT( S6, S8) 3.000000 0.000000
BENEFIT( S7, S8) 4.000000 0.000000
MATCH( S1, S2) 0.000000 -9.000000
MATCH( S1, S3) 0.000000 -3.000000
MATCH( S1, S4) 0.000000 -4.000000
MATCH( S1, S5) 0.000000 -2.000000
MATCH( S1, S6) 0.000000 -1.000000
MATCH( S1, S7) 0.000000 -5.000000
MATCH( S1, S8) 1.000000 -6.000000
MATCH( S2, S3) 0.000000 -1.000000
MATCH( S2, S4) 1.000000 -7.000000
MATCH( S2, S5) 0.000000 -3.000000
MATCH( S2, S6) 0.000000 -5.000000
MATCH( S2, S7) 0.000000 -2.000000
MATCH( S2, S8) 0.000000 -1.000000
MATCH( S3, S4) 0.000000 -4.000000
MATCH( S3, S5) 0.000000 -4.000000
MATCH( S3, S6) 0.000000 -2.000000
MATCH( S3, S7) 1.000000 -9.000000
MATCH( S3, S8) 0.000000 -2.000000
MATCH( S4, S5) 0.000000 -1.000000
MATCH( S4, S6) 0.000000 -5.000000
MATCH( S4, S7) 0.000000 -5.000000
MATCH( S4, S8) 0.000000 -2.000000
MATCH( S5, S6) 1.000000 -8.000000
MATCH( S5, S7) 0.000000 -7.000000
MATCH( S5, S8) 0.000000 -6.000000
MATCH( S6, S7) 0.000000 -2.000000
MATCH( S6, S8) 0.000000 -3.000000
MATCH( S7, S8) 0.000000 -4.000000
Row Slack or Surplus Dual Price
1 30.00000 1.000000
CONSTRAINTS( S1) 0.000000 0.000000
CONSTRAINTS( S2) 0.000000 0.000000
CONSTRAINTS( S3) 0.000000 0.000000
CONSTRAINTS( S4) 0.000000 0.000000
CONSTRAINTS( S5) 0.000000 0.000000
CONSTRAINTS( S6) 0.000000 0.000000
CONSTRAINTS( S7) 0.000000 0.000000
CONSTRAINTS( S8) 0.000000 0.000000