| |||||||||||||
Maximal inscribing square Description Computing a maximal inscribing square for the curve
(sin(t)*cos(t), sin(t)*t). Comparison of results with different solver choices.
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
inscribedsquare.mos (!****************************************************** Mosel Example Problems ====================== file inscribedsquare.mos ```````````````````````` Computes a maximal inscribing square for the curve (sin(t)*cos(t), sin(t)*t), t in [-pi,pi] Source: https://www.minlplib.org/inscribedsquare01.html x2..x5 are the four values of the parameter t. x6 and x7 are the (x,y) coordinates of the first corner of the square. (x8, x9) is a vector pointing to a second vertex, all the other vertices are given by a combination of these four values. The length of the vector (x8,x9) is exactly the side length of the square, which we are maximizing, that is, the square of it, to keep it nicer. (c) 2023 Fair Isaac Corporation author: S. Heipcke, July 2023 *******************************************************!) model "inscribedsquare" uses "mmxnlp" parameters ALG=1 ! Solver choice: 1: global, 2: SLP, 3: Knitro end-parameters declarations x2,x3,x4,x5,x6,x7,x8,x9: mpvar end-declarations ! Variable bounds x2 >= -3.14159265358979; x2 <= 3.14159265358979; x3 >= -3.14159265358979; x3 <= 3.14159265358979; x4 >= -3.14159265358979; x4 <= 3.14159265358979; x5 >= -3.14159265358979; x5 <= 3.14159265358979; x6 is_free x7 is_free (! Optionally, set initial values: setinitval(x2, -3.14159265358979) setinitval(x3, -1.5707963267949) setinitval(x4, 1.5707963267949) setinitval(x5, 1.5707963267949) setinitval(x6, 1.22464679914735E-16) setinitval(x7, 3.84734138744358E-16) setinitval(x8, 1) setinitval(x9, 1) !) Obj:= x8^2 + x9^2; ! Constraints E2:= sin(x2)*cos(x2) - x6 = 0; E3:= sin(x2)*x2 - x7 = 0; E4:= sin(x3)*cos(x3) - x6 - x8 = 0; E5:= sin(x3)*x3 - x7 - x9 = 0; E6:= sin(x4)*cos(x4) - x6 + x9 = 0; E7:= sin(x4)*x4 - x7 - x8 = 0; E8:= sin(x5)*cos(x5) - x6 - x8 + x9 = 0; E9:= sin(x5)*x5 - x7 - x8 - x9 = 0; setparam("XNLP_VERBOSE",true) ! Uncomment to see detailed output case ALG of 1: writeln("Using global solver") 2: do writeln("Using SLP as local solver") ! Use multi-start heuristic addmultistart("random points", XNLP_MSSET_INITIALVALUES, 100) setparam("XPRS_NLPSOLVER", 1) ! Use a local NLP solver setparam("XNLP_SOLVER", 0) ! Select SLP as local solver end-do 3: do writeln("Using Knitro as local solver") ! Use multi-start heuristic addmultistart("random points", XNLP_MSSET_INITIALVALUES, 100) setparam("XPRS_NLPSOLVER", 1) ! Use a local NLP solver setparam("XNLP_SOLVER", 1) ! Select Knitro as local solver end-do end-case maximize(Obj) writeln("Solution value: ", getobjval) writeln("Corner point: ", x6.sol, ",", x7.sol) writeln("Side vector: ", x8.sol, " ", x9.sol) writeln("t=", x2.sol, " ", x3.sol, " ", x4.sol, " ", x5.sol) end-model | |||||||||||||
© Copyright 2024 Fair Isaac Corporation. |