写在最前面:规划问题重要的是模型的建立,对于模型的求解是相对简单的
不使用集合语言
例题:
lingo代码
max = 2*x1 + 3*x2 - 5*x3;
x1 + x2 + x3 = 7;
2*x1 - 5*x2 + x3 >= 10;
x1 + x2 + x3 <= 12;
x1 >= 0;
x2 >= 0;
x3 >= 0;
求解结果:
使用集合语言
例题:
lingo代码:
!定义集合,分类变量;
sets:
demand/1..6/:a ,b, d;
supply/1..2/:x, y, e;
link(demand,supply):c;
endsets
!定义数据段;
data:
a = 1.25 8.75 0.5 5.75 3 7.25;
b = 1.25 0.75 4.75 5 6.5 7.75;
d = 3 5 4 7 6 11;
x = 5 2;
y = 1 7;
e = 20 20;
enddata
!定义模型;
min = @sum(supply(j):@sum(demand(i):
c(i, j) * @sqrt((x(j)-a(j))^2 + (y(j)-b(i))^2)));
@for( demand(i):@sum(supply(j):c(i, j)) = d(i));
@for(supply(j):@sum(demand(i):c(i, j)) <= e(j));
运行结果: