Template:Team:Paris Saclay/simbox
From 2013.igem.org
(Difference between revisions)
Line 287: | Line 287: | ||
{ | { | ||
var usedmols= new Array(); | 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 inid= reac.inputs[j]; | ||
+ | if(usedmols[inid] == undefined) | ||
+ | usedmols[inid]= 1; | ||
+ | else | ||
+ | usedmols[inid] ++; | ||
+ | proba *= sim.molecules[inid].quantity; | ||
+ | } | ||
+ | for(var j= 0 ; j < reac.outputs.length ; ++j) | ||
+ | { | ||
+ | var outid= reac.outputs[j]; | ||
+ | if(usedmols[outid] != undefined) | ||
+ | usedmols[outid]--; | ||
+ | } | ||
+ | proba /= Math.pow(sim.volume, reac.inputs.length); | ||
+ | |||
+ | var entier= Math.floor(proba); | ||
+ | var frac= proba - entier; | ||
+ | for(var elt in usedmols) | ||
+ | { | ||
+ | if( entier * usedmols[elt] >= sim.molecules[elt].quantity ) | ||
+ | { | ||
+ | var tmpe= Math.floor(sim.molecules[elt].quantity / usedmols[elt]); | ||
+ | if(tmpe < entier) | ||
+ | entier= tmpe; | ||
+ | frac= 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | for(var j= 0 ; j < reac.inputs.length ; ++j) | ||
+ | sim.molecules[reac.inputs[j]].quantity -= entier; | ||
+ | for(var j= 0 ; j < reac.outputs.length ; ++j) | ||
+ | sim.molecules[reac.outputs[j]].quantity += entier; | ||
+ | |||
+ | bool lastone= false; | ||
+ | if(frac > 0) | ||
+ | lastone= (Math.random() < frac); | ||
+ | if(lastone) | ||
+ | { | ||
+ | for(var j= 0 ; j < reac.inputs.length ; ++j) | ||
+ | sim.molecules[reac.inputs[j]].quantity --; | ||
+ | for(var j= 0 ; j < reac.outputs.length ; ++j) | ||
+ | sim.molecules[reac.outputs[j]].quantity ++; | ||
+ | } | ||
} | } | ||
+ | |||
+ | for(var i= 0 ; i < sim.molecules.length ; ++i) | ||
+ | sim.molecules[i].history.push(sim.molecules[i].quantity); | ||
} | } | ||
Revision as of 00:08, 3 August 2013