y<0.7;
end
(2)执行运行结果为:
Local optimal solution found.
Objective value: 1.355556
Extended solver steps: 2
Total solver iterations: 9
Variable Value Reduced Cost
X 0.6666667 0.000000
Y 0.3333333 0.000000
Row Slack or Surplus Dual Price
1 1.355556 -1.000000
2 0.000000 -10.88889
3 0.000000 9.400000
4 0.3666667 0.000000
(3)结果分析:在X=0.6666667,Y=0.3333333时,z取得最小值1.355556。
三、利用LINGO数学软件包求解最短路问题实例
例2. 在图中,用点表示城市,现有A,B1,B2,C1,C2,C3,D7个城市,点与点之间的连线表示城市之间有道路相连,连线旁的数字表示道路胡长度,现计划从城市A到城市D铺设一条天然气管道,请设计出最小价格管道铺设方案?
(1)在LINGO中输入:
model:
!We have a network of 7 cities. We want to find the length of the shortest route from city 1 to city 7;
sets:
!Here is our primitive set of seven cities;
cities/A,B1,B2,C1,C2,C3,D/; !The Derived set "roads" lists the roads that exist between the cities; roads(cities,cities)/
A,B1 A,B2 B1,C1 B1,C2 B1,C3 B2,C1 B2,C2 B2,C3
C1,D C2,D C3,D/:w,x;
endsets
data:
!Here are the distances that correspond to above links;
w = 2 4 3 3 1 2 3 1 1 3 4;
enddata
n=@size(cities);!The number of cities;
min=@sum(roads:w*x);
@for(cities(i)| i #ne# 1 #and# i #ne# n:
@sum(roads(i,j):x(i,j))=@sum(roads(j,i):x(j,i)));
@sum(roads(i,j)|i #eq# 1 :x(i,j))=1;
End
(2)执行运行结果为:
Global optimal solution found.
Objective value: 6.000000
Total solver iterations: 0
Variable Value Reduced Cost
N 7.000000 0.000000
W( A, B1) 2.000000 0.000000
W( A, B2) 4.000000 0.000000
W( B1, C1) 3.000000 0.000000
W( B1, C2) 3.000000 0.000000
W( B1, C3) 1.000000 0.000000
W( B2, C1) 2.000000 0.000000
W( B2, C2) 3.000000 0.000000
W( B2, C3) 1.000000 0.000000
W( C1, D) 1.000000 0.000000
W( C2, D) 3.000000 0.000000
W( C3, D) 4.000000 0.000000
X( A, B1) 1.000000 0.000000
X( A, B2) 0.000000 1.000000
X( B1, C1) 1.000000 0.000000
X( B1, C2) 0.000000 2.000000
X( B1, C3) 0.000000 1.000000
X( B2, C1) 0.000000 0.000000
X( B2, C2) 0.000000 3.000000
X( B2, C3) 0.000000 2.000000 X( C1, D) 1.000000 0.000000 X( C2, D) 0.000000 0.000000 X( C3, D) 0.000000 0.000000
Row Slack or Surplus Dual Price 1 0.000000 0.000000 2 6.000000 -1.000000 3 0.000000 -6.000000 4 0.000000 -4.000000 5 0.000000 -3.000000 6 0.000000 -1.000000 7 0.000000 -3.000000 8 0.000000 -4.000000
(3)结果分析:(由X=1的结果)看出最短路是11A B C D →→→,最短路长是6个单位。
四、利用LINGO 数学软件包求解博弈实例
(1)在LINGO 中输入:
model : sets :
playerA/1..3/:x; playerB/1..3/;
game(playerA,playerB):C; endsets data :
C = 0 1 -1 -1 0 1 1-1 0; enddata
max =v_A; @free (v_A); @for (playerB(j):
@sum (playerA(i):C(i,j)*x(i))>=v_A); @sum (playerA:x)=1; End
(2)执行运行结果为:
Global optimal solution found.
Objective value: 0.000000 Total solver iterations: 0
Variable Value Reduced Cost V_A 0.000000 0.000000 X( 1) 0.3333333 0.000000 X( 2) 0.3333333 0.000000 X( 3) 0.3333333 0.000000 C( 1, 1) 0.000000 0.000000 C( 1, 2) 1.000000 0.000000
C( 1, 3) -1.000000 0.000000 C( 2, 1) -1.000000 0.000000 C( 2, 2) 0.000000 0.000000 C( 2, 3) 1.000000 0.000000 C( 3, 1) 1.000000 0.000000 C( 3, 2) -1.000000 0.000000
C( 3, 3) 0.000000 0.000000
Row Slack or Surplus Dual Price 1 0.000000 1.000000 2 0.000000 -0.3333333 3 0.000000 -0.3333333 4 0.000000 -0.3333333 5 0.000000 0.000000
(3)结果分析:儿童甲以1/3胡概率出石头、剪子、布中每种策略的一种,其赢得值为0.
(1)在LINGO中输入:
model:
sets:
playerA/1..3/:x;
playerB/1..3/;
game(playerA,playerB):C;
endsets
data:
C = 1 3 9
6 5 7
8 4 2;
enddata
max=v_A;
@free(v_A);
@for(playerB(j):
@sum(playerA(i):C(i,j)*x(i))>=v_A); @sum(playerA:x)=1;
End (2)执行运行结果为:
Global optimal solution found.
Objective value: 5.000000
Total solver iterations: 4
Variable Value Reduced Cost V_A 5.000000 0.000000 X( 1) 0.000000 2.000000 X( 2) 1.000000 0.000000 X( 3) 0.000000 1.000000 C( 1, 1) 1.000000 0.000000 C( 1, 2) 3.000000 0.000000 C( 1, 3) 9.000000 0.000000 C( 2, 1) 6.000000 0.000000 C( 2, 2) 5.000000 0.000000 C( 2, 3) 7.000000 0.000000 C( 3, 1) 8.000000 0.000000 C( 3, 2) 4.000000 0.000000 C( 3, 3) 2.000000 0.000000
Row Slack or Surplus Dual Price
1 5.000000 1.000000
2 1.000000 0.000000
3 0.000000 -1.000000
4 2.000000 0.000000
5 0.000000 5.000000 (3)结果分析:最优策略为4。