/* Curve fitting in Picat. From GLPK example cf12b.mod: """ Curve fitting problem 12.11(b) H P Williams "Model Building in Mathematical Programming" """ The answer should be y = 0.6250x + -0.4000 Max deviation = 1.7250 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 => N = 19, X = [0.0,0.5,1.0,1.5,1.9,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0,6.6,7.0,7.6,8.5,9.0,10.0], Y = [1.0,0.9,0.7,1.5,2.0,2.4,3.2,2.0,2.7,3.5,1.0,4.0,3.6,2.7,5.7,4.6,6.0,6.8,7.3], A :: -1.0..1.0, B :: -1.0..1.0, U = new_list(N), % U :: -10.0..10.0, V = new_list(N), % V :: -10.0..10.0, Z :: -100.0..100.0, % deviation (must have a domain) foreach(I in 1..N) U[I] #>= 0.0, V[I] #>= 0.0, B * X[I] + A + U[I] - V[I] #= Y[I], % deviation constraints Z - U[I] #>= 0.0, Z - V[I] #>= 0.0 end, solve($[min(Z)], X ++ Y ++ U ++ V ++ [A,B]), println(max_deviation=Z), println(a=A), println(b=B), println(u=U), println(v=V), nl.