Beispiel #1
0
        public static Dictionary <string, object> Execute(
            DynaShape.Solver solver,
            List <Goal> goals,
            [DefaultArgument("null")] List <GeometryBinder> geometryBinders,
            [DefaultArgument("0")] int iterations,
            [DefaultArgument("true")] bool reset,
            [DefaultArgument("true")] bool execute,
            [DefaultArgument("true")] bool enableMomentum,
            [DefaultArgument("true")] bool enableFastDisplay,
            [DefaultArgument("false")] bool enableManipulation)
        //int mode = 0)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            if (reset)
            {
                solver.StopBackgroundExecution();
                solver.Clear();
                solver.AddGoals(goals);
                if (geometryBinders != null)
                {
                    solver.AddGeometryBinders(geometryBinders);
                }
                solver.Display.Render();
            }
            else
            {
                solver.EnableMouseInteraction = enableManipulation;
                solver.EnableMomentum         = enableMomentum;
                solver.EnableFastDisplay      = enableFastDisplay;
                solver.IterationCount         = iterations;
                solver.Mode = 0;


                if (execute)
                {
                    solver.StartBackgroundExecution();
                }
                else
                {
                    solver.StopBackgroundExecution();
                    if (!enableFastDisplay)
                    {
                        solver.Iterate();
                    }
                }
            }

            return(enableFastDisplay
               ? null
               : new Dictionary <string, object> {
                { "nodePositions", solver.GetStructuredNodePositionsAsPoints() },
                { "goalOutputs", solver.GetGoalOutputs() },
                { "geometries", solver.GetGeometries() }
            });
        }
Beispiel #2
0
        public static Dictionary <string, object> ExecuteSilently(
            DynaShape.Solver solver,
            List <Goal> goals,
            [DefaultArgument("null")] List <GeometryBinder> geometryBinders,
            [DefaultArgument("10000")] int iterations,
            [DefaultArgument("0.001")] double threshold,
            [DefaultArgument("true")] bool execute,
            [DefaultArgument("true")] bool enableMomentum)
        {
            if (!execute)
            {
                return(null);
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            solver.Clear();
            solver.AddGoals(goals);
            solver.AddGeometryBinders(geometryBinders);
            solver.Execute(iterations, threshold);

            TimeSpan computationTime = stopwatch.Elapsed;

            stopwatch.Restart();

            return(new Dictionary <string, object> {
                { "nodePositions", solver.GetStructuredNodePositionsAsPoints() },
                { "goalOutputs", solver.GetGoalOutputs() },
                { "geometries", solver.GetGeometries() },
                { "stats", String.Concat(
                      "Computation Time: " + computationTime,
                      "\nData Output Time: " + stopwatch.Elapsed,
                      "\nIterations      : " + solver.CurrentIteration,
                      "\nMovement        : " + solver.GetKineticEnergy()) }
            });
        }