Beispiel #1
0
        private static void CalculateSFNetworkDynamics()
        {
            Console.CursorLeft = 0;
            Console.WriteLine(" ");
            SFNetworkOscillator     nw       = new SFNetworkOscillator(100, 3, .65, 1, 10, -Math.PI, Math.PI, 0, .1, .001, 170302);
            Stopwatch               swGlobal = new Stopwatch();
            CancellationTokenSource ctSrc    = new CancellationTokenSource();
            Task task = new Task(() =>
            {
                Console.WriteLine("Time: {0:F5}\t0\t0", nw.Time);
                Stopwatch sw = new Stopwatch();
                while (!ctSrc.IsCancellationRequested)
                {
                    sw.Restart();
                    nw.SimulateDynamicStep();
                    sw.Stop();
                    swGlobal.Stop();
                    Console.WriteLine("Time: {0:F5}\t{1}\t{2}", nw.Time, sw.Elapsed, swGlobal.Elapsed);
                    swGlobal.Start();
                }
                swGlobal.Stop();
                Console.WriteLine("Calculating finished in {0}\n{1} states calculated from t={2} to t={3}", swGlobal.Elapsed, nw.States.Count, nw.States[0].Time, nw.Time);
                string path = "SFNetworkOscillator_" + nw.Nodes.Count + "_" + nw.Multiplier + "_" + nw.Strength + "_" + nw.FrequenciesInitMin + "_" + nw.FrequenciesInitMax + "_" + nw.PhasesInitMin + "_" + nw.PhasesInitMax + "_" + nw.TimeInit + "_" + nw.TimeStep + "_" + nw.SolveStep + "_" + nw.RandomSeed + "_" + nw.States.Count + ".sfnwosc";
                nw.Serialize(path);
                Console.WriteLine("Serializing finished successfully!\nNetwork saved by path: {0}\nFile size: {1} bytes", path, new FileInfo(path).Length);
            }, ctSrc.Token);

            task.Start();
            swGlobal.Start();

            bool cliStop = false;

            while (!cliStop)
            {
                string s = Console.ReadLine();
                if (s == "stop")
                {
                    ctSrc.Cancel();
                }
            }
        }
        static void Main(string[] args)
        {
            SFNetworkOscillator nw = new SFNetworkOscillator(75, 3, 0.3, 1, 10, -Math.PI, Math.PI, 0, 0.1, 0.005, 626);
            Stopwatch           sw = new Stopwatch();

            for (int i = 0; i < 300; i++)
            {
                sw.Restart();
                nw.SimulateDynamicStep();
                Console.WriteLine(sw.ElapsedMilliseconds);
            }
            nw.Serialize("cs_network_dynamics_check");
            return;

            string s = "";

            for (int i = 0; i < nw.Phases.Length; i++)
            {
                s += nw.Phases[i] + "\n";
            }
            File.WriteAllText("cs_network_check_dynamics", s);
        }