public bool apply(reactor rec,pair_part ret){ particle a = rec.get_particle_id(ret.id1); particle b = rec.get_particle_id(ret.id2); type_state old_a = a.st; type_state old_b = b.st; switch (function) { case 0: default: return false; case 1: //link rec.link (a, b); break; case 2: // split rec.unlink (a, b); break; case 3: // add type_state new_a = new type_state(a.st.type,a.st.state+1); type_state new_b = new type_state(b.st.type,b.st.state+1); rec.update_new_state (a, old_a,new_a); rec.update_new_state (b, old_b,new_b); break; case 4: // swap rec.update_new_state (a, old_a,old_b); rec.update_new_state (b, old_b,old_a); break; } return true; }
public void TestReactor () { reactor rec = new reactor (); /// new configuration tests Assert.AreEqual (0, rec.particles.Count); Assert.AreEqual (0, rec.rules.Count); int t = 0, s = 1; type_state key = new type_state(t,s); particle p = new particle (t, s); rec.add_particle (p); // test add particles Assert.AreEqual (1, rec.particles.Count); Assert.IsTrue(rec.stDict.ContainsKey(key)); Assert.AreEqual (1, rec.stDict [key].Count); // check link -> no links Assert.AreEqual (0, rec.pDict.Count); // double add rec.add_particle (p); Assert.AreEqual (1, rec.particles.Count); // two particles particle q = new particle (t, s); // test add rec.add_particle (q); Assert.AreEqual (2, rec.particles.Count); // test dictionnaries Assert.IsTrue(rec.stDict.ContainsKey(key)); Assert.AreEqual (2, rec.stDict [key].Count); // test remove rec.remove_particle (q); Assert.AreEqual (1, rec.particles.Count); Assert.IsTrue(rec.stDict.ContainsKey(key)); Assert.AreEqual (1, rec.stDict [key].Count); rec.remove_particle (p); Assert.AreEqual (0, rec.particles.Count); Assert.IsTrue(rec.stDict.ContainsKey(key)); Assert.AreEqual (0, rec.stDict [key].Count); // test link rec.add_particle (q); rec.add_particle (p); Assert.AreEqual (2, rec.particles.Count); Assert.IsTrue(rec.stDict.ContainsKey(key)); Assert.AreEqual (2, rec.stDict [key].Count); // create pair part pair_st pst = new pair_st (p, q); pair_st pstn = new pair_st (p.st, q.st); Assert.AreEqual (pst.a, pstn.a); Assert.AreEqual (pst.b, pstn.b); rec.link (p, q); Assert.AreEqual (2, rec.particles.Count); Assert.IsTrue(rec.stDict.ContainsKey(key)); Assert.AreEqual (2, rec.stDict [key].Count); Assert.IsTrue (rec.pDict.ContainsKey (pst)); Assert.AreEqual (1, rec.pDict[pst].Count); }
public bool apply(reactor rec,pair_part ret){ particle a = rec.get_particle_id(ret.id1); particle b = rec.get_particle_id(ret.id2); type_state old_a = a.st; type_state old_b = b.st; // Console.WriteLine ("A:" + (old_a.state == r.reactants.b.state)); pair_st st = products; type_state new_a = st.a; type_state new_b = st.b; if (old_a != new_a) rec.update_new_state (a, old_a, new_a); if (old_b!=new_b) rec.update_new_state (b , old_b, new_b); if (productContact) rec.link (a, b); else { a.unlink (b); rec.unlink (a, b); } return true; }