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--)
+
for(var i= array.length-1; i > 0 ; --i)
-
    {
+
{
-
        var j = Math.floor(Math.random() * (i + 1));
+
  var j= Math.floor(Math.random() * (i + 1));
-
        var temp = array[i];
+
  var tmp= array[i];
-
        array[i] = array[j];
+
  array[i]= array[j];
-
        array[j] = temp;
+
  array[j]= tmp;
-
    }
+
}
-
    return array;
+
}
}
function simulation_step(simid)
function simulation_step(simid)
{
{
-
  //randomize order
+
var sim= simulations[simid];
-
  var indexes= new Array();
+
 
-
  for(var i= 0 ; i < simulations[simid].reactions.length ; ++i)
+
  //Shuffle reaction order
-
   indexes[i]= i;
+
  shuffle_array(sim.reac_order);
-
shuffle_array(indexes);
+
 
-
alert(indexes[0]);
+
  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