예제 #1
0
파일: Program.cs 프로젝트: babaq/Soul
 static void Init()
 {
     Console.WriteLine("Init Neural Network And Simulation Environment . . .\n");
     // neural network
     network = new Network();
     Console.WriteLine("1: MP   2: LI   3: IF   4: HH\n");
     var select = Console.ReadLine();
     switch (select)
     {
         case "1":
             InitMP();
             break;
         case "2":
             InitLI();
             break;
         case "3":
             InitIF();
             break;
         case "4":
             InitHH();
             break;
     }
     // solver to be used
     solver = new ODESolver();
     // recorder to be used
     recorder = new Recorder(simulator,RecordType.All,"SCoreTest01");
     // simulator
     simulator = new Simulator(0.1, 20, network, solver, recorder);
     Console.WriteLine("Init Done. Ready for Simulation.\n");
 }
예제 #2
0
        private void StartAnimation(
            object sender, EventArgs e)
        {
// Invoke ODE solver:
            ODESolver.Function[] f =
                new ODESolver.Function[2] {
                f1, f2
            };
            double[] result = ODESolver.RungeKutta4(
                f, xx, time, dt);
// Display moving pendulum on screen:
            Point pt = new Point(
                140 + 130 * Math.Sin(result[0]),
                20 + 130 * Math.Cos(result[0]));

            ball.Center = pt;
            line1.X2    = pt.X;
            line1.Y2    = pt.Y;
// Display theta - time curve on canvasRight:
            if (time < xMax)
            {
                pl.Points.Add(new Point(XNormalize(time) + 10,
                                        YNormalize(180 * result[0] / Math.PI)));
            }
// Reset the initial values for next calculation:
            xx    = result;
            time += dt;
            if (time > 0 && Math.Abs(result[0]) < 0.01 &&
                Math.Abs(result[1]) < 0.001)
            {
                tbDisplay.Text = "Stopped";
                CompositionTarget.Rendering -= StartAnimation;
            }
        }
예제 #3
0
    void FixedUpdate()
    {
        var result = ODESolver.RungeKutta4(
            new ProjectileODE(
                new ProjectileODEData(this)),
            0);

        transform.position  = result.Position;
        Properties.Velocity = result.Velocity;
        if (transform.position.y < 0)
        {
            Time.timeScale = 0;
            Debug.Log(Time.timeSinceLevelLoad);
        }
    }
예제 #4
0
파일: WorkShop.xaml.cs 프로젝트: babaq/Soul
        public WorkShop()
        {
            InitializeComponent();

            var network = new Network();
            var solver = new ODESolver();
            var recorder = new Recorder(Simulator, RecordType.None, "Soul");
            Simulator = new Simulator(0.01, 50, network, solver, recorder);
            IsReportProgress = true;
            CellNet = new CellNet(network);
            IsImaging = true;

            var transformGroup = new Transform3DGroup();
            TranslateTransform = new TranslateTransform3D();
            RotateTransform = new RotateTransform3D(new QuaternionRotation3D());
            ScaleTransform = new ScaleTransform3D();
            transformGroup.Children.Add(TranslateTransform);
            transformGroup.Children.Add(RotateTransform);
            transformGroup.Children.Add(ScaleTransform);
            ModelVisual.Transform = transformGroup;

            ActionType = ActionType.None;
            MouseLeftButtonDown += WorkShop_MouseLeftButtonDown;
            MouseLeftButtonUp += WorkShop_MouseLeftButtonUp;
            MouseRightButtonDown += WorkShop_MouseRightButtonDown;
            MouseRightButtonUp += WorkShop_MouseRightButtonUp;
            MouseMove += WorkShop_MouseMove;
            MouseWheel += WorkShop_MouseWheel;

            var n = new LI(-50, -48, 5, 2, -55);
            var net0 = Proliferation.Division(n, new Point3D(1, 10, 10), "InitPotential", new Randomizer(new RNG(), dimyend: 9, dimzend: 9, mean: -50.0, std: 5));
            net0.ReSet();
            //net0.ReShape(new Point3D(2, 10, 5));
            var net1 = Proliferation.Division(n, new Point3D(1, 10, 10), "InitPotential", new Randomizer(new RNG(), dimyend: 9, dimzend: 9, mean: -50.0, std: 10));
            net1.ReSet();
            Projection.From_To(net0, net1, new WeightSynapse(null, 1), ProjectionType.OneToOne, 1.0);
            Projection.From_To(net0, net0, new WeightSynapse(null, -0.4), ProjectionType.AllToAll, 0.3);
            Projection.From_To(net1, net0, new WeightSynapse(null, -0.1), ProjectionType.AllToAll, 0.5);
            Projection.From_To(net1, net1, new WeightSynapse(null, 0.1), ProjectionType.OneToOne, 0.8);
            var net = new Network();
            net.ChildNetworks.Add(net0.ID, net0);
            net.ChildNetworks.Add(net1.ID, net1);
            LoadNetwork(net);
            CellNet.ChildCellNet[net0.ID].Position = new Point3D(-15, 0, 15);
        }
예제 #5
0
        private void DoSimulation()
        {
            if (cfg != null && cfg.Exps != null)
            {
                //can have multiple combinations of model and solver, but always same conditions, different experiments, same simulation. For comparison.
                //if need separate N,dt, initial conditions, etc, use two different simulations
                for (int nSim = 0; nSim < cfg.Exps.Length; nSim++)
                {
                    //create model and solver
                    ODEModel  model  = Factory.MakeModel(cfg.Exps[nSim].Model);
                    ODESolver solver = Factory.MakeSolver(cfg.Exps[nSim].Solver);
                    //cfg.Simulations[nSim].Input;

                    //create simulation and setup
                    Simulation sim = new Simulation();
                    if (cfg.InputFromFile)
                    {
                        string[] u;
                        if (File.Exists(cfg.InputFileName))
                        {
                            List <string> lst = File.ReadAllLines(cfg.InputFileName).ToList <string>();
                            lst.RemoveAll((x) => { return(x == "" || x[0] == '%'); });
                            u = lst.ToArray();
                            sim.Setup(nSim, solver, model, cfg.x0, cfg.N, cfg.dt, u, cfg.ParamFileName);
                        }
                        else
                        {
                            MessageBox.Show("Input file not found");
                        }
                    }
                    else
                    {
                        sim.Setup(nSim, solver, model, cfg.x0, cfg.N, cfg.dt, cfg.u, cfg.ParamFileName);
                    }

                    //que simulation
                    simCtrl.Que(sim);
                }
            }
        }
예제 #6
0
 //  This method updates the velocity and location
 //  of the projectile using a 4th order Runge-Kutta
 //  solver to integrate the equations of motion.
 public override void UpdateLocationAndVelocity(double dt)
 {
     ODESolver.RungeKutta4(this, dt);
 }
예제 #7
0
 //  This method updates the velocity and position
 //  of the spring using a 4th order Runge-Kutta
 //  solver to integrate the equations of motion.
 public void UpdatePositionAndVelocity(double dt)
 {
     ODESolver.RungeKutta4(this, dt);
 }