Ejemplo n.º 1
0
        public RealTester()
        {
            this.Tolerance = 1e-3;
            this.Attempts  = 5;

            var vars_1 = new[] { "x" };
            var vars_2 = new[] { "x", "y" };
            var vars_3 = new[] { "x", "y", "z" };

            RemoteFunction <double> f1 = new RealRemoteFunction(json: $"{TASKS_LOC}/Dummy/Dummy_1.json", port: 5001, field: "f");
            Dictionary <string, Tuple <double, double> > a1 = vars_1.ToDictionary(k => k, k => Tuple.Create(-10.0, 10.0));
            Dictionary <string, double> s1 = vars_1.ToDictionary(k => k, k => 0.0);

            RemoteFunction <double> f2 = new RealRemoteFunction(json: $"{TASKS_LOC}/Dummy/Dummy_2.json", port: 5002, field: "f");
            Dictionary <string, Tuple <double, double> > a2 = vars_2.ToDictionary(k => k, k => Tuple.Create(-10.0, 10.0));
            Dictionary <string, double> s2 = vars_2.ToDictionary(k => k, k => 0.0);

            RemoteFunction <double> f3 = new RealRemoteFunction(json: $"{TASKS_LOC}/Dummy/Dummy_3.json", port: 5003, field: "f");
            Dictionary <string, Tuple <double, double> > a3 = vars_3.ToDictionary(k => k, k => Tuple.Create(-10.0, 10.0));
            Dictionary <string, double> s3 = vars_3.ToDictionary(k => k, k => 0.0);

            this.TestFunctions = new[] { f1, f2, f3 };
            this.Areas         = new[] { a1, a2, a3 };
            this.Solutions     = new[] { s1, s2, s3 };
        }
Ejemplo n.º 2
0
 static RealVector RunRealVectorAlgorithm(
     Algorithm<RealVector, double, RealVector> algorithm,
     RealRemoteFunction f,
     Dictionary<string, Tuple<double, double>> area, string logStates)
 {
     f.Initialize();
     var result = algorithm.Work(x => f.Calculate(x), area, logStates);
     f.Terminate();
     return result;
 }
Ejemplo n.º 3
0
        public static void TestRealRemoteFunction()
        {
            var f = new RealRemoteFunction(json: $"{TASKS_LOC}/Dummy/Dummy_3.json", port: 5000, field: "f");

            f.Initialize();
            List <double> results = new List <double>();

            for (int i = 0; i < N; ++i)
            {
                var result = f.Calculate(new Dictionary <string, double>()
                {
                    { "x", 1.0 },
                    { "y", 2.0 },
                    { "z", 3.0 }
                });
                results.Add(result);
            }

            f.Terminate();

            Assert.True(results.TrueForAll(_ => _ == 36.0));
        }
Ejemplo n.º 4
0
        static void Body(Options opts)
        {
            var algConfig = JObject.Parse(File.ReadAllText(opts.AlgorithmConfig));
            var language = algConfig["language"].Value<string>();
            var name = algConfig["algorithm"].Value<string>();
            var logStates = opts.LogStates;
            if (string.Equals(logStates, "_none"))
                logStates = null;

            var taskConfig = JObject.Parse(File.ReadAllText(opts.TaskConfig));
            var area = new Dictionary<string, Tuple<Double, Double>>();
            foreach (var areaPart in taskConfig["area"])
            {
                area.Add(
                    areaPart["name"].Value<string>(),
                    Tuple.Create(areaPart["min"].Value<double>(), areaPart["max"].Value<double>()));
            }

            if (string.Equals(language, "CSharp") && (string.Equals(name, "RS") || string.Equals(name, "RandomSearch")))
            {
                var radius = algConfig["radius"].Value<double>();
                var maxTime = algConfig["maxTime"].Value<double>();
                var algorithm = Algorithms.CSharp.RandomSearch.CreateFixedStepRandomSearch(radius, maxTime);

                var f = new RealRemoteFunction(opts.TaskConfig, opts.Port, opts.Field);
                var result = RunRealVectorAlgorithm(algorithm, f, area, logStates);

                SaveRealVectorResult(result, opts);
                return;
            }

            if (string.Equals(language, "FSharp") && (string.Equals(name, "RS") || string.Equals(name, "RandomSearch")))
            {
                var radius = algConfig["radius"].Value<double>();
                var maxTime = algConfig["maxTime"].Value<double>();
                var algorithm = Algorithms.FSharp.RandomSearch.CreateFixedStepRandomSearch(radius, maxTime);

                var f = new RealRemoteFunction(opts.TaskConfig, opts.Port, opts.Field);
                var result = RunRealVectorAlgorithm(algorithm, f, area, logStates);

                SaveRealVectorResult(result, opts);
                return;
            }

            if (string.Equals(language, "CSharp") && (string.Equals(name, "DE") || string.Equals(name, "DifferentialEvolution")))
            {
                var populationSize = algConfig["populationSize"].Value<int>();
                var weightingFactor = algConfig["weightingFactor"].Value<double>();
                var crossoverRate = algConfig["crossoverRate"].Value<double>();
                var maxTime = algConfig["maxTime"].Value<double>();
                var algorithm = Algorithms.CSharp.DifferentialEvolution.CreateDifferentialEvolution(populationSize, weightingFactor, crossoverRate, maxTime);

                var f = new RealRemoteFunction(opts.TaskConfig, opts.Port, opts.Field);
                var result = RunRealVectorAlgorithm(algorithm, f, area, logStates);

                SaveRealVectorResult(result, opts);
                return;
            }

            throw new Exception("Unsupported Algorithm");
        }