/// <summary> /// Set up the simulation. /// </summary> /// <param name="entities">Entities that are included in the simulation.</param> /// <exception cref="ArgumentNullException">circuit</exception> /// <exception cref="CircuitException">{0}: No circuit objects for simulation".FormatString(Name)</exception> protected virtual void Setup(EntityCollection entities) { if (entities == null) { throw new ArgumentNullException(nameof(entities)); } if (entities.Count == 0) { throw new CircuitException("{0}: No circuit objects for simulation".FormatString(Name)); } // Use the same comparers as the circuit. This is crucial because they use the same identifiers! EntityParameters = new ParameterPool(entities.Comparer); EntityBehaviors = new BehaviorPool(entities.Comparer, BehaviorTypes.ToArray()); // Create the variables that will need solving if (Configurations.TryGet(out CollectionConfiguration cconfig)) { Variables = new VariableSet(cconfig.VariableComparer ?? EqualityComparer <string> .Default); _cloneParameters = cconfig.CloneParameters; } else { Variables = new VariableSet(); _cloneParameters = false; } // Setup all entity parameters and behaviors SetupParameters(entities); SetupBehaviors(entities); }
/// <summary> /// Set up all behaviors previously created. /// </summary> /// <param name="entities">The circuit entities.</param> private void SetupBehaviors(EntityCollection entities) { var types = BehaviorTypes.ToArray(); foreach (var entity in entities) { entity.CreateBehaviors(types, this, entities); } }