0
$\begingroup$

Do you know if there is a mistake in this command syntax? It is very simple and still it takes too long. I cannot obtain any result at all:

Maximize[{(EuclideanDistance[{a, d}, {b, e}]+EuclideanDistance[{b, e}, {c, f}]+EuclideanDistance[{c, f}, {a, d}]), 0<=a<=1,0<=d<=1,0<=b<=1,0<=e<=1,0<=c<=1,0<=f<=1}, {a,d,b,e,c,f}]
$\endgroup$
1
  • 3
    $\begingroup$ This is not a simple optimization problem:a nonlinear and nondifferentiable target function in 6 variables. The result of NMaximize[{(EuclideanDistance[{a, d}, {b, e}] + EuclideanDistance[{b, e}, {c, f}] + EuclideanDistance[{c, f}, {a, d}]), 0 <= a <= 1, 0 <= d <= 1, 0 <= b <= 1, 0 <= e <= 1, 0 <= c <= 1, 0 <= f <= 1}, {a, d, b, e, c, f}, Method -> "DifferentialEvolution"] suggests an exact solution. $\endgroup$
    – user64494
    Nov 17, 2020 at 19:05

1 Answer 1

3
$\begingroup$
scene = GeometricScene[{ad, be, cf},
   {Line[{ad, be}], Line[{be, cf}], Line[{cf, ad}]}];

RandomInstance[scene, RandomSeeding -> 4]

enter image description here

Maximizing the sum of the distances

{max, arg} = 
 NMaximize[{(EuclideanDistance[{a, d}, {b, e}] + 
      EuclideanDistance[{b, e}, {c, f}] + EuclideanDistance[{c, f}, {a, d}]), 
    0 <= a <= 1, 0 <= d <= 1, 0 <= b <= 1, 0 <= e <= 1, 0 <= c <= 1, 
    0 <= f <= 1}, {a, d, b, e, c, f}] /. x_Real :> RootApproximant[x]

(* {2 + Sqrt[2], {a -> 1, d -> 1, b -> 1, e -> 0, c -> 0, f -> 1}} *)

Equivalently, maximizing the perimeter of the triangle

{max2, arg2} = 
 NMaximize[{Perimeter[Triangle[{{a, d}, {b, e}, {c, f}}]], 0 <= a <= 1, 
    0 <= d <= 1, 0 <= b <= 1, 0 <= e <= 1, 0 <= c <= 1, 0 <= f <= 1}, {a, d, 
    b, e, c, f}] /. x_Real :> RootApproximant[x]

(* {2 + Sqrt[2], {a -> 1, d -> 1, b -> 1, e -> 0, c -> 0, f -> 1}} *)

As expected, the results are identical

{max, arg} === {max2, arg2}

(* True *)

Show[GeometricScene[{ad -> {a, d}, be -> {b, e}, cf -> {c, f}} /. arg,
   {Line[{ad, be}], Line[{be, cf}], Line[{cf, ad}]}]["Graphics"], 
 Frame -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.