private SystemDDs EncodeParallel(ParallelSystem sys, List <int> currentAvailStartBits)
        {
            SystemDDs   sysDDs1, sysDDs2, sysDDs;
            List <bool> synchBool = new List <bool>();

            for (int i = 0; i < synchs.Count; i++)
            {
                synchBool[i] = sys.ContainsAction(synchs[i]);
            }

            // construct mtbdds for first operand
            sysDDs1 = EncodeSystemDefRec(sys.system1, currentAvailStartBits);

            List <int> newCurrentAvailStartBits = new List <int>();

            for (int i = 0; i < synchs.Count; i++)
            {
                newCurrentAvailStartBits[i] = synchBool[i] ? sysDDs1.synchs[i].max : currentAvailStartBits[i];
            }

            // construct mtbdds for second operand
            sysDDs2 = EncodeSystemDefRec(sys.system2, newCurrentAvailStartBits);

            // create object to store mtbdds
            sysDDs = new SystemDDs();

            // combine mtbdds for independent bit
            sysDDs.ind = CombineNonSynchronising(sysDDs1.ind, sysDDs2.ind, sysDDs1.id, sysDDs2.id);

            // combine mtbdds for each synchronising action
            for (int i = 0; i < synchs.Count; i++)
            {
                if (synchBool[i])
                {
                    sysDDs.synchs.Add(CombineSynchronising(sysDDs1.synchs[i], sysDDs2.synchs[i]));
                }
                else
                {
                    sysDDs.synchs.Add(CombineNonSynchronising(sysDDs1.synchs[i], sysDDs2.synchs[i], sysDDs1.id, sysDDs2.id));
                }
            }

            // combine mtbdds for identity matrices
            sysDDs.id = CUDD.Function.Times(sysDDs1.id, sysDDs2.id);

            // combine lists of synchs
            sysDDs.allSynchs.UnionWith(sysDDs1.allSynchs);
            sysDDs.allSynchs.UnionWith(sysDDs2.allSynchs);

            return(sysDDs);
        }
示例#2
0
        public void Dispose_Should_call_Dispose_on_all_systems()
        {
            bool done1 = false;
            bool done2 = false;

            ISystem <int> s1 = Substitute.For <ISystem <int> >();
            ISystem <int> s2 = Substitute.For <ISystem <int> >();

            s1.When(s => s.Dispose()).Do(_ => done1 = true);
            s2.When(s => s.Dispose()).Do(_ => done2 = true);

            ISystem <int> system = new ParallelSystem <int>(s1, null, s2);

            system.Dispose();

            Check.That(done1).IsTrue();
            Check.That(done2).IsTrue();
        }
示例#3
0
        public void Update_Should_call_update_on_all_systems()
        {
            bool mainDone = false;
            bool done1    = false;
            bool done2    = false;

            using (ISystem <int> system = new ParallelSystem <int>(
                       new ActionSystem <int>(_ => mainDone = true),
                       null,
                       new ActionSystem <int>(_ => done1 = true),
                       new ActionSystem <int>(_ => done2 = true)))
            {
                system.Update(0);
            }

            Check.That(mainDone).IsTrue();
            Check.That(done1).IsTrue();
            Check.That(done2).IsTrue();
        }
示例#4
0
        public void Update_with_runner_Should_call_update_on_all_systems()
        {
            bool done1 = false;
            bool done2 = false;
            bool done3 = false;
            bool done4 = false;

            using (SystemRunner <int> runner = new SystemRunner <int>(2))
                using (ISystem <int> system = new ParallelSystem <int>(
                           runner,
                           new ActionSystem <int>(_ => done1 = true),
                           new ActionSystem <int>(_ => done2 = true),
                           new ActionSystem <int>(_ => done3 = true),
                           new ActionSystem <int>(_ => done4 = true)))
                {
                    system.Update(0);
                }

            Check.That(done1).IsTrue();
            Check.That(done2).IsTrue();
            Check.That(done3).IsTrue();
            Check.That(done4).IsTrue();
        }
        public void Update_with_runner_Should_not_call_update_on_any_systems_When_disabled()
        {
            bool done1 = false;
            bool done2 = false;
            bool done3 = false;
            bool done4 = false;

            using (DefaultParallelRunner runner = new(2))
                using (ISystem <int> system = new ParallelSystem <int>(
                           runner,
                           new ActionSystem <int>(_ => done1 = true),
                           new ActionSystem <int>(_ => done2 = true),
                           new ActionSystem <int>(_ => done3 = true),
                           new ActionSystem <int>(_ => done4 = true)))
                {
                    system.IsEnabled = false;
                    system.Update(0);
                }

            Check.That(done1).IsFalse();
            Check.That(done2).IsFalse();
            Check.That(done3).IsFalse();
            Check.That(done4).IsFalse();
        }