@@ -74,7 +74,7 @@ async function singleSim(query: SingleSimQuery): Promise<SingleSimResponse> {
7474 }
7575}
7676
77- async function chainSim ( query : ChainSimQuery ) : Promise < ChainSimResponse > {
77+ async function chainSim ( query : ChainSimQuery , doLog = true ) : Promise < ChainSimResponse > {
7878 let rho = query . rho ;
7979 let time = 0 ;
8080 let lastStrat = "" ;
@@ -84,7 +84,7 @@ async function chainSim(query: ChainSimQuery): Promise<ChainSimResponse> {
8484
8585 while ( rho < query . cap ) {
8686 const ts = performance . now ( ) ;
87- if ( ts - lastLog > 250 ) {
87+ if ( ts - lastLog > 250 && doLog ) {
8888 lastLog = ts ;
8989 output . textContent = `Simulating ${ logToExp ( rho , 0 ) } /${ stopStr } ` ;
9090 await sleep ( ) ;
@@ -207,11 +207,71 @@ async function simAll(query: SimAllQuery): Promise<SimAllResponse> {
207207 }
208208}
209209
210+ async function stepChainSim ( query : StepChainQuery ) : Promise < StepSimResponse > {
211+ let rho = query . rho ;
212+ const results : simResult [ ] = [ ] ;
213+ const stopStr = logToExp ( query . cap ) ;
214+ let lastLog = 0 ;
215+
216+ while ( rho < query . cap - query . step + 0.000001 ) {
217+ const ts = performance . now ( ) ;
218+ if ( ts - lastLog > 250 ) {
219+ lastLog = ts ;
220+ output . textContent = `Simulating ${ logToExp ( rho , 0 ) } /${ stopStr } ` ;
221+ await sleep ( ) ;
222+ }
223+
224+ const chain_res = await chainSim ( {
225+ queryType : "chain" ,
226+ settings : query . settings ,
227+ sigma : query . sigma ,
228+ rho,
229+ theory : query . theory ,
230+ strat : query . strat ,
231+ cap : query . cap ,
232+ hardCap : query . hardCap
233+ } , false ) ;
234+ if ( ! global . simulating ) break ;
235+
236+ let tau_acc = 0 ;
237+ let time_acc = 0 ;
238+ let pub_count = 0 ;
239+ let bestRes = defaultResult ( ) ;
240+ for ( let result of chain_res . results ) {
241+ tau_acc += result . deltaTau ;
242+ time_acc += result . time ;
243+ pub_count ++ ;
244+ const tauH = tau_acc / ( time_acc / 3600 ) ;
245+ let cur_res : simResult = {
246+ theory : query . theory ,
247+ sigma : query . sigma ,
248+ lastPub : rho ,
249+ pubRho : result . pubRho ,
250+ deltaTau : tau_acc ,
251+ pubMulti : 1 ,
252+ strat : pub_count + " pub" + ( pub_count > 1 ? "s" : "" ) ,
253+ tauH : tauH ,
254+ time : time_acc ,
255+ boughtVars : [ ]
256+ }
257+ bestRes = getBestResult ( bestRes , cur_res ) ;
258+ }
259+ results . push ( bestRes ) ;
260+ rho += query . step ;
261+ }
262+
263+ return {
264+ responseType : "step" ,
265+ results : results
266+ }
267+ }
268+
210269export async function simulate ( query : SimQuery ) : Promise < SimResponse > {
211270 switch ( query . queryType ) {
212271 case "single" : return await singleSim ( query ) ;
213272 case "chain" : return await chainSim ( query ) ;
214273 case "step" : return await stepSim ( query ) ;
215274 case "all" : return await simAll ( query ) ;
275+ case "step_chain" : return await stepChainSim ( query ) ;
216276 }
217277}
0 commit comments