Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
1  
Did you check TimeConstraint? –  Spawn1701D Apr 22 '13 at 1:11
    
@Spawn1701D That seems not to work for FindInstance? –  Peter Apr 22 '13 at 1:13
    
@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. –  Peter Apr 22 '13 at 1:14
5  
There is also the wrapper/Function variant TimeConstrained. –  Spawn1701D Apr 22 '13 at 1:16
    
@Spawn1701D Yup, that seems to work! –  Peter Apr 22 '13 at 1:17
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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