The purpose of the post is to show that converting Or constraints to a Max function runs faster in FindMinimum.
In[1]:= (* Or Constraints For a Point To Be Outside a Pentagon Centered \
at the Origin *)
cons = RegionDisjoint[RegularPolygon[5], Point[{x, y}]] // N
Out[1]= 5. x < -3.80423 + 2.23607 x + 3.80423 y ||
5. x > 3.80423 + 2.23607 x - 3.80423 y ||
15.2169 + 17.8885 x + 5.81234 y < 0. || 7.60845 + 9.40456 y < 0. ||
15.2169 - 17.8885 x + 5.81234 y < 0.
In[2]:= (* Find The Smallest Distance From {.2,.3} To the Edge of the \
Pentagon *)
AbsoluteTiming @
FindMinimum[{Sqrt[(x - .2)^2 + (y - .3)^2], cons}, {x, y}]
Out[2]= {0.393141, {0.448755, {x -> 0.463772, y -> 0.66305}}}
In[3]:=
(* Convert the Constraints to the Right Hand Side Being 0 *)
cons1 = cons /. {a_ > b_ -> a - b > 0, a_ < b_ -> b - a > 0}
Out[3]= -3.80423 - 2.76393 x + 3.80423 y >
0 || -3.80423 + 2.76393 x + 3.80423 y >
0 || -15.2169 - 17.8885 x - 5.81234 y > 0 || -7.60845 - 9.40456 y >
0 || -15.2169 + 17.8885 x - 5.81234 y > 0
In[4]:= (* Convert the Constraints to Max of Left Hand Side >=0 \
*) cons2 = Max[(List @@ cons1[[All, 1]])] > 0
Out[4]= Max[-7.60845 - 9.40456 y, -15.2169 - 17.8885 x -
5.81234 y, -15.2169 + 17.8885 x - 5.81234 y, -3.80423 -
2.76393 x + 3.80423 y, -3.80423 + 2.76393 x + 3.80423 y] > 0
In[5]:= (* Recalculate Distance From {.2,.3} To Edge, Note Speed Up *)
AbsoluteTiming @
FindMinimum[{Sqrt[(x - .2)^2 + (y - .3)^2], cons2}, {x, y}]
Out[5]= {0.21711, {0.448755, {x -> 0.463772, y -> 0.66305}}}