42 lines
1.1 KiB
MiniZinc
42 lines
1.1 KiB
MiniZinc
int: w = 4;
|
|
int: h = 4;
|
|
|
|
% arraydec
|
|
set of int: HEIGHT = 0..h;
|
|
set of int: CHEIGHT = 1..h-1;
|
|
set of int: WIDTH = 0..w;
|
|
set of int: CWIDTH = 1..w-1;
|
|
array[HEIGHT,WIDTH] of var float: t; % temperature at point (i,j)
|
|
var float: left; % left edge temperature
|
|
var float: right; % right edge temperature
|
|
var float: top; % top edge temperature
|
|
var float: bottom; % bottom edge temperature
|
|
|
|
% equation
|
|
% Laplace equation: each internal temp. is average of its neighbours
|
|
constraint forall(i in CHEIGHT, j in CWIDTH)(
|
|
4.0*t[i,j] = t[i-1,j] + t[i,j-1] + t[i+1,j] + t[i,j+1]);
|
|
% sides
|
|
% edge constraints
|
|
constraint forall(i in CHEIGHT)(t[i,0] = left);
|
|
constraint forall(i in CHEIGHT)(t[i,w] = right);
|
|
constraint forall(j in CWIDTH)(t[0,j] = top);
|
|
constraint forall(j in CWIDTH)(t[h,j] = bottom);
|
|
% corners
|
|
% corner constraints
|
|
constraint t[0,0]=0.0;
|
|
constraint t[0,w]=0.0;
|
|
constraint t[h,0]=0.0;
|
|
constraint t[h,w]=0.0;
|
|
left = 0.0;
|
|
right = 0.0;
|
|
top = 100.0;
|
|
bottom = 0.0;
|
|
|
|
solve satisfy;
|
|
|
|
output [ show_float(6, 2, t[i,j]) ++
|
|
if j == w then "\n" else " " endif |
|
|
i in HEIGHT, j in WIDTH
|
|
];
|