/* Curve fitting in Picat. From GLPK example cf12a.mod: """ Curve fitting problem 12.11(a) H P Williams "Model Building in Mathematical Programming" """ The answer should be y = 0.6375x + 0.581 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 :: 0.0..1.0, B :: 0.0..1.0, U = new_list(N), U :: 0.0..3.0, V = new_list(N), V :: 0.0..3.0, Z #= sum(U) + sum(V), foreach(I in 1..N) B * X[I] + A + U[I] - V[I] #= Y[I] end, solve($[min(Z)], X ++ Y ++ U ++ V), println(z=Z), println(a=A), println(b=B), % println(u=U), % println(v=V), nl.