0
$\begingroup$

In the optimization of a function, shown below, why are the variables xi, yi not adhering to their specified allowed regions {variable, 0, 5}?

{sol, pts} = Reap[
NMaximize[fitness[x2, y2, x3, y3, x4, y4],
{{x2, 0, 5}, {y2, 0, 5}, {x3, 0, 5}, {y3, 0, 5}, {x4, 0, 5}, {y4, 0, 5}}, Integers, 
Method -> {"SimulatedAnnealing","SearchPoints" -> 20,
"PerturbationScale" -> 1, "RandomSeed" -> 1}, 
EvaluationMonitor :> Sow[{{x2, y2}, {x3, y3}, {x4, y4}}]]] //AbsoluteTiming

{0.56064, {{-2., {x2 -> -6, y2 -> -4, x3 -> -17, y3 -> 7, x4 -> 8, y4 -> 6}}, 
{{{{0, 2}, {0, 2}, {1, 3}}, {{2, 2}, {1, 4}, {4, 
      3}}, {{1, 0}, {2, 5}, {3, 5}}, {{1, 1}, {4, 2}, {4, 4}}, {{4, 
      2}, {2, 1}, {4, 4}}, {{5, 5}, {4, 3}, {1, 2}}, {{2, 3}, {2, 
      4}, {0, 1}}, {{4, 4}, {0, 4}, {1, 4}}, {{2, 2}, {5, 3}, {4, 
      0}}, {{2, 2}, {4, 5}, {1, 0}}, OutputSizeLimit`Skeleton[
    2001], {{4, 11}, {-1, 3}, {12, 4}}, {{4, 11}, {-1, 3}, {12, 
      4}}, {{4, 11}, {-1, 3}, {12, 4}}, {{4, 11}, {-1, 3}, {12, 
      4}}, {{3, 11}, {-1, 3}, {12, 4}}, {{4, 11}, {0, 3}, {12, 
      4}}, {{4, 11}, {-1, 3}, {12, 4}}, {{3, 11}, {-1, 3}, {12, 
      4}}, {{3, 11}, {-1, 3}, {12, 4}}}}}}
$\endgroup$
  • 1
    $\begingroup$ I don't see anything in the documentation that says that using the syntax {x2, 0, 5} constrains x2 to be between 0 and 5. The supported syntax is NMaximize[{f, constraints}, {x2, ..}] $\endgroup$ – Carl Woll May 22 at 18:00
  • 1
    $\begingroup$ What @CarlWoll says. {x2, 0, 5} just means that the starting values of x2 should be between 0 and 5, but there's no attempt to constrain the function to that interval. $\endgroup$ – Brett Champion May 22 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.