0
$\begingroup$

Imagine I provide some random input to function like FindInstance[], and I observe that, despite the existence of good solutions, the function will, with some probability, indefinitely evaluate without success. For an example, please see my earlier question: Why is FindInstance failing when I relax a set of constraints?

Can I somehow force the function to return, say, an empty list {} after some time $T$ has passed?

$\endgroup$
  • 1
    $\begingroup$ Did you check TimeConstraint? $\endgroup$ – Spawn1701D Apr 22 '13 at 1:11
  • $\begingroup$ @Spawn1701D That seems not to work for FindInstance? $\endgroup$ – Peter Apr 22 '13 at 1:13
  • $\begingroup$ @Spawn1701D I'm looking for something I can also wrap around some section of code to force it to restart or quit after some time has passed. $\endgroup$ – Peter Apr 22 '13 at 1:14
  • 5
    $\begingroup$ There is also the wrapper/Function variant TimeConstrained. $\endgroup$ – Spawn1701D Apr 22 '13 at 1:16
  • $\begingroup$ @Spawn1701D Yup, that seems to work! $\endgroup$ – Peter Apr 22 '13 at 1:17
2
$\begingroup$

TimeConstrained[expr, t, failexpr] returns failexpr if the time constraint t is not met.

$\endgroup$

Your Answer

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

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