/// <summary>
        /// Set up the simulation.
        /// </summary>
        /// <param name="circuit">The circuit that will be used.</param>
        /// <exception cref="ArgumentNullException">circuit</exception>
        /// <exception cref="CircuitException">{0}: No circuit objects for simulation".FormatString(Name)</exception>
        protected virtual void Setup(Circuit circuit)
        {
            if (circuit == null)
            {
                throw new ArgumentNullException(nameof(circuit));
            }

            // No use simulating an empty circuit
            if (circuit.Entities.Count == 0)
            {
                throw new CircuitException("{0}: No circuit objects for simulation".FormatString(Name));
            }

            // Use the same comparer as the circuit. This is crucial because they use the same identifiers!
            EntityParameters = new ParameterPool(circuit.Entities.Comparer);
            EntityBehaviors  = new BehaviorPool(circuit.Entities.Comparer);

            // Create the variables that will need solving
            Variables = Configurations.TryGet(out CollectionConfiguration cconfig)
                ? new VariableSet(cconfig.VariableComparer ?? EqualityComparer <string> .Default)
                : new VariableSet();

            // Setup all objects
            circuit.Entities.BuildOrderedComponentList();

            // Get all parameters
            SetupParameters(circuit.Entities);
        }
Example #2
0
        /// <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);
        }
        protected BrowserBehaviors(Korat korat, BehaviorPool pool) : base(korat)
        {
            if (pool == null)
            {
                throw new ArgumentNullException("Behaviors pool should not be null.");
            }

            Pool = pool;
        }
Example #4
0
        protected BehaviorsPicker(Korat korat, BehaviorPool pool)
        {
            if (korat == null)
            {
                throw new ArgumentNullException("Given Korat instance should not be null.");
            }

            if (pool == null)
            {
                throw new ArgumentNullException("Given Pool instance should not be null.");
            }

            Korat = korat;
            Pool  = pool;
        }
Example #5
0
        static void Main(string[] args)
        {
            Korat korat = new Korat();

            // Constructs behavior pool by "BehaviorPool pool = Parser.Parse(args)" in the future.
            BehaviorPool pool = new BehaviorPool();

            pool.Add(new WinBehaviorsPicker(korat, pool).Pick("7"));
            pool.Add(new ChromeBehaviorsPicker(korat, pool).Pick("60.0"));

            ChromeBehaviors chrome = pool.Request <ChromeBehaviors>();
            OsBehaviors     os     = pool.Request <OsBehaviors>();

            if (chrome == null || os == null)
            {
                Console.WriteLine("No such behaviors.");
            }
            else
            {
                Console.WriteLine("Before replacing behaviors:");
                RunScript(os, chrome);
            }

            pool.Remove(os);
            pool.Remove(chrome);
            pool.Add(new IeBehaviorsPicker(korat, pool).Pick("ie7"));
            pool.Add(new UbuntuBehaviorsPicker(korat, pool).Pick("16.10"));
            BrowserBehaviors browser = pool.Request <BrowserBehaviors>();

            os = pool.Request <OsBehaviors>();

            if (browser == null || os == null)
            {
                Console.WriteLine("No such behaviors.");
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("After replacing behaviors:");
                RunScript(os, browser);
            }

            Console.Read();
        }
Example #6
0
        /// <summary>
        /// Build the data provider for setting up a behavior for the entity. The entity can control which parameters
        /// and behaviors are visible to behaviors using this method.
        /// </summary>
        /// <param name="parameters">The parameters in the simulation.</param>
        /// <param name="behaviors">The behaviors in the simulation.</param>
        /// <returns>A data provider for the behaviors.</returns>
        /// <exception cref="ArgumentNullException">
        /// parameters
        /// or
        /// behaviors
        /// </exception>
        protected virtual SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            parameters.ThrowIfNull(nameof(parameters));
            behaviors.ThrowIfNull(nameof(behaviors));

            // By default, we include the parameters of this entity
            var result = new SetupDataProvider();

            result.Add("entity", parameters[Name]);
            result.Add("entity", behaviors[Name]);
            return(result);
        }
 public ChromeBehaviors(Korat korat, BehaviorPool pool) : base(korat, pool)
 {
 }
Example #8
0
        /// <summary>
        /// Add inductances to the data provider for setting up behaviors
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }

            // Base execution (will add entity behaviors and parameters for this mutual inductance)
            var data = base.BuildSetupDataProvider(parameters, behaviors);

            // Register inductor 1
            data.Add("inductor1", parameters.GetEntityParameters(InductorName1));
            data.Add("inductor1", behaviors.GetEntityBehaviors(InductorName1));

            // Register inductor 2
            data.Add("inductor2", parameters.GetEntityParameters(InductorName2));
            data.Add("inductor2", behaviors.GetEntityBehaviors(InductorName2));

            return(data);
        }
Example #9
0
        /// <summary>
        /// Setup data provider
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            parameters.ThrowIfNull(nameof(parameters));
            behaviors.ThrowIfNull(nameof(behaviors));
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add the controlling source
            provider.Add("control", behaviors[ControllingName]);
            provider.Add("control", parameters[ControllingName]);

            return(provider);
        }
Example #10
0
 public WinBehaviorsPicker(Korat korat, BehaviorPool pool) : base(korat, pool)
 {
 }
 public UbuntuBehaviorsPicker(Korat korat, BehaviorPool pool) : base(korat, pool)
 {
 }
Example #12
0
        /// <summary>
        /// Build the data provider for setting up a behavior for the entity. The entity can control which parameters
        /// and behaviors are visible to behaviors using this method.
        /// </summary>
        /// <param name="parameters">The parameters in the simulation.</param>
        /// <param name="behaviors">The behaviors in the simulation.</param>
        /// <returns>A data provider for the behaviors.</returns>
        /// <exception cref="ArgumentNullException">
        /// parameters
        /// or
        /// behaviors
        /// </exception>
        protected virtual SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }

            // By default, we include the parameters of this entity
            var result = new SetupDataProvider();

            result.Add("entity", parameters[Name]);
            result.Add("entity", behaviors[Name]);
            return(result);
        }
Example #13
0
        /// <summary>
        /// Build the data provider for setting up behaviors
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add our model parameters and behaviors
            if (Model != null)
            {
                provider.Add("model", parameters.GetEntityParameters(Model.Name));
                provider.Add("model", behaviors.GetEntityBehaviors(Model.Name));
            }

            return(provider);
        }
Example #14
0
 public Edge(Korat korat, BehaviorPool pool) : base(korat, pool)
 {
 }
        /// <summary>
        /// Setup data provider
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add the controlling source
            provider.Add("control", behaviors.GetEntityBehaviors(ControllingName));
            provider.Add("control", parameters.GetEntityParameters(ControllingName));

            return(provider);
        }
        /// <summary>
        /// Build the data provider
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (behaviors == null)
            {
                throw new ArgumentNullException(nameof(behaviors));
            }
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add behaviors and parameters of the controlling voltage source
            provider.Add("control", behaviors[ControllingName]);
            provider.Add("control", parameters[ControllingName]);
            return(provider);
        }
Example #17
0
        /// <summary>
        /// Add inductances to the data provider for setting up behaviors
        /// </summary>
        /// <returns></returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            parameters.ThrowIfNull(nameof(parameters));
            behaviors.ThrowIfNull(nameof(behaviors));

            // Base execution (will add entity behaviors and parameters for this mutual inductance)
            var data = base.BuildSetupDataProvider(parameters, behaviors);

            // Register inductor 1
            data.Add("inductor1", parameters[InductorName1]);
            data.Add("inductor1", behaviors[InductorName1]);

            // Register inductor 2
            data.Add("inductor2", parameters[InductorName2]);
            data.Add("inductor2", behaviors[InductorName2]);

            return(data);
        }
Example #18
0
        /// <summary>
        /// Build the data provider for setting up a behavior for the entity. The entity can control which parameters
        /// and behaviors are visible to behaviors using this method.
        /// </summary>
        /// <param name="parameters">The parameters in the simulation.</param>
        /// <param name="behaviors">The behaviors in the simulation.</param>
        /// <returns>
        /// A data provider for the behaviors.
        /// </returns>
        protected override SetupDataProvider BuildSetupDataProvider(ParameterPool parameters, BehaviorPool behaviors)
        {
            var provider = base.BuildSetupDataProvider(parameters, behaviors);

            // Add our model parameters and behaviors
            if (!string.IsNullOrEmpty(Model))
            {
                provider.Add("model", parameters[Model]);
                provider.Add("model", behaviors[Model]);
            }

            return(provider);
        }