Can I force a function to quit and return some value after a certain amount of time has passed during its evaluation?
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?
Answer
TimeConstrained[expr, t, failexpr] returns failexpr if the time constraint t is not met.
Comments
Post a Comment