<divclass="textblock"><p>A simple class to enforce both an elapsed time limit and a deterministic time limit in the same thread as a program. </p>
<p>The idea is to call <aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a> as often as possible, until it returns false. The program should then abort as fast as possible.</p>
<p>The deterministic limit is used to ensure reproductibility. As a consequence the deterministic time has to be advanced manually using the method <aclass="el"href="classoperations__research_1_1_time_limit.html#af90cfd1fc238433fc303ee28c5914eb9"title="Advances the deterministic time.">AdvanceDeterministicTime()</a>.</p>
<p>The instruction counter keeps track of number of executed cpu instructions. It uses Performance Monitoring Unit (PMU) counters to keep track of instruction count.</p>
<p>The call itself is as fast as CycleClock::Now() + a few trivial instructions, unless the time_limit_use_instruction_count flag is set.</p>
<p>The limit is very conservative: it returns true (i.e. the limit is reached) when current_time + max(T, ε) >= limit_time, where ε is a small constant (see <aclass="el"href="classoperations__research_1_1_time_limit.html#a1837453fa693143e6ec334701557a448">TimeLimit::kSafetyBufferSeconds</a>), and T is the maximum measured time interval between two consecutive calls to <aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a> over the last kHistorySize calls (so that we only consider "recent" history). This is made so that the probability of actually exceeding the time limit is small, without aborting too early.</p>
<p>The deterministic time limit can be logged at a more granular level: the method <aclass="el"href="classoperations__research_1_1_time_limit.html#af90cfd1fc238433fc303ee28c5914eb9"title="Advances the deterministic time.">TimeLimit::AdvanceDeterministicTime</a> takes an optional string argument: the name of a counter. In debug mode, the time limit object computes also the elapsed time for each named counter separately, and these values can be used to determine the coefficients for computing the deterministic duration from the number of operations. The values of the counters can be printed using <aclass="el"href="classoperations__research_1_1_time_limit.html#a764be64f3029f8b8e23511061d8de355"title="Returns information about the time limit object in a human-readable form.">TimeLimit::DebugString()</a>. There is no API to access the values of the counters directly, because they do not exist in optimized mode.</p>
<p>The basic steps for determining coefficients for the deterministic time are:</p><oltype="1">
<li>Run the code in debug mode to collect the values of the deterministic time counters. Unless the algorithm is different in optimized mode, the values of the deterministic counters in debug mode will be the same as in optimized mode.</li>
<li>Run the code in optimized mode to measure the real (CPU) time of the whole benchmark.</li>
<li>Determine the coefficients for deterministic time from the real time and the values of the deterministic counters, e. g. by solving the equations C_1*c_1 + C_2*c_2 + ... + C_N*c_N + Err = T where C_1 is the unknown coefficient for counter c_1, Err is the random measurement error and T is the measured real time. The equation can be solved e.g. using the least squares method.</li>
<p>Note that in optimized mode, the counters are disabled for performance reasons, and calling AdvanceDeterministicTime(duration, counter_name) is equivalent to calling AdvanceDeterministicTime(duration). </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00106">106</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<trclass="memdesc:aa0975c0aa18ee607a54e7c4c8986ff0f"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets the elapsed, the deterministic time and the instruction count limits. <ahref="classoperations__research_1_1_time_limit.html#aa0975c0aa18ee607a54e7c4c8986ff0f">More...</a><br/></td></tr>
<trclass="memdesc:a43229b9a540c5b4c3751ebb13e73ace8"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets the instruction limit. <ahref="classoperations__research_1_1_time_limit.html#a43229b9a540c5b4c3751ebb13e73ace8">More...</a><br/></td></tr>
<trclass="memdesc:a4cb3517d59bf4642a85294267736af20"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the number of instructions executed since the creation of this object. <ahref="classoperations__research_1_1_time_limit.html#a4cb3517d59bf4642a85294267736af20">More...</a><br/></td></tr>
<trclass="memdesc:a810d5f7aaf80cc09cf5a094e20c1aaca"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns true when the external limit is true, or the deterministic time is over the deterministic limit or if the next time <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> is called is likely to be over the time limit. <ahref="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca">More...</a><br/></td></tr>
<trclass="memdesc:a4273b83b06bfbf856393db6d0a9b8715"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the time left on this limit, or 0 if the limit was reached (it never returns a negative value). <ahref="classoperations__research_1_1_time_limit.html#a4273b83b06bfbf856393db6d0a9b8715">More...</a><br/></td></tr>
<trclass="memdesc:a362a88bfe50d83c028154a62ef53e780"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the remaining deterministic time before <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> returns true due to the deterministic limit. <ahref="classoperations__research_1_1_time_limit.html#a362a88bfe50d83c028154a62ef53e780">More...</a><br/></td></tr>
<trclass="memdesc:a0be73bea3d751ca2926c1cd616abb31e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the number of instructions left to reach the limit. <ahref="classoperations__research_1_1_time_limit.html#a0be73bea3d751ca2926c1cd616abb31e">More...</a><br/></td></tr>
<trclass="memdesc:af90cfd1fc238433fc303ee28c5914eb9"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Advances the deterministic time. <ahref="classoperations__research_1_1_time_limit.html#af90cfd1fc238433fc303ee28c5914eb9">More...</a><br/></td></tr>
<trclass="memdesc:ad068edb54c705c548c20e4ba47b4e3a8"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Advances the deterministic time. <ahref="classoperations__research_1_1_time_limit.html#ad068edb54c705c548c20e4ba47b4e3a8">More...</a><br/></td></tr>
<trclass="memdesc:ae3fe2e2b613455b49c6cc74dd3c7581e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the time elapsed in seconds since the construction of this object. <ahref="classoperations__research_1_1_time_limit.html#ae3fe2e2b613455b49c6cc74dd3c7581e">More...</a><br/></td></tr>
<trclass="memdesc:ac7e861414a70fc937d18bc7ca743fc98"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the elapsed deterministic time since the construction of this object. <ahref="classoperations__research_1_1_time_limit.html#ac7e861414a70fc937d18bc7ca743fc98">More...</a><br/></td></tr>
<trclass="memdesc:a5b6cf15a55615535aa54e71103de8d9f"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Registers the external Boolean to check when <aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a> is called. <ahref="classoperations__research_1_1_time_limit.html#a5b6cf15a55615535aa54e71103de8d9f">More...</a><br/></td></tr>
<trclass="memdesc:a4747b1676f59ae0ccca60bb4c414de08"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the current external Boolean limit. <ahref="classoperations__research_1_1_time_limit.html#a4747b1676f59ae0ccca60bb4c414de08">More...</a><br/></td></tr>
<trclass="memdesc:a312550ebabce586fb77c49e813c610f8"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Sets new time limits. <ahref="classoperations__research_1_1_time_limit.html#a312550ebabce586fb77c49e813c610f8">More...</a><br/></td></tr>
<trclass="memdesc:af6b375b546e563ed7e6312123ce9c7a0"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Overwrites the deterministic time limit with the new value. <ahref="classoperations__research_1_1_time_limit.html#af6b375b546e563ed7e6312123ce9c7a0">More...</a><br/></td></tr>
<trclass="memdesc:a75214ecbf18d3e29566c78cac35f699b"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Queries the deterministic time limit. <ahref="classoperations__research_1_1_time_limit.html#a75214ecbf18d3e29566c78cac35f699b">More...</a><br/></td></tr>
<trclass="memdesc:a764be64f3029f8b8e23511061d8de355"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns information about the time limit object in a human-readable form. <ahref="classoperations__research_1_1_time_limit.html#a764be64f3029f8b8e23511061d8de355">More...</a><br/></td></tr>
<trclass="memdesc:a8e8e386d8f916b1fefb983118cbdf0a6"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a time limit object that uses infinite time for wall time, deterministic time and instruction count limit. <ahref="classoperations__research_1_1_time_limit.html#a8e8e386d8f916b1fefb983118cbdf0a6">More...</a><br/></td></tr>
<trclass="memdesc:a905ec35ba16ac082d3528cf4b6ea9658"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a time limit object that puts limit only on the deterministic time. <ahref="classoperations__research_1_1_time_limit.html#a905ec35ba16ac082d3528cf4b6ea9658">More...</a><br/></td></tr>
<trclass="memdesc:a0ea9620e492bd75ea7e2fcded8f1de8b"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a time limit object initialized from an object that provides methods <code>max_time_in_seconds()</code> and max_deterministic_time(). <ahref="classoperations__research_1_1_time_limit.html#a0ea9620e492bd75ea7e2fcded8f1de8b">More...</a><br/></td></tr>
<p>The elapsed time is based on the wall time and the counter starts 'now'. The deterministic time has to be manually advanced using the method <aclass="el"href="classoperations__research_1_1_time_limit.html#af90cfd1fc238433fc303ee28c5914eb9"title="Advances the deterministic time.">AdvanceDeterministicTime()</a>.</p>
<p>Instruction count is the number of instructions executed. It is based on PMU counters and is not very acurate.</p>
<p>Use an infinite limit value to ignore a limit. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00485">485</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00127">127</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00227">227</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>For reproducibility reasons, the deterministic time doesn't advance automatically as the regular elapsed time does.</p>
<p>In debug mode, this method also updates the deterministic time counter with the given name. In optimized mode, this method is equivalent to <code><aclass="el"href="classoperations__research_1_1_time_limit.html#af90cfd1fc238433fc303ee28c5914eb9"title="Advances the deterministic time.">AdvanceDeterministicTime(double)</a></code>. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00241">241</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>Overwrites the deterministic time limit with the new value. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00297">297</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>Returns information about the time limit object in a human-readable form. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8cc_source.html#l00031">31</a> of file <aclass="el"href="time__limit_8cc_source.html">time_limit.cc</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00282">282</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00145">145</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>This method is designed specifically to work with solver parameter protos, e.g. <code>BopParameters</code>, <code>MipParameters</code> and <code>SatParameters</code>. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00160">160</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00304">304</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>Returns the remaining deterministic time before <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> returns true due to the deterministic limit. </p>
<p>If the <code><aclass="el"href="classoperations__research_1_1_time_limit.html"title="A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...">TimeLimit</a></code> was constructed with <b>infinity</b> as the deterministic limit (default value), this will always return infinity. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00213">213</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>That corresponds to the sum of all deterministic durations passed as an argument to <code><aclass="el"href="classoperations__research_1_1_time_limit.html#af90cfd1fc238433fc303ee28c5914eb9"title="Advances the deterministic time.">AdvanceDeterministicTime()</a></code> calls. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00261">261</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00252">252</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00595">595</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>Note that it might return a positive value even though <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> would return true; because the latter is conservative (see toplevel comment). If <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> was actually called and did return <b>true</b>, though, this will always return 0.</p>
<p>If the <aclass="el"href="classoperations__research_1_1_time_limit.html"title="A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...">TimeLimit</a> was constructed with <b>infinity</b> as the limit, this will always return infinity.</p>
<p>Note that this function is not optimized for speed as <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> is. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00584">584</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00135">135</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>Returns true when the external limit is true, or the deterministic time is over the deterministic limit or if the next time <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> is called is likely to be over the time limit. </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00546">546</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00525">525</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00536">536</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<p>Registers the external Boolean to check when <aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a> is called. </p>
<p>This is used to mark the limit as reached through an external Boolean, i.e. <code><aclass="el"href="classoperations__research_1_1_time_limit.html#a810d5f7aaf80cc09cf5a094e20c1aaca"title="Returns true when the external limit is true, or the deterministic time is over the deterministic lim...">LimitReached()</a></code> returns true when the value of external_boolean_as_limit is true whatever the time limits are.</p>
<p>Note that users of the <aclass="el"href="classoperations__research_1_1_time_limit.html"title="A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...">TimeLimit</a> can modify the provided atomic for their own internal logic (see <aclass="el"href="classoperations__research_1_1_shared_time_limit.html#a17a237457e57625296e6b24feb19c60a">SharedTimeLimit::Stop()</a> for example). </p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00274">274</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00519">519</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00172">172</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00109">109</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="time__limit_8h_source.html#l00108">108</a> of file <aclass="el"href="time__limit_8h_source.html">time_limit.h</a>.</p>