/* Triangle problem in Picat. From the lecture notes Modelling with Constraints http://www.cse.unsw.edu.au/~cs4418/2008/Lectures/Modelling2.ppt, page 45ff This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. main => go. go => temp(Temp), N = Temp.length, % Note .vars() here. Temp.vars() :: 0.0..100.0, foreach(I in 2..N-1,J in 2..N-1) % Temp[I,J] #= 1.0/4.0*(Temp[I-1,J] + Temp[I+1,J] + Temp[I,J-1] + Temp[I,J+1]) Temp[I,J]*4.0 #= (Temp[I-1,J] + Temp[I+1,J] + Temp[I,J-1] + Temp[I,J+1]) end, solve(Temp), foreach(Row in Temp) foreach(T in Row) printf("%10.3f ", T) end, nl end, HalfN = N div 2, printf("Tempature at Temp[%d,%d]: %0.3f\n", HalfN, HalfN, Temp[HalfN,HalfN]), nl. temp(Temp) => Temp = [[100.0,100.0,100.0,100.0,100.0,100.0,100.0], [ 0.0, _, _, _, _, _, 0.0], [ 0.0, _, _, _, _, _, 0.0], [ 0.0, _, _, _, _, _, 0.0], [ 0.0, _, _, _, _, _, 0.0], [ 0.0, _, _, _, _, _, 0.0], [ 0.0, _, _, _, _, _, 0.0]].