[Ipopt] Ipopt report issue

Sebastian Ferrera Ferrera sebastian.ferrera at corpbanca.cl
Mon Dec 6 08:33:54 EST 2010


Thanks for the help Stefan,

Actually, my objective is to catch the number of iterations and accuracy of the minimization process.

I am running Ipopt through a precompiled dll (Ipopt38.dll) and I have a class on my project (VS2008) that makes the conection between my source code and the Ipopt's functions.

The way I use Ipopt is something like:

[DllImport(Ipopt38)]
        unsafe private static extern IntPtr CreateIpoptProblem(int n, double* x_L, double* x_U, int m, double* g_L, double* g_U,  int nele_jac, 
            int nele_hess, int index_style, Eval_F_CB eval_f, Eval_G_CB eval_g, Eval_Grad_F_CB eval_grad_f, Eval_Jac_G_CB eval_jac_g, Eval_H_CB eval_h);

[DllImport(Ipopt38)]
        unsafe private static extern int IpoptSolve(
            IntPtr ipopt_problem, double* x, double* g, double* obj_val, double* mult_g, double* mult_x_L, double* mult_x_U, void* user_data);



public IpoptReturnCode SolveProblem(double[] x, out double obj_val, double[] g, double[] mult_g, double[] mult_x_L, double[] mult_x_U)
        {
            unsafe
            {
                fixed (double* p_obj_val = &obj_val, p_x = x, p_g = g, p_mult_g = mult_g, p_mult_x_L = mult_x_L, p_mult_x_U = mult_x_U)
                {
                    return (IpoptReturnCode)IpoptSolve(m_problem, p_x, p_g, p_obj_val, p_mult_g, p_mult_x_L, p_mult_x_U, null);
                }
            }
        }

public Ipopt(int n, double[] x_L, double[] x_U, int m, double[] g_L, double[] g_U, int nele_jac, int nele_hess,
            EvaluateObjectiveDelegate eval_f, EvaluateConstraintsDelegate eval_g, EvaluateObjectiveGradientDelegate eval_grad_f, 
            EvaluateJacobianDelegate eval_jac_g, EvaluateHessianDelegate eval_h)
        {
            unsafe
            {
                fixed (double* p_x_L = x_L, p_x_U = x_U, p_g_L = g_L, p_g_U = g_U)
                {
                    m_eval_f = new ObjectiveEvaluator(eval_f).Evaluate;
                    m_eval_g = new ConstraintsEvaluator(eval_g).Evaluate; 
                    m_eval_grad_f = new ObjectiveGradientEvaluator(eval_grad_f).Evaluate;
                    m_eval_jac_g = new JacobianEvaluator(eval_jac_g).Evaluate;
                    m_eval_h = new HessianEvaluator(eval_h).Evaluate;

                    m_problem = CreateIpoptProblem(n, p_x_L, p_x_U, m, p_g_L, p_g_U, nele_jac, nele_hess, 0,
                        m_eval_f, m_eval_g, m_eval_grad_f, m_eval_jac_g, m_eval_h);

                    if (m_problem == IntPtr.Zero)
                    {
                        throw new ArgumentException("Failed to initialize IPOPT problem");
                    }
                }
            }

            m_disposed = false;
        }

That is a part of my conection (Ipopt.cs) to the Ipopt38.dll and in my main project I have this:

		    double[] dbl_x = { 1.0, 5.0, 5.0, 1.0 };
		    double obj;
                IpoptReturnCode status;
                using (Ipopt problem = new Ipopt(p_dbl.n, p_dbl.x_L, p_dbl.x_U, p_dbl.m, p_dbl.g_L, p_dbl.g_U, p_dbl.nele_jac, p_dbl.nele_hess,
                p_dbl.eval_f, p_dbl.eval_g, p_dbl.eval_grad_f, p_dbl.eval_jac_g, p_dbl.eval_h))
                {
                    problem.AddOption("tol", 1e-7);
                    problem.AddOption("mu_strategy", "adaptive");
                    problem.AddOption("output_file", "hs071.txt");    

                    /* solve the problem */
                    
                    status = problem.SolveProblem(dbl_x, out obj, null, null, null, null);
                }


p_dbl is a class that manages the evaluations, number of constraints, etc.

So, I need to find something that can return the number of iterations and accuracy (optimal_solution, etc)... my first idea was to read the result file (hs071.txt) or return the journal to a string variable, but I think there must be another way...

Sorry for my poor english and I hope you understand,

Sebastián.



-----Mensaje original-----
De: Stefan Vigerske [mailto:stefan at math.hu-berlin.de] 
Enviado el: Viernes, 03 de Diciembre de 2010 15:10
Para: Sebastian Ferrera Ferrera
CC: ipopt at list.coin-or.org
Asunto: Re: [Ipopt] Ipopt report issue

Hi,

Ipopt has the concept of Journals that can be used to redirect output to 
whereever you like.

When you create the IpoptApplication object, just give it as argument a 
"false", so it does not create the default journal:
        ipopt = new IpoptApplication(false);

Then you can create your own journal and pass it to Ipopt. It should be 
called "console", otherwise Ipopt may create another one later, if I 
rembember correct.
   SmartPtr<Journal> jrnl = new MyJournal(gev, "console", J_ITERSUMMARY);
   jrnl->SetPrintLevel(J_DBG, J_NONE);
   if (!ipopt->Jnlst()->AddJournal(jrnl))
     std::cerr << "Failed to register MyJournal for IPOPT output."
               << std::endl;

There are also some Journals implemented already, you may be interested 
in the StreamJournal, which you can give a stringstream, that you can 
transform into a string object afterwards.
http://www.coin-or.org/Doxygen/Ipopt/class_ipopt_1_1_journal.html


Stefan


Am 03.12.2010 15:05, schrieb Sebastian Ferrera Ferrera:
> Hello friends,
>
> I am currently working on a project using the Ipopt minimization.
>
> I am writing because I would like to know whether it is posible to configure Ipopt so that the report does not appear in the Windows command prompt but e.g. in a string variable.
>
> Thank you and regards,
>
>
> Atte.,
>
> Sebastián Ferrera.
> Ingeniero Financiero en Sistemas Junior
> Ingeniería Financiera
> Rosario Norte Nº 660 Piso 7
> Fono: 660 2413
> E-mail : sebastian.ferrera at corpbanca.cl<mailto:david.matamala at corpbanca.cl>
> www.corpbanca.cl<http://www.corpbanca.cl/>
>
>
>
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/ipopt




More information about the Ipopt mailing list