Пример #1
0
        public void TestOptimizationProblemContext()
        {
            var in1                = new ContinuousDimension("in_1", 0, 10);
            var in2                = new DiscreteDimension("in_2", 1, 20);
            var inputHypergrid     = new Hypergrid("input", in1, in2);
            var out1               = new ContinuousDimension("out_1", -5, 7);
            var objectiveHypergrid = new Hypergrid("output", out1);
            var context1           = new DiscreteDimension("ctx_1", -100, -0);
            var contextHypergrid   = new Hypergrid("context", context1);
            var objectives         = new OptimizationObjective[]
            {
                new OptimizationObjective("out_1", true),
                new OptimizationObjective("nonExistent", false),
            };
            var optimizationProblem = new OptimizationProblem(inputHypergrid, contextHypergrid, objectiveHypergrid, objectives);
            var serialized          = OptimizerServiceEncoder.EncodeOptimizationProblem(optimizationProblem);
            var deserialized        = OptimizerServiceDecoder.DecodeOptimizationProblem(serialized);

            Assert.Equal(optimizationProblem.ParameterSpace.Name, deserialized.ParameterSpace.Name);
            Assert.Equal(optimizationProblem.ObjectiveSpace.Name, deserialized.ObjectiveSpace.Name);
            Assert.Equal(optimizationProblem.ContextSpace.Name, deserialized.ContextSpace.Name);

            Assert.Equal(optimizationProblem.Objectives[0].Name, objectives[0].Name);
            Assert.Equal(optimizationProblem.Objectives[0].Minimize, objectives[0].Minimize);
            Assert.Equal(optimizationProblem.Objectives[1].Name, objectives[1].Name);
            Assert.Equal(optimizationProblem.Objectives[1].Minimize, objectives[1].Minimize);

            // This is not a rigorous test but it should be sufficient given the other tests in this set.
            Assert.Equal(optimizationProblem.ParameterSpace.Dimensions[0].Name, deserialized.ParameterSpace.Dimensions[0].Name);
            Assert.Equal(optimizationProblem.ParameterSpace.Dimensions[1].Name, deserialized.ParameterSpace.Dimensions[1].Name);
            Assert.Equal(optimizationProblem.ObjectiveSpace.Dimensions[0].Name, deserialized.ObjectiveSpace.Dimensions[0].Name);
            Assert.Equal(optimizationProblem.ContextSpace.Dimensions[0].Name, deserialized.ContextSpace.Dimensions[0].Name);
        }
 public static OptimizerService.DiscreteDimension EncodeDiscreteDimension(DiscreteDimension dimension)
 {
     return(new OptimizerService.DiscreteDimension
     {
         Name = dimension.Name,
         Min = dimension.Min,
         Max = dimension.Max,
     });
 }
Пример #3
0
        public void TestDiscreteDimension()
        {
            var dimension    = new DiscreteDimension("_%% \n \t \\//", long.MinValue, long.MaxValue);
            var serialized   = OptimizerServiceEncoder.EncodeDiscreteDimension(dimension);
            var deserialized = OptimizerServiceDecoder.DecodeDiscreteDimension(serialized);

            Assert.Equal(deserialized.Name, dimension.Name);
            Assert.Equal(deserialized.Min, dimension.Min);
            Assert.Equal(deserialized.Max, dimension.Max);
        }
        private void Awake()
        {
            m_Car = GetComponent <CarController>();

            inputSpeed    = new ContinuousDimension("", "", "", -100, 180);
            backwardSpeed = new RightQuadraticSet(inputSpeed, "", -100, -10, 0);
            zeroSpeed     = new BellSet(inputSpeed, "", 0, 5, 10);
            lowSpeed      = new QuadraticSet(inputSpeed, "", 10, 40, 0, 50, 5, 45);
            //private FuzzySet medSpeed;
            highSpeed = new LeftQuadraticSet(inputSpeed, "", 40, 45, 50);


            inputSideBoundDistance = new ContinuousDimension("", "", "", -10, 10);
            dangerousRight         = new LeftQuadraticSet(inputSideBoundDistance, "", 0, 9, 10);
            dangerousLeft          = new RightQuadraticSet(inputSideBoundDistance, "", -10, -9, 0);
            safe = new TrapezoidalSet(inputSideBoundDistance, "", -5, 5, -7, 7);


            inputFrontBoundDistance = new ContinuousDimension("", "", "", 0, 150);
            far            = new LeftLinearSet(inputFrontBoundDistance, "", 20, 40);
            close          = new TrapezoidalSet(inputFrontBoundDistance, "", 15, 20, 10, 25);
            dangerousClose = new RightLinearSet(inputFrontBoundDistance, "", 10, 15);


            outputGas    = new ContinuousDimension("", "", "", -100, 100);
            pedalToMetal = new LeftQuadraticSet(outputGas, "", 0, 80, 100);
            clutch       = new SingletonSet(outputGas, "", 0);
            brake        = new RightLinearSet(outputGas, "", -100, 0);


            outputBrakes = new ContinuousDimension("", "", "", 0, 1);


            outputAction = new DiscreteDimension("", "");


            outputSteeringWheel = new ContinuousDimension("", "", "", -100, 100);
            turnLeft            = new RightLinearSet(outputSteeringWheel, "", -100, 0);
            turnRight           = new LeftLinearSet(outputSteeringWheel, "", 0, 100);
            forward             = new TriangularSet(outputSteeringWheel, "", 0, -10, 10);


            simpleSteeringRules =
                (dangerousLeft & turnRight) |
                (dangerousRight & turnLeft) |
                (safe & forward);

            simpleGasRules =
                (far & pedalToMetal) |
                ((close & lowSpeed) & clutch) |
                ((close & highSpeed) & brake) |
                ((close & zeroSpeed) & brake) |
                (dangerousClose & brake);
        }
Пример #5
0
        public TestSerializingAndDeserializing()
        {
            /* FIXME: This needs better cross-plat support and error handling.
             * - We should include C:\Python37 as another PYTHONHOME location to look for by default
             * - Currently this doesn't handle Linux very well
             * - On Ubuntu Python 3.7 needs to be installed from a separate
             *   repo, which installs as libpython3.7m.so which fails tobe
             *   found due to the trailing "m".
             */

            string pathToVirtualEnv = Environment.GetEnvironmentVariable("PYTHONHOME");

            if (string.IsNullOrEmpty(pathToVirtualEnv))
            {
                pathToVirtualEnv = @"c:\ProgramData\Anaconda3";
            }
            else
            {
                Environment.SetEnvironmentVariable("PYTHONHOME", pathToVirtualEnv, EnvironmentVariableTarget.Process);
            }

            string pathToPythonPkg = $"{pathToVirtualEnv}\\pkgs\\python-3.7.4-h5263a28_0";

            Environment.SetEnvironmentVariable("PATH", $"{pathToVirtualEnv};{pathToPythonPkg}", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("PYTHONPATH", $"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib", EnvironmentVariableTarget.Process);

            continuous = new ContinuousDimension(name: "continuous", min: 1, max: 10);
            discrete   = new DiscreteDimension(name: "discrete", min: 1, max: 10);
            ordinal    = new OrdinalDimension(name: "ordinal", orderedValues: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            }, ascending: true);
            categorical = new CategoricalDimension(name: "categorical", values: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            });
            allKindsOfDimensions = new Hypergrid(
                name: "all_kinds_of_dimensions",
                dimensions: new IDimension[]
            {
                continuous,
                discrete,
                ordinal,
                categorical,
            });
        }
Пример #6
0
        public void TestOptimizationProblemNoContext()
        {
            var in1                = new ContinuousDimension("in_1", 0, 10);
            var in2                = new DiscreteDimension("in_2", 1, 20);
            var inputHypergrid     = new Hypergrid("input", in1, in2);
            var out1               = new ContinuousDimension("out_1", -5, 7);
            var objectiveHypergrid = new Hypergrid("output", out1);
            var objectives         = new OptimizationObjective[]
            {
                new OptimizationObjective("out_1", true),
                new OptimizationObjective("nonExistent", false),
            };
            var optimizationProblem = new OptimizationProblem(inputHypergrid, objectiveHypergrid, objectives);
            var serialized          = OptimizerServiceEncoder.EncodeOptimizationProblem(optimizationProblem);
            var deserialized        = OptimizerServiceDecoder.DecodeOptimizationProblem(serialized);

            Assert.Null(deserialized.ContextSpace);
        }
Пример #7
0
        public TestSerializingAndDeserializing()
        {
            string pathToVirtualEnv = Environment.GetEnvironmentVariable("PYTHONHOME");

            if (string.IsNullOrEmpty(pathToVirtualEnv))
            {
                pathToVirtualEnv = @"c:\ProgramData\Anaconda3";
            }
            else
            {
                Environment.SetEnvironmentVariable("PYTHONHOME", pathToVirtualEnv, EnvironmentVariableTarget.Process);
            }

            string pathToPythonPkg = $"{pathToVirtualEnv}\\pkgs\\python-3.7.4-h5263a28_0";

            Environment.SetEnvironmentVariable("PATH", $"{pathToVirtualEnv};{pathToPythonPkg}", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("PYTHONPATH", $"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib", EnvironmentVariableTarget.Process);

            continuous = new ContinuousDimension(name: "continuous", min: 1, max: 10);
            discrete   = new DiscreteDimension(name: "discrete", min: 1, max: 10);
            ordinal    = new OrdinalDimension(name: "ordinal", orderedValues: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            }, ascending: true);
            categorical = new CategoricalDimension(name: "categorical", values: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            });
            allKindsOfDimensions = new SimpleHypergrid(
                name: "all_kinds_of_dimensions",
                dimensions: new List <IDimension>()
            {
                continuous,
                discrete,
                ordinal,
                categorical,
            });
        }