The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

88 lines
1.2 KiB

4 weeks ago
  1. /*
  2. Curve fitting problem 12.11(b) H P Williams "Model Building in Mathematical Programming"
  3. Dr. H J Mackenzie
  4. HARD software
  5. hjm@hardsoftware.com
  6. 2006-01-23
  7. */
  8. # set of points
  9. set I;
  10. # independent variable
  11. param x {i in I};
  12. # dependent variable
  13. param y {i in I};
  14. # output input values
  15. printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i];
  16. # define equation variables
  17. var a;
  18. var b;
  19. var u {i in I}, >= 0;
  20. var v {i in I}, >= 0;
  21. var z;
  22. # define objective function
  23. minimize deviation: z;
  24. # define equation constraint
  25. s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
  26. # define deviation constrains
  27. s.t. u_deviation {i in I} : z - u[i] >= 0;
  28. s.t. v_deviation {i in I} : z - v[i] >= 0;
  29. solve;
  30. printf "y = %.4fx + %.4f Max deviation = %.4f\n", b, a, z;
  31. /*
  32. *
  33. * DATA section
  34. *
  35. */
  36. data;
  37. param : I : x y :=
  38. 1 0 1
  39. 2 0.5 0.9
  40. 3 1 0.7
  41. 4 1.5 1.5
  42. 5 1.9 2
  43. 6 2.5 2.4
  44. 7 3 3.2
  45. 8 3.5 2
  46. 9 4 2.7
  47. 10 4.5 3.5
  48. 11 5 1
  49. 12 5.5 4
  50. 13 6 3.6
  51. 14 6.6 2.7
  52. 15 7 5.7
  53. 16 7.6 4.6
  54. 17 8.5 6
  55. 18 9 6.8
  56. 19 10 7.3
  57. ;
  58. end;