Ejemplo n.º 1
0
        public void Irradiate(double strength, RadiationSource source)
        {
            int count = 1;

            if (strength >= 0.1)
            {
                count = (int)Math.Ceiling(Core.Instance.mRandom.NextDouble() * 10.0 * strength);
            }
            else if (Core.Instance.mRandom.NextDouble() > strength * 10.0)
            {
                return;          // count=0
            }
            while (count > 1000) // at really high timewarps we can get huge counts.  Try to keep up
            {
                count -= 100;
                IrradiateOnce(100, source);
            }
            while (count > 100)
            {
                count -= 10;
                IrradiateOnce(10, source);
            }
            while (count-- > 0)
            {
                IrradiateOnce(1, source);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new environment with the specified list of agents, environment dimensions, list of barriers,
        /// and radiation source(s).
        /// </summary>
        /// <param name="Agents">Represents all agents in the enviroment.</param>
        /// <param name="Width">Represents the width of the enviroment.</param>
        /// <param name="Height">Represents the height of the enviroment.</param>
        /// <param name="Barriers">Represents all barriers in the enviroment.</param>
        /// <param name="Source">Represents the source(s) of radiation in the environment.</param>
        public Environment(List <Agent> Agents, double Width, double Height, List <Barrier> Barriers, RadiationSource Source)
        {
            //A uniform random generator for generating the X coordinate of agents' positions.
            NumberGenerator PXRandomGenerator = new UniformRandom(0.0, Width, (int)(DateTime.Now.Ticks));

            //A uniform random generator for generating the Y coordinate of agents' positions.
            NumberGenerator PYRandomGenerator = new UniformRandom(0.0, Height, (int)(DateTime.Now.Ticks + 1));

            //A uniform random generator for generating the X coordinate of agents' velocities.
            NumberGenerator VXRandomGenerator = new UniformRandom(-Width, Width, (int)(DateTime.Now.Ticks + 2));

            //A uniform random generator for generating the Y coordinate of agents' velocities.
            NumberGenerator VYRandomGenerator = new UniformRandom(-Height, Height, (int)(DateTime.Now.Ticks + 3));

            this.Source   = Source;
            this.Barriers = Barriers;
            this.Agents   = Agents;

            // Ensure that the agents are initialized properly.
            foreach (Agent a in Agents)
            {
                a.RadiationFunction = Source.GetRadiation;
                a.MyBestValue       = a.RadiationFunction(a.PX, a.PY);
                a.SendMessage       = Send;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new environment with the specified number of agents, environment dimensions, list of barriers,
        /// and radiation source(s).
        /// </summary>
        /// <param name="NumberOfAgents">Represents the number of all agents in the environment.</param>
        /// <param name="Width">Represents the width of the enviroment.</param>
        /// <param name="Height">Represents the height of the enviroment.</param>
        /// <param name="Barriers">Represents all barriers in the enviroment.</param>
        /// <param name="Source">Represents the source(s) of radiation in the environment.</param>
        public Environment(int NumberOfAgents, double Width, double Height, List <Barrier> Barriers, RadiationSource Source)
        {
            //A uniform random generator for generating the X coordinate of agents' positions.
            NumberGenerator PXRandomGenerator = new UniformRandom(0.0, Width, (int)(DateTime.Now.Ticks));

            //A uniform random generator for generating the Y coordinate of agents' positions.
            NumberGenerator PYRandomGenerator = new UniformRandom(0.0, Height, (int)(DateTime.Now.Ticks + 1));

            //A uniform random generator for generating the X coordinate of agents' velocities.
            NumberGenerator VXRandomGenerator = new UniformRandom(-Width, Width, (int)(DateTime.Now.Ticks + 2));

            //A uniform random generator for generating the Y coordinate of agents' velocities.
            NumberGenerator VYRandomGenerator = new UniformRandom(-Height, Height, (int)(DateTime.Now.Ticks + 3));

            this.Source   = Source;
            this.Barriers = Barriers;

            // Populate the list of agents with random positions and velocities.
            Agents = new List <Agent>(NumberOfAgents);
            for (int i = 0; i < NumberOfAgents; i++)
            {
                Agents.Add(new Agent(
                               PXRandomGenerator.NextDouble(),
                               PYRandomGenerator.NextDouble(),
                               VXRandomGenerator.NextDouble(),
                               VYRandomGenerator.NextDouble(),
                               Source.GetRadiation,
                               Send
                               ));
            }
        }
Ejemplo n.º 4
0
        private void IrradiateOnce(int count, RadiationSource source)
        {
            Vector3 aimPt  = mVessel.rootPart.partTransform.position + randomVector(10.0f);
            Vector3 aimDir = randomVector();
            double  energy = 0;

            switch (source)
            {
            case RadiationSource.VanAllen:     // low-energy
                energy = 10.0 + Core.Instance.mRandom.NextDouble() * 150.0;
                break;

            case RadiationSource.Solar:     // medium-energy
                energy = 120.0 + Core.Instance.mRandom.NextDouble() * 300.0;
                aimDir = Sun.Instance.sunDirection;
                break;

            case RadiationSource.Galactic:     // high-energy
                energy = (1.0 - 4.0 * Math.Log(Core.Instance.mRandom.NextDouble())) * 300.0;
                break;
            }

            IrradiateVector(count, energy, aimPt - aimDir * 1e4f, aimDir);
        }
Ejemplo n.º 5
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            try
            {
                int agentNum = int.Parse(AgentsNum.Text);
                enableStart();

                if (agentNum <= 0)
                {
                    throw new Exception("Number Of Agents Must be => 1");
                }
                if (_source.Count == 0)
                {
                    throw new Exception("Please Add at least one source");
                }

                List <double> _xpos = new List <double>();
                List <double> _ypos = new List <double>();
                List <double> _A    = new List <double>();
                List <double> _B    = new List <double>();
                foreach (Point p in _source)
                {
                    _xpos.Add(p.X);
                    _ypos.Add(p.Y);
                    _A.Add(1000);
                    _B.Add(1000);
                }

                switch (comboBox1.SelectedIndex)
                {
                default:
                case 0:
                    // Gaussian Function Source
                    R   = new GaussianFunctionSource(_source[0].X, _source[0].Y, 1000);
                    env = new Swarm_Logic.Environment(agentNum, MaxX, MaxY, B, R);
                    env.OnIterationEnd += OnIterationEnds;
                    break;

                case 1:
                    // Multiple Gaussian Function Sources
                    R   = new MultipleGaussianFunctionSources(_xpos.ToArray(), _ypos.ToArray(), _A.ToArray(), _B.ToArray());
                    env = new Swarm_Logic.Environment(agentNum, MaxX, MaxY, B, R);
                    env.OnIterationEnd += OnIterationEnds;
                    break;

                case 2:
                    // Multiple Noise Gaussian Function Sources
                    R   = new MultipleNoisyGaussianFunctionSources(_xpos.ToArray(), _ypos.ToArray(), _A.ToArray(), _B.ToArray());
                    env = new Swarm_Logic.Environment(agentNum, MaxX, MaxY, B, R);
                    env.OnIterationEnd += OnIterationEnds;
                    break;
                }

                RefreshGraphics();
                RestartButton.Enabled = true;
            }

            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
                disableStart();
            }
        }
Ejemplo n.º 6
0
        private void IrradiateOnce(int count, RadiationSource source)
        {
            Vector3 aimPt = mVessel.CurrentCoM + randomVector(10.0f);
            Vector3 aimDir = randomVector();
            double energy = 0;
            switch (source)
            {
                case RadiationSource.VanAllen: // low-energy
                    energy = 10.0 + Core.Instance.mRandom.NextDouble() * 150.0;
                    break;
                case RadiationSource.Solar: // medium-energy
                    energy = 120.0 + Core.Instance.mRandom.NextDouble() * 300.0;
                    aimDir = Sun.Instance.sunDirection;
                    break;
                case RadiationSource.Galactic: // high-energy
                    energy = (1.0 - 4.0 * Math.Log(Core.Instance.mRandom.NextDouble())) * 300.0;
                    break;
            }

            IrradiateVector(count, energy, aimPt - aimDir * 1e4f, aimDir);
        }
Ejemplo n.º 7
0
 public void Irradiate(double strength, RadiationSource source)
 {
     int count = 1;
     if (strength >= 0.1)
         count = (int)Math.Ceiling(Core.Instance.mRandom.NextDouble() * 10.0 * strength);
     else if (Core.Instance.mRandom.NextDouble() > strength * 10.0)
         return; // count=0
     while (count > 1000) // at really high timewarps we can get huge counts.  Try to keep up
     {
         count -= 100;
         IrradiateOnce(100, source);
     }
     while (count > 100)
     {
         count -= 10;
         IrradiateOnce(10, source);
     }
     while (count-- > 0)
     {
         IrradiateOnce(1, source);
     }
 }