示例#1
0
        protected void Init(SimulatorInitArgs args, bool registerLogger)
        {
            var selfMPs = GetSelfPatterns();

            // get simulation initial events from application
            var pairs = GetInitialEvents();

            Init(selfMPs, pairs, args, registerLogger);
        }
示例#2
0
        protected void Init(Stream selfStream, SimulatorInitArgs args, bool registerLogger)
        {
            var bSelfformatter = new BinaryFormatter();
            var selfPatterns   = (List <MolecularPattern>)bSelfformatter.Deserialize(selfStream);

            // get simulation initial events from application
            var initEvents = GetInitialEvents();

            Init(selfPatterns, initEvents, args, registerLogger);
        }
示例#3
0
        protected void Init(Stream selfStream, Stream runInitStream, SimulatorInitArgs args, bool registerLogger)
        {
            var bSelfformatter = new BinaryFormatter();
            var selfPatterns   = (List <MolecularPattern>)bSelfformatter.Deserialize(selfStream);

            var bInitformatter = new BinaryFormatter();
            var initEvents     = (List <SimulatorInitEvent>)bInitformatter.Deserialize(runInitStream);

            Init(selfPatterns, initEvents, args, registerLogger);
        }
示例#4
0
        private void Init(List <MolecularPattern> selfPatterns,
                          List <SimulatorInitEvent> initEvents, SimulatorInitArgs args, bool registerLogger)
        {
            // create and start local agents
            // number of local tissue must be equal to the number of NS nodes
            LocalTissues = new List <LocalTissue>(new LocalTissue[args.NumLocals]);
            for (int i = 0; i < args.NumLocals; i++)
            {
                var lt = new LocalTissue();
                LocalTissues[i] = lt;
                lt.Start();
            }

            // create, train and start thymus agents
            Thymuses = new List <Thymus>(new Thymus[args.NumThymuses]);
            for (int i = 0; i < args.NumThymuses; i++)
            {
                var thymus = new Thymus(args.NumTCells, args.PeptideLen);
                thymus.Train(selfPatterns);                             // train the thymus by self patterns
                Thymuses[i] = thymus;
                thymus.Start();
            }

            // create and start bone marrow agents
            BoneMarrows = new List <BoneMarrow <T> >(new BoneMarrow <T> [args.NumBoneMarrows]);
            for (int i = 0; i < args.NumBoneMarrows; i++)
            {
                var bm = new BoneMarrow <T>(args.NumAPCs, OnProcessSpamp, OnProcessSdamp, OnProcessAntigen);
                BoneMarrows[i] = bm;
                bm.Start();
            }

            // create and start lymph node agents
            LymphNodes = new List <LymphNode>(new LymphNode[args.NumLymphNodes]);
            for (int i = 0; i < args.NumLymphNodes; i++)
            {
                var ln = new LymphNode();
                LymphNodes[i] = ln;
                ln.Start();
            }

            if (registerLogger)
            {
                // register logger event
                foreach (var tissue in Tissues)
                {
                    tissue.LogEvent += new EventHandler <LogEventArgs>(OnLog);
                }
            }

            // schedule all initial events
            foreach (var pair in initEvents.Where(e => e.LocalNodeId < LocalTissues.Count))
            {
                if (pair.Signal == null)
                {
                    throw new Exception("Event signal cannot be null.");
                }
                if (pair.LocalNodeId > args.NumLocals)
                {
                    throw new Exception("Event refers to an invalid local node ID. Check number of local nodes and localNodeId of event.");
                }
                Scheduler.Schedule(LocalTissues[pair.LocalNodeId].HandleSignal, pair.Time, pair.Signal);
            }
            Initialized = true;
        }