public void Create2()
        {
            var randomDevice = new StdRandomDevice();
            var mt           = new StdMt19937(randomDevice);

            this.DisposeAndCheckDisposedState(randomDevice);
            this.DisposeAndCheckDisposedState(mt);
        }
Example #2
0
        private static void Main()
        {
            //generate dense graph with size N=5
            const uint n = 500;

            using var dense = new Dense <double>(n);

            //set interactions
            for (uint i = 0; i < n; i++)
            {
                for (uint j = 0; j < n; j++)
                {
                    dense.J[i, j] = (i == j) ? 0 : -1;
                }
            }

            //set local fields
            for (uint i = 0; i < n; i++)
            {
                dense.H[i] = -1;
            }

            //generate random engine (mersenne twister)
            using var randRngine = new StdMt19937(0x1234);

            //create classical Ising system
            using var system = OpenJij.MakeClassicalIsing(dense.GenSpin(randRngine), dense);

            //generate schedule list
            //from beta=0.1 to beta=100, 10 samples, 10 Monte Carlo step for each tempearature
            using var scheduleList = OpenJij.MakeClassicalScheduleList(0.1, 100, 10, 200);

            //do annealing (updater: SingleSpinFlip)
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            Algorithm <SingleSpinFlip <ClassicalIsing <Dense <double> > > > .Run(system, randRngine, scheduleList);

            stopWatch.Stop();

            double ticks = stopWatch.ElapsedTicks;
            double time  = (ticks / Stopwatch.Frequency) * 1000;

            Console.WriteLine($"time {time}[ms]");

            //show spins
            Console.Write("The result spins are [");
            foreach (var elem in Result.GetSolution(system))
            {
                Console.Write($"{elem} ");
            }

            Console.WriteLine("]");
        }
Example #3
0
        public Spins GenSpin(StdMt19937 randomNumderEngine)
        {
            if (randomNumderEngine == null)
            {
                throw new ArgumentNullException(nameof(randomNumderEngine));
            }

            randomNumderEngine.ThrowIfDisposed();
            this.ThrowIfDisposed();

            var spins = NativeMethods.graph_Graph_gen_spin_mt19937(this.NativePtr, randomNumderEngine.NativePtr);

            using (var vector = new StdVector <int>(spins))
                return(new Spins(vector.ToArray().Select(v => new Spin(v))));
        }
        public static void Run(Ising system, StdMt19937 randomNumberEngine, ScheduleList scheduleList)
        {
            if (system == null)
            {
                throw new ArgumentNullException(nameof(system));
            }
            if (randomNumberEngine == null)
            {
                throw new ArgumentNullException(nameof(randomNumberEngine));
            }
            if (scheduleList == null)
            {
                throw new ArgumentNullException(nameof(scheduleList));
            }

            system.ThrowIfDisposed();
            randomNumberEngine.ThrowIfDisposed();
            scheduleList.ThrowIfDisposed();

            if (!UpdaterElementTypesRepository.SupportTypes.TryGetValue(typeof(T), out var types))
            {
                throw new NotSupportedException($"{typeof(T).Name} does not support");
            }
            if (types.Item2 != system.IsingType)
            {
                throw new NotSupportedException($"{typeof(T).Name} supports only {system.IsingType}");
            }
            if (types.Item3 != system.GraphType)
            {
                throw new NotSupportedException($"{typeof(T).Name} supports only {system.GraphType}");
            }
            if (types.Item4 != system.FloatType)
            {
                throw new NotSupportedException($"{typeof(T).Name} supports only {system.FloatType}");
            }

            var updaterType = types.Item1;
            var ret         = NativeMethods.algorithm_Algorithm_run(updaterType,
                                                                    system.NativePtr,
                                                                    system.IsingType,
                                                                    system.GraphType,
                                                                    system.FloatType,
                                                                    randomNumberEngine.NativePtr,
                                                                    scheduleList.NativePtr);
        }
Example #5
0
 private static void Main(string[] args)
 {
     using var rd   = new StdRandomDevice();
     using var mt   = new StdMt19937(rd);
     using var dist = new StdUniformRealDistribution <double>(1.0, -1.0);
 }
        public void Create()
        {
            var mt = new StdMt19937(100);

            this.DisposeAndCheckDisposedState(mt);
        }