this repo has no description
1int: w = 4;
2int: h = 4;
3
4% arraydec
5set of int: HEIGHT = 0..h;
6set of int: CHEIGHT = 1..h-1;
7set of int: WIDTH = 0..w;
8set of int: CWIDTH = 1..w-1;
9array[HEIGHT,WIDTH] of var float: t; % 在点(i,j)处的温度
10var float: left; % 左侧温度
11var float: right; % 右侧温度
12var float: top; % 顶部温度
13var float: bottom; % 底部温度
14
15% 拉普拉斯方程:每一个内部点温度是它相邻点的平均值
16constraint forall(i in CHEIGHT, j in CWIDTH)(
17 4.0*t[i,j] = t[i-1,j] + t[i,j-1] + t[i+1,j] + t[i,j+1]);
18
19% sides
20% 边约束
21constraint forall(i in CHEIGHT)(t[i,0] = left);
22constraint forall(i in CHEIGHT)(t[i,w] = right);
23constraint forall(j in CWIDTH)(t[0,j] = top);
24constraint forall(j in CWIDTH)(t[h,j] = bottom);
25
26% 角约束
27constraint t[0,0]=0.0;
28constraint t[0,w]=0.0;
29constraint t[h,0]=0.0;
30constraint t[h,w]=0.0;
31left = 0.0;
32right = 0.0;
33top = 100.0;
34bottom = 0.0;
35
36solve satisfy;
37
38output [ show_float(6, 2, t[i,j]) ++
39 if j == w then "\n" else " " endif |
40 i in HEIGHT, j in WIDTH
41];