public static IEnumerable <R> Start <R>(this IPendulum <R> p)
 {
     while (!p.Ranking.IsOptimized())
     {
         yield return(p.GetExec().Execute());
     }
 }
        public static R Execute <R>(this IPendulum <R> p)
        {
            p.Modifications.MapModifications();

            var optimized = p.Ranking.IsOptimized();
            var constrain = p.Constrains.TestConstrains();

            var rng    = new Random();
            var mods   = p.Modifications.GetModificationCount();
            var modNum = 0;

            p.Ranking.Reset();

            while (p.Ranking.HasStepsLeft())
            {
                // Bruteforce-like Strategy
                p.Modifications.PerformModification(modNum);

                p.GetExec().Result = p.GetExec().Execute();
                p.Ranking.Evaluate();

                optimized = p.Ranking.IsOptimized();
                constrain = p.Constrains.TestConstrains();

                if (optimized && constrain)
                {
                    break;
                }

                if (!constrain)
                {
                    modNum = rng.Next(0, mods);
                }
            }

            p.OnDoneActions.ForEach(x => x());

            return(default(R));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create base scene
        /// </summary>
        private void InitializeScene()
        {
            WindDirectionScene.Camera = SimulationScene.Camera;

            cartTrajectoryLines           = new LinesVisual3D();
            cartTrajectoryLines.Thickness = 3;
            cartTrajectoryLines.Color     = Colors.Blue;
            cartTrajectoryLines.Points    = cartTrajectoryPoints;
            SimulationScene.Children.Add(cartTrajectoryLines);

            pendulumTrajectoryLines           = new LinesVisual3D();
            pendulumTrajectoryLines.Thickness = 3;
            pendulumTrajectoryLines.Color     = Colors.Gold;
            pendulumTrajectoryLines.Points    = pendulumTrajectoryPoints;
            SimulationScene.Children.Add(pendulumTrajectoryLines);

            targetTrajectoryLines           = new LinesVisual3D();
            targetTrajectoryLines.Thickness = 3;
            targetTrajectoryLines.Color     = Colors.Red;
            targetTrajectoryLines.Points    = targetTrajectoryPoints;

            targetTrajectoryCheckPoints        = new PointsVisual3D();
            targetTrajectoryCheckPoints.Color  = Colors.Purple;
            targetTrajectoryCheckPoints.Size   = 5;
            targetTrajectoryCheckPoints.Points = targetTrajectoryPoints;

            simulationArea = new SimulationArea();
            SimulationScene.Children.Add(simulationArea.Model);
            models.Add(simulationArea);

            cart = new Cart();
            SimulationScene.Children.Add(cart.Model);
            models.Add(cart);

            pendulum = new Pendulum();
            SimulationScene.Children.Add(pendulum.Model);
            models.Add(pendulum);
        }
Exemplo n.º 4
0
 public static IPendulum <T> AddRanking <T>(this IPendulum <T> p, Func <T, float> eval, float goal = 1)
 {
     p.Ranking.AddEval(eval, goal);
     return(p);
 }
Exemplo n.º 5
0
 public static IPendulum <T> WhenDone <T>(this IPendulum <T> p, Action whenDoneAction)
 {
     p.OnDoneActions.Add(whenDoneAction);
     return(p);
 }
Exemplo n.º 6
0
 public static IPendulum <T> AddConstrain <T>(this IPendulum <T> p, Func <bool> constrain)
 {
     p.Constrains.AddConstrain(constrain);
     return(p);
 }
Exemplo n.º 7
0
 public static IPendulum <T> SetSteps <T>(this IPendulum <T> p, int i)
 {
     p.Ranking.SetMaxSteps(i);
     return(p);
 }
Exemplo n.º 8
0
 public static IPendulum <T> AddDimension <T>(this IPendulum <T> p, IAxis <T> axis)
 {
     p.Modifications.AddModificationDimension(axis);
     return(p);
 }