Implementation of Hock-Schittkowski problem no. 71 from the CUTE collection. Adapted from http://www.orfe.princeton.edu/~rvdb/ampl/nlmodels/cute/hs071.mod Optimal solution x* = { 1.0; 4.742994; 3.8211503; 1.3794082 }, f* = 17.0140173
Inheritance: IpoptProblem
Esempio n. 1
0
        private void StartOptButton_Click(object sender, RoutedEventArgs e)
        {
            /* allocate space for the initial point and set the values */
            double[] x = { 1.0, 5.0, 5.0, 1.0 };

            try
            {
                var output = new StringBuilder();

                IpoptReturnCode status;
                double obj;
                using (var hs071 = new HS071())
                {
                    // Set some options.  The following ones are only examples,
                    // they might not be suitable for your problem.
                    hs071.AddOption("tol", 1e-7);
                    hs071.AddOption("mu_strategy", "adaptive");

                    // Solve the problem.
                    status = hs071.SolveProblem(x, out obj, null, null, null, null);
                }

                output.AppendLine("HS071");
                output.AppendLine("=====");
                output.AppendFormat("Optimization return status: {0}{1}{1}", status, Environment.NewLine);
                output.AppendFormat("Objective function value f = {0}{1}", obj, Environment.NewLine);
                for (int i = 0; i < 4; ++i) output.AppendFormat("x[{0}]={1}{2}", i, x[i], Environment.NewLine);
                output.AppendLine();

                // Also optimize Rosenbrock post office problem
                var r = new HS037();
                var rosenbrock = IpoptAdapter.CreateIpoptProblem(r._n, r._x_L, r._x_U, r._m, r._g_L, r._g_U, r._nele_jac,
                                                         r._nele_hess, IpoptIndexStyle.C,
                                                         r.eval_f, r.eval_g, r.eval_grad_f, r.eval_jac_g, r.eval_h);
                IpoptAdapter.AddIpoptStrOption(rosenbrock, "hessian_approximation", "limited-memory");
                IpoptAdapter.AddIpoptIntOption(rosenbrock, "limited_memory_max_history", 5);

                x = new[] { 10.0, 10.0, 10.0 };
                status = IpoptAdapter.IpoptSolve(rosenbrock, x, null, out obj, null, null, null, IntPtr.Zero);

                output.AppendLine("Rosenbrock Post Office");
                output.AppendLine("======================");
                output.AppendFormat("Optimization return status: {0}{1}{1}", status, Environment.NewLine);
                output.AppendFormat("Objective function value f = {0}{1}", obj, Environment.NewLine);
                for (int i = 0; i < 3; ++i) output.AppendFormat("x[{0}]={1}{2}", i, x[i], Environment.NewLine);

                OptOutputTextBox.Text = output.ToString();
            }
            catch (Exception exc)
            {
                OptOutputTextBox.Text = exc.GetType().FullName + ": " + exc.Message + Environment.NewLine + exc.StackTrace;
            }
        }
Esempio n. 2
0
        public void Constructor_OptionsFileAvailable_UsingOptionsFileData()
        {
            const string logFileName = "hs071_opt.txt";
            if (File.Exists(logFileName)) File.Delete(logFileName);

            const string optFileName = "ipopt.opt";
            File.WriteAllLines(optFileName, new[] { String.Format("output_file {0}", logFileName) });

            var instance = new HS071();
            double obj;
            var x = new[] { 1.0, 5.0, 5.0, 1.0 };
            instance.SolveProblem(x, out obj);

            instance.Dispose();
            if (File.Exists(optFileName)) File.Delete(optFileName);

            const bool expected = true;
            var actual = File.Exists(logFileName);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        private void OptimizeButtonClick(object sender, RoutedEventArgs e)
        {
            /* allocate space for the initial point and set the values */
            double[] x = { 1.0, 5.0, 5.0, 1.0 };

            try
            {
                var output = new StringBuilder();

                IpoptReturnCode status;
                double obj;
                using (var hs071 = new HS071())
                {
                    // Set some options.  The following ones are only examples,
                    // they might not be suitable for your problem.
                    hs071.AddOption("tol", 1e-7);
                    hs071.AddOption("mu_strategy", "adaptive");

                    // Solve the problem.
                    status = hs071.SolveProblem(x, out obj, null, null, null, null);
                }

                output.AppendLine("HS071");
                output.AppendLine("=====");
                output.AppendFormat("Optimization return status: {0}{1}{1}", status, Environment.NewLine);
                output.AppendFormat("Objective function value f = {0}{1}", obj, Environment.NewLine);
                for (int i = 0; i < 4; ++i) output.AppendFormat("x[{0}]={1}{2}", i, x[i], Environment.NewLine);
                output.AppendLine();

                IpoptResult.Text = output.ToString();
            }
            catch (Exception exc)
            {
                IpoptResult.Text = exc.GetType().FullName + ": " + exc.Message + Environment.NewLine + exc.StackTrace;
            }
        }
Esempio n. 4
0
 public void Setup()
 {
     _instance = new HS071();
     _instance.AddOption("tol", 1e-7);
     _instance.AddOption("mu_strategy", "adaptive");
 }
Esempio n. 5
0
 public void Teardown()
 {
     _instance.Dispose();
     _instance = null;
 }