//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: protected void assertInputs(final Minimizer<java.util.function.Function<com.opengamma.strata.collect.array.DoubleArray, double>, com.opengamma.strata.collect.array.DoubleArray> minimizer)
        protected internal virtual void assertInputs(Minimizer <System.Func <DoubleArray, double>, DoubleArray> minimizer)
        {
            try
            {
                minimizer.minimize(null, DoubleArray.of(2d, 3d));
                Assert.fail();
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final IllegalArgumentException e)
            catch (legalArgumentException)
            {
                // Expected
            }
            try
            {
                minimizer.minimize(F_2D, null);
                Assert.fail();
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final IllegalArgumentException e)
            catch (legalArgumentException)
            {
                // Expected
            }
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: AndreyShp/StudyFun
        protected void Application_Start()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Initialize your application
            WebSettingsConfig.Instance.SetDeferredSettings(webSettingsConfig => {
                ISalesSettings salesSettings = webSettingsConfig.GetSalesSettings(SectionId.VisualDictionary);
                if (salesSettings == null)
                {
                    return;
                }

                long languageId          = WebSettingsConfig.Instance.GetLanguageFromId();
                var representationsQuery = new RepresentationsQuery(languageId);

                List <SalesItemForUser> allSalesItems =
                    representationsQuery.GetForSales(WebSettingsConfig.Instance.DefaultUserLanguages,
                                                     salesSettings);
                var salesCalculator             = new SalesCalculator(allSalesItems, allSalesItems, salesSettings.Discount);
                salesSettings.SummDiscountPrice = salesCalculator.SummDiscountPrice;
            }, webSettingsConfig => {
                //кладем в кэш файл sitemap.xml
                SitemapFileGenerator.Generate(false);
            }, webSettingsConfig => {
                //подчистить старые файлы js/css
                Minimizer.DeleteOldFiles(webSettingsConfig.WebPath);
            });
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: protected void assertMinimizer(final Minimizer<java.util.function.Function<com.opengamma.strata.collect.array.DoubleArray, double>, com.opengamma.strata.collect.array.DoubleArray> minimizer, final double tol)
        protected internal virtual void assertMinimizer(Minimizer <System.Func <DoubleArray, double>, DoubleArray> minimizer, double tol)
        {
            DoubleArray r = minimizer.minimize(F_2D, DoubleArray.of(10d, 10d));

            assertEquals(r.get(0), -3.4, tol);
            assertEquals(r.get(1), 1, tol);
            r = (minimizer.minimize(ROSENBROCK, DoubleArray.of(10d, -5d)));
            assertEquals(r.get(0), 1, tol);
            assertEquals(r.get(1), 1, tol);
        }
コード例 #4
0
 /// <inheritdoc/>
 public override void Apply(Minimizer minimizer)
 {
     base.Apply(minimizer);
     if (_strictMirror)
     {
         minimizer.AddConstraint(new Squared(Scale) - 1, $"keep scale of {Name}");
     }
     else
     {
         minimizer.Minimize += 1e6 * (new Squared(Scale) + 1.0 / new Squared(Scale));
     }
 }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: protected void assertSolvingRosenbrock(final Minimizer<java.util.function.Function<com.opengamma.strata.collect.array.DoubleArray, double>, com.opengamma.strata.collect.array.DoubleArray> minimizer, final double tol)
        protected internal virtual void assertSolvingRosenbrock(Minimizer <System.Func <DoubleArray, double>, DoubleArray> minimizer, double tol)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray start = com.opengamma.strata.collect.array.DoubleArray.of(-1d, 1d);
            DoubleArray start = DoubleArray.of(-1d, 1d);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray solution = minimizer.minimize(ROSENBROCK, start);
            DoubleArray solution = minimizer.minimize(ROSENBROCK, start);

            assertEquals(1.0, solution.get(0), tol);
            assertEquals(1.0, solution.get(1), tol);
        }
コード例 #6
0
        /// <summary>
        /// Solves the unknowns in this circuit.
        /// </summary>
        public void Solve()
        {
            var minimizer = new Minimizer();

            minimizer.Warning += Warn;

            // Build the function that needs to be minimized
            for (var i = 0; i < _wires.Count; i++)
            {
                foreach (var length in _wires[i].Lengths)
                {
                    if (length.IsFixed)
                    {
                        if (length.Value < 0.0)
                        {
                            Warn(this, new WarningEventArgs($"Wire length '{length}' is smaller than 0."));
                        }
                        continue;
                    }
                    var x = length - WireLength;
                    minimizer.Minimize += 1e3 * (x + new Squared(x) + new Exp(-x));
                    length.Value        = WireLength;
                    minimizer.AddMinimum(length, 0.0);
                }
            }

            foreach (var c in _components)
            {
                c.Value.Apply(minimizer);
            }

            foreach (var c in _constraints)
            {
                if (!c.Key.IsFixed)
                {
                    minimizer.AddConstraint(c.Key, c.Value);
                }
                else
                {
                    if (!c.Key.Value.IsZero())
                    {
                        Warn(this, new WarningEventArgs($"Could not {c.Value}"));
                    }
                }
            }

            minimizer.Solve();
            Solved             = true;
            minimizer.Warning -= Warn;
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: protected void assertSolvingUncoupledRosenbrock(final Minimizer<java.util.function.Function<com.opengamma.strata.collect.array.DoubleArray, double>, com.opengamma.strata.collect.array.DoubleArray> minimizer, final double tol)
        protected internal virtual void assertSolvingUncoupledRosenbrock(Minimizer <System.Func <DoubleArray, double>, DoubleArray> minimizer, double tol)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray start = com.opengamma.strata.collect.array.DoubleArray.of(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
            DoubleArray start = DoubleArray.of(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleArray solution = minimizer.minimize(UNCOUPLED_ROSENBROCK, start);
            DoubleArray solution = minimizer.minimize(UNCOUPLED_ROSENBROCK, start);

            for (int i = 0; i < solution.size(); i++)
            {
                assertEquals(1.0, solution.get(i), tol);
            }
        }
コード例 #8
0
        /// <summary>
        /// Refines an intersection pair for two curves given an initial guess.<br/>
        /// This is an unconstrained minimization, so the caller is responsible for providing a very good initial guess.
        /// </summary>
        /// <param name="crv0">The first curve.</param>
        /// <param name="crv1">The second curve.</param>
        /// <param name="firstGuess">The first guess parameter.</param>
        /// <param name="secondGuess">The second guess parameter.</param>
        /// <param name="tolerance">The value tolerance for the intersection.</param>
        /// <returns>The results collected into the object <see cref="CurvesIntersectionResult"/>.</returns>
        internal static CurvesIntersectionResult CurvesWithEstimation(NurbsBase crv0, NurbsBase crv1,
                                                                      double firstGuess, double secondGuess, double tolerance)
        {
            IObjectiveFunction objectiveFunctions = new CurvesIntersectionObjectives(crv0, crv1);
            Minimizer          min      = new Minimizer(objectiveFunctions);
            MinimizationResult solution = min.UnconstrainedMinimizer(new Vector {
                firstGuess, secondGuess
            }, tolerance * tolerance);

            // These are not the same points, also are used to filter where the intersection is not happening.
            Point3 pt1 = crv0.PointAt(solution.SolutionPoint[0]);
            Point3 pt2 = crv1.PointAt(solution.SolutionPoint[1]);

            return(new CurvesIntersectionResult(pt1, pt2, solution.SolutionPoint[0], solution.SolutionPoint[1]));
        }
コード例 #9
0
        /// <summary>
        /// Refines an intersection between a curve and a plane given an initial guess.<br/>
        /// This is an unconstrained minimization, so the caller is responsible for providing a very good initial guess.
        /// </summary>
        /// <param name="crv">The curve to intersect.</param>
        /// <param name="plane">The plane to intersect with the curve.</param>
        /// <param name="firstGuess">The first guess parameter.</param>
        /// <param name="secondGuess">The second guess parameter.</param>
        /// <param name="tolerance">The value tolerance for the intersection.</param>
        /// <returns>The results collected into the object <see cref="CurvePlaneIntersectionResult"/>.</returns>
        internal static CurvePlaneIntersectionResult CurvePlaneWithEstimation(NurbsBase crv, Plane plane,
                                                                              double firstGuess, double secondGuess, double tolerance)
        {
            IObjectiveFunction objectiveFunctions = new CurvePlaneIntersectionObjectives(crv, plane);
            Minimizer          min      = new Minimizer(objectiveFunctions);
            MinimizationResult solution = min.UnconstrainedMinimizer(new Vector {
                firstGuess, secondGuess
            }, tolerance * tolerance);

            Point3 pt = crv.PointAt(solution.SolutionPoint[0]);

            (double u, double v)parameters = plane.ClosestParameters(pt);
            Vector uv = new Vector {
                parameters.u, parameters.v, 0.0
            };

            return(new CurvePlaneIntersectionResult(pt, solution.SolutionPoint[0], uv));
        }
コード例 #10
0
        public double ParameterAtChordLength(double t, double chordLength)
        {
            if (chordLength <= 0)
            {
                throw new ArgumentException("Chord length must be greater than 0.");
            }

            if (chordLength >= Length)
            {
                return(1.0);
            }

            IObjectiveFunction objectiveFunction = new ChordLengthObjective(this, t, chordLength);
            Minimizer          min      = new Minimizer(objectiveFunction);
            var lengthAtPrevious        = LengthAt(t);
            var initialGuess            = ParameterAtLength(lengthAtPrevious + chordLength);
            MinimizationResult solution = min.UnconstrainedMinimizer(new Vector {
                initialGuess, initialGuess
            });

            return(solution.SolutionPoint[0]);
        }
コード例 #11
0
 /// <inheritdoc/>
 public virtual void Apply(Minimizer minimizer)
 {
     // Make any minimization of the coordinates very weak to avoid having issues with our other minimizations
     // We will give a small priority to Y-coordinates to avoid problems with arbitrary rotational
     minimizer.Minimize += new Squared(1e-6 * X) + new Squared(1.1e-6 * Y);
 }
コード例 #12
0
 public override void Apply(Minimizer minimizer)
 {
     base.Apply(minimizer);
     minimizer.Minimize += new Squared(NormalX - 1) / 1e4;
     minimizer.AddConstraint(new Squared(NormalX) + new Squared(NormalY) - 1, $"fix orientation of {Name}");
 }
コード例 #13
0
 public ActionResult Minimize(int group_id)
 {
     VDolgah.Models.Minimizer min = new Minimizer();
     min.MinGroup(group_id);
     return(RedirectToAction("Index", new { group_id = group_id }));
 }