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)); }
/// <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); }
public static IPendulum <T> AddRanking <T>(this IPendulum <T> p, Func <T, float> eval, float goal = 1) { p.Ranking.AddEval(eval, goal); return(p); }
public static IPendulum <T> WhenDone <T>(this IPendulum <T> p, Action whenDoneAction) { p.OnDoneActions.Add(whenDoneAction); return(p); }
public static IPendulum <T> AddConstrain <T>(this IPendulum <T> p, Func <bool> constrain) { p.Constrains.AddConstrain(constrain); return(p); }
public static IPendulum <T> SetSteps <T>(this IPendulum <T> p, int i) { p.Ranking.SetMaxSteps(i); return(p); }
public static IPendulum <T> AddDimension <T>(this IPendulum <T> p, IAxis <T> axis) { p.Modifications.AddModificationDimension(axis); return(p); }