コード例 #1
0
        public T RegisterFactor <T>(string identifier) where T : Factor
        {
            // if the factor already exists, then return it
            var            factorKey = new FactorKey(identifier, typeof(T));
            SimulationNode node;
            ModelKey       modelKey;

            if (!_modelLookup.TryGetValue(factorKey, out modelKey))
            {
                // otherwise create. Note that creating the factor always creates the corresponding model
                var factor = _factory.CreateFactor(typeof(T), identifier, this) as T;
                var model  = factor.Model;
                modelKey                = new ModelKey(identifier, model.GetType());
                node                    = AddModelToGraph(modelKey, model);
                node.Factor             = factor;
                _modelLookup[factorKey] = modelKey;
            }
            else
            {
                node = _nodes[modelKey];
            }
            _nodeStack.Peek().AddRequisite(node);
            return((T)node.Factor);
        }
コード例 #2
0
 public bool Matches(FactorKey model)
 {
     return model.GetType() == this.Type;
 }
コード例 #3
0
 public bool Matches(FactorKey model)
 {
     return(model.GetType() == this.Type);
 }