Exemple #1
0
        } // Main(...)

        static ICollection <CheetahCurve> EvaluationOnTheFirstApplicationOfConstraint(ICheetahSolver solver,
                                                                                      CheetahDataSet dataSet)
        {
            // 1. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            // 2. Initializing parametric object using data set
            // On this step we are compiling the model and creating system of equation
            // After that we will be ready to run the solver
            if (!parametric.Init(dataSet, null, null))
            {
                // If parametric.Init will return FALSE, then there is critical error in the data set
                // So we are not able to make system of equation and to evaluate the problem
                // We should cancel the procedure and rebuild data set
                throw new Exception("Something goes wrong");
            }

            // 3. Regenerating constrained model (running solver)
            // On this step we are solving the system of equation, that we've made in the previous step
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 4. Retrieving results
            var resultGeometry = parametric.GetSolution(true);

            // 5. We have to clear compiled data
            parametric.ClearSolver();

            return(resultGeometry);
        } // EvaluationOnTheFirstApplicationOfConstraint(...)
Exemple #2
0
        static void Main(string[] args)
        {
            // 1. Creating geometric model

            var dataSet = new CheetahDataSet();

            var entIdList = new List <long>();

            CreateGeometricModel(dataSet, entIdList);

            // 2. Creating solver object
            var solver = new SolverCpu10();

            // 3. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false);

            const double precision = 1E-15; // Working with much better accuracy then the default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 4. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
            {
                throw new Exception("Something goes wrong");
            }

            // 5. Running constraints solver
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 6. Retrieving results (we created rectangle with fillets that is "closest" to the initial lines and arcs)
            var resultGeometry = parametric.GetSolution(true);

            // 7. Checking that all geometric constraints are satisfied.
            //    Actually, we have no need to check - if Evaluate returns true than everything is OK
            if (!CheckResults(resultGeometry, entIdList, precision))
            {
                throw new Exception("Something goes wrong");
            }

            GC.Collect();
        } // Main(...)
        static void Main(string[] args)
        {
            const string filePath = "dataset.xml";

            // 1. Creating entities and constraints (constraints are not satisfied yet)
            var dataSet = CreateDataSet();

            // 2. Saving data set to xml-file
            dataSet.SaveToXml(filePath);

            // 3. Loading data set from xml-file
            var dataSetFromFile = CheetahDataSet.LoadFromXml(filePath);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-8; // Working with lower accuracy then default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSetFromFile, null, null))
            {
                throw new Exception("Something goes wrong");
            }

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            GC.Collect();
        } // Main(...)
        static void Main(string[] args)
        {
            // 1. Creating geometric model

            var dataSet = new CheetahDataSet();

            var entIdList = new List<long>();

            CreateGeometricModel(dataSet, entIdList);

            // 2. Creating solver object
            var solver = new SolverCpu10();

            // 3. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false);

            const double precision = 1E-15; // Working with much better accuracy then the default 1E-12 

            CheetahParametricBasic.Settings.Precision = precision;

            // 4. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
                throw new Exception("Something goes wrong");

            // 5. Running constraints solver
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 6. Retrieving results (we created rectangle with fillets that is "closest" to the initial lines and arcs)
            var resultGeometry = parametric.GetSolution(true);

            // 7. Checking that all geometric constraints are satisfied.
            //    Actually, we have no need to check - if Evaluate returns true than everything is OK
            if (!CheckResults(resultGeometry, entIdList, precision))
                throw new Exception("Something goes wrong");

            GC.Collect();
            
        } // Main(...)
        static void Main(string[] args)
        {
            const string filePath = "dataset.xml";

            // 1. Creating entities and constraints (constraints are not satisfied yet)
            var dataSet = CreateDataSet();

            // 2. Saving data set to xml-file
            dataSet.SaveToXml(filePath);

            // 3. Loading data set from xml-file
            var dataSetFromFile = CheetahDataSet.LoadFromXml(filePath);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-8; // Working with lower accuracy then default 1E-12 

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSetFromFile, null, null))
                throw new Exception("Something goes wrong");

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            GC.Collect();

        } // Main(...)
        } // Main(...)

        static ICollection<CheetahCurve> EvaluationOnTheFirstApplicationOfConstraint(ICheetahSolver solver, 
                                                                                     CheetahDataSet dataSet)
        {
            // 1. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            // 2. Initializing parametric object using data set
            // On this step we are compiling the model and creating system of equation
            // After that we will be ready to run the solver
            if (!parametric.Init(dataSet, null, null))
                // If parametric.Init will return FALSE, then there is critical error in the data set
                // So we are not able to make system of equation and to evaluate the problem
                // We should cancel the procedure and rebuild data set
                throw new Exception("Something goes wrong");

            // 3. Regenerating constrained model (running solver)
            // On this step we are solving the system of equation, that we've made in the previous step
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 4. Retrieving results
            var resultGeometry = parametric.GetSolution(true);

            // 5. We have to clear compiled data
            parametric.ClearSolver();

            return resultGeometry;
            
        } // EvaluationOnTheFirstApplicationOfConstraint(...)
        } // EvaluationOnTheFirstApplicationOfConstraint(...)

        static ICollection<CheetahCurve> EvaluationOnDragginTheLine(ICheetahSolver solver, CheetahDataSet dataSet, 
                                                                    CheetahLine2D draggingLine, CheetahPoint2D draggingPoint)
        {
            // 1. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            // 2. Initializing parametric object using data set
            // On this step we are compiling the model and creating system of equation
            // After that we will be ready to run the solver
            // We will drag the line, so we need to specify the curve to drag and the dragging point
            if (!parametric.Init(dataSet, new[] { draggingLine }, new[] { draggingPoint }))
                // If parametric.Init will return FALSE, then there is critical error in data set
                // So we are not able to make system of equation and to evaluate the problem
                // We should cancel the procedure and rebuild data set
                throw new Exception("Something goes wrong");

            // 3. Now we can drag. We don't need to recompile the model on each drag iteration,
            // because the model will be the same - only initial value (the drag point) will be changed
            // We are simulating drag using this loop
            for (var i = 0; i < 100; i++)
            {
                // 4. Our parametric object is initialized by dataSet object
                // So the current values of the dataSet curves are the initial values of the system
                // If we will change some value - the initial values will be changed appropriately
                // All that we need to reinitialize the model by the new point from the screen 
                // is to reset the value for the dragging line end point
                draggingLine.End.X *= 1.01;
                draggingLine.End.Y *= 1.05;

                // 5. Regenerating constrained model (running solver)
                // On this step we are solving the system of equation, that we've prepared on the previous step
                // Now we are dragging the curve and, because we do it manually (by mouse), we can not be precise 
                // We don't need to calculate on each step with 10^-12 or greater precision
                // So we can cheat a little and decrease the precision for drag iterations
                // That's why we are using parametric.EvaluateFast function
                if (!parametric.EvaluateFast())
                    // If parametric.EvaluateFast will return FALSE it usually means that we can not evaluate the system 
                    // with this initial values (we have reached maximum number of iterations)/
                    // It is NOT a critical problem. This situation can appear while we drag some curve 
                    // in position that conflict with constraints/
                    // For example, while we rounding out the arc and can get negative radius, 
                    // or squeeze the line to zero length (and get negative length)
                    // In our solver, if we have such a situation - we restore the previous drag iteration solution.
                    throw new Exception("Something goes wrong");
                    
                // In this example we don't use results of EvaluateFast/
                // In real life they may be retreived and used to update dragging lines on the screen
            }

            // 6. Regenerating constrained model (running solver)
            // Now we "click the mouse button" to end the drag.
            // We need to evaluate the system with high precision (that's why we use Evaluate instead of EvaluateFast)
            // We can use last iteration solution as new initial value to evaluate the system much faster
            // (for this purpose we set recompile parameter to false)
            if (!parametric.Evaluate(false))
                throw new Exception("Something goes wrong");

            // 7. Retrieving results
            var resultGeometry = parametric.GetSolution(true);

            // 8. We have to clear compiled data
            parametric.ClearSolver();

            return resultGeometry;
            
        } // EvaluationOnDragginTheLine(...)
Exemple #8
0
        } // EvaluationOnTheFirstApplicationOfConstraint(...)

        static ICollection <CheetahCurve> EvaluationOnDragginTheLine(ICheetahSolver solver, CheetahDataSet dataSet,
                                                                     CheetahLine2D draggingLine, CheetahPoint2D draggingPoint)
        {
            // 1. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            // 2. Initializing parametric object using data set
            // On this step we are compiling the model and creating system of equation
            // After that we will be ready to run the solver
            // We will drag the line, so we need to specify the curve to drag and the dragging point
            if (!parametric.Init(dataSet, new[] { draggingLine }, new[] { draggingPoint }))
            {
                // If parametric.Init will return FALSE, then there is critical error in data set
                // So we are not able to make system of equation and to evaluate the problem
                // We should cancel the procedure and rebuild data set
                throw new Exception("Something goes wrong");
            }

            // 3. Now we can drag. We don't need to recompile the model on each drag iteration,
            // because the model will be the same - only initial value (the drag point) will be changed
            // We are simulating drag using this loop
            for (var i = 0; i < 100; i++)
            {
                // 4. Our parametric object is initialized by dataSet object
                // So the current values of the dataSet curves are the initial values of the system
                // If we will change some value - the initial values will be changed appropriately
                // All that we need to reinitialize the model by the new point from the screen
                // is to reset the value for the dragging line end point
                draggingLine.End.X *= 1.01;
                draggingLine.End.Y *= 1.05;

                // 5. Regenerating constrained model (running solver)
                // On this step we are solving the system of equation, that we've prepared on the previous step
                // Now we are dragging the curve and, because we do it manually (by mouse), we can not be precise
                // We don't need to calculate on each step with 10^-12 or greater precision
                // So we can cheat a little and decrease the precision for drag iterations
                // That's why we are using parametric.EvaluateFast function
                if (!parametric.EvaluateFast())
                {
                    // If parametric.EvaluateFast will return FALSE it usually means that we can not evaluate the system
                    // with this initial values (we have reached maximum number of iterations)/
                    // It is NOT a critical problem. This situation can appear while we drag some curve
                    // in position that conflict with constraints/
                    // For example, while we rounding out the arc and can get negative radius,
                    // or squeeze the line to zero length (and get negative length)
                    // In our solver, if we have such a situation - we restore the previous drag iteration solution.
                    throw new Exception("Something goes wrong");
                }

                // In this example we don't use results of EvaluateFast/
                // In real life they may be retreived and used to update dragging lines on the screen
            }

            // 6. Regenerating constrained model (running solver)
            // Now we "click the mouse button" to end the drag.
            // We need to evaluate the system with high precision (that's why we use Evaluate instead of EvaluateFast)
            // We can use last iteration solution as new initial value to evaluate the system much faster
            // (for this purpose we set recompile parameter to false)
            if (!parametric.Evaluate(false))
            {
                throw new Exception("Something goes wrong");
            }

            // 7. Retrieving results
            var resultGeometry = parametric.GetSolution(true);

            // 8. We have to clear compiled data
            parametric.ClearSolver();

            return(resultGeometry);
        } // EvaluationOnDragginTheLine(...)
        static void Main(string[] args)
        {
            // 1. Creating data set
            var dataSet = new CheetahDataSet();

            // 2. Creating geometry
            var line1 = new CheetahLine2D(0, 0, 10, 1);
            var line2 = new CheetahLine2D(10, 0, 10, 11);
            var line3 = new CheetahLine2D(10, 10, 1, 10);
            var line4 = new CheetahLine2D(0, 10, 1, 1);

            // 3. Creating constraints
            dataSet.AddCoincidence(line1, IdentifiableValueReferences.LineEnd,
                                   line2, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line2, IdentifiableValueReferences.LineEnd,
                                   line3, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line3, IdentifiableValueReferences.LineEnd,
                                   line4, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line4, IdentifiableValueReferences.LineEnd,
                                   line1, IdentifiableValueReferences.LineStart);

            dataSet.AddPerpendicular(line1, line2);
            dataSet.AddPerpendicular(line2, line3);

            dataSet.AddParallel(line2, line4);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-14; // Working with better accuracy then default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
            {
                throw new Exception("Something goes wrong");
            }

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            // 9. We can find corresponding objects by id
            var resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            var resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);
            var resultLine3 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line3.Id);
            var resultLine4 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line4.Id);

            // 10. Now we can check that all constraints are satisfied (line segments form rectangle)

            if (Math.Abs(resultLine1.End.X - resultLine2.Start.X) > precision || Math.Abs(resultLine1.End.Y - resultLine2.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }
            if (Math.Abs(resultLine2.End.X - resultLine3.Start.X) > precision || Math.Abs(resultLine2.End.Y - resultLine3.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }
            if (Math.Abs(resultLine3.End.X - resultLine4.Start.X) > precision || Math.Abs(resultLine3.End.Y - resultLine4.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }
            if (Math.Abs(resultLine4.End.X - resultLine1.Start.X) > precision || Math.Abs(resultLine4.End.Y - resultLine1.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }

            if (!IsDivisible(resultLine1.PolarAngle - resultLine2.PolarAngle, Math.PI / 2, precision))
            {
                throw new Exception("Something goes wrong");
            }
            if (!IsDivisible(resultLine2.PolarAngle - resultLine3.PolarAngle, Math.PI / 2, precision))
            {
                throw new Exception("Something goes wrong");
            }

            if (!IsDivisible(resultLine2.PolarAngle - resultLine4.PolarAngle, Math.PI, precision))
            {
                throw new Exception("Something goes wrong");
            }

            GC.Collect();
        } // Main(...)
        static void Main(string[] args)
        {
            // 1. Creating data set
            var dataSet = new CheetahDataSet();

            // 2. Creating geometry
            var line1 = new CheetahLine2D(0, 0, 10, 1);
            var line2 = new CheetahLine2D(10, 0, 10, 11);
            var line3 = new CheetahLine2D(10, 10, 1, 10);
            var line4 = new CheetahLine2D(0, 10, 1, 1);

            // 3. Creating constraints
            dataSet.AddCoincidence(line1, IdentifiableValueReferences.LineEnd,
                line2, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line2, IdentifiableValueReferences.LineEnd,
                line3, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line3, IdentifiableValueReferences.LineEnd,
                line4, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line4, IdentifiableValueReferences.LineEnd,
                line1, IdentifiableValueReferences.LineStart);

            dataSet.AddPerpendicular(line1, line2);
            dataSet.AddPerpendicular(line2, line3);

            dataSet.AddParallel(line2, line4);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-14; // Working with better accuracy then default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
                throw new Exception("Something goes wrong");

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            // 9. We can find corresponding objects by id
            var resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            var resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);
            var resultLine3 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line3.Id);
            var resultLine4 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line4.Id);

            // 10. Now we can check that all constraints are satisfied (line segments form rectangle)

            if (Math.Abs(resultLine1.End.X - resultLine2.Start.X) > precision || Math.Abs(resultLine1.End.Y - resultLine2.Start.Y) > precision)
                throw new Exception("Something goes wrong");
            if (Math.Abs(resultLine2.End.X - resultLine3.Start.X) > precision || Math.Abs(resultLine2.End.Y - resultLine3.Start.Y) > precision)
                throw new Exception("Something goes wrong");
            if (Math.Abs(resultLine3.End.X - resultLine4.Start.X) > precision || Math.Abs(resultLine3.End.Y - resultLine4.Start.Y) > precision)
                throw new Exception("Something goes wrong");
            if (Math.Abs(resultLine4.End.X - resultLine1.Start.X) > precision || Math.Abs(resultLine4.End.Y - resultLine1.Start.Y) > precision)
                throw new Exception("Something goes wrong");

            if (!IsDivisible(resultLine1.PolarAngle - resultLine2.PolarAngle, Math.PI / 2, precision))
                throw new Exception("Something goes wrong");
            if (!IsDivisible(resultLine2.PolarAngle - resultLine3.PolarAngle, Math.PI / 2, precision))
                throw new Exception("Something goes wrong");

            if (!IsDivisible(resultLine2.PolarAngle - resultLine4.PolarAngle, Math.PI, precision))
                throw new Exception("Something goes wrong");

            GC.Collect();

        } // Main(...)