Template:Team:Paris Saclay/simbox
From 2013.igem.org
(Difference between revisions)
Line 37: | Line 37: | ||
this.molecules= new Array(); | this.molecules= new Array(); | ||
this.reactions= new Array(); | this.reactions= new Array(); | ||
+ | this.reac_order= new Array(); | ||
this.running= false; | this.running= false; | ||
this.refresh_run_time= 50; | this.refresh_run_time= 50; | ||
Line 136: | Line 137: | ||
simulations[id].reactions[i].outputs[j]= tmpid; | simulations[id].reactions[i].outputs[j]= tmpid; | ||
} | } | ||
+ | |||
+ | //precompute index array for easy shuffling | ||
+ | simulations[id].reac_order[i]= i; | ||
} | } | ||
Line 264: | Line 268: | ||
function shuffle_array(array) | function shuffle_array(array) | ||
{ | { | ||
- | + | for(var i= array.length-1; i > 0 ; --i) | |
- | + | { | |
- | + | var j= Math.floor(Math.random() * (i + 1)); | |
- | + | var tmp= array[i]; | |
- | + | array[i]= array[j]; | |
- | + | array[j]= tmp; | |
- | + | } | |
- | + | ||
} | } | ||
function simulation_step(simid) | function simulation_step(simid) | ||
{ | { | ||
- | // | + | var sim= simulations[simid]; |
- | + | ||
- | for(var i= 0 ; i < | + | //Shuffle reaction order |
- | + | shuffle_array(sim.reac_order); | |
- | + | ||
- | + | for(var i= 0 ; i < sim.reac_order.length ; ++i) | |
+ | { | ||
+ | var usedmols= new Array(); | ||
+ | |||
+ | var reac= sim.reactions[sim.reac_order[i]]; | ||
+ | var proba= reac.probability; | ||
+ | for(var j= 0 ; j < reac.inputs.length ; ++j) | ||
+ | { | ||
+ | var tmp= sim.molecules[reac.inputs[j]].quantity; | ||
+ | alert(usedmols[1]); | ||
+ | proba *= tmp; | ||
+ | } | ||
+ | proba /= Math.pow(sim.volume, reac.inputs.length); | ||
+ | |||
+ | } | ||
} | } | ||
Revision as of 23:43, 2 August 2013