Convergence Plot : Objective function value vs iteration

437 views
Skip to first unread message

Snehil Verma

unread,
Feb 2, 2022, 9:39:35 AM2/2/22
to am...@googlegroups.com
I need to plot the graph of objective value vs iteration. 
Problem is attached below :
It has 60 iteration and has corresponding objective function value. 
Please tell me which software or method I can use to plot this graph.  
I have installed AMPL api to run the program on MATLAB to get the plot on matlab but it's giving some error. 
Is there any other method to plot the graph. 
Thanks you! 
IMG_20220202_132804.jpg

AMPL Google Group

unread,
Feb 2, 2022, 1:08:44 PM2/2/22
to AMPL Modeling Language
To plot objective values from a solver log, I would copy the relevant lines of the log, paste the lines into a spreadsheet program (like Excel), and use the "Text to Columns" feature to extract the iteration numbers and objective values. Then a plot can be created by using the many convenient plotting features in the spreadsheet program.

It is possible to automate some of this procedure, but that can be difficult, because the detailed iteration data from the solver log is only available as a text listing. Unless you have a really large number of plots to make, copying and pasting by hand is likely to be the easiest approach.


--
Robert Fourer
am...@googlegroups.com
{#HS:1775765496-108454#}

Snehil Verma

unread,
Feb 2, 2022, 11:23:19 PM2/2/22
to am...@googlegroups.com
Thankyou Sir, 
Instead of using MS. Excel, I want to run the following AMPL program on MATLAB. 
Is there any API which can integrate AMPL with MATLAB and run the following AMPL program. 

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-1775765496-5222644463-1643825324-182380671%40helpscout.net.

AMPL Google Group

unread,
Feb 3, 2022, 11:24:45 AM2/3/22
to AMPL Modeling Language
There is an AMPL API for MATLAB that can run AMPL programs, and can exchange data and results between AMPL and MATLAB.

It is not clear what you mean, however, when you say "run the following AMPL program on MATLAB." Can you explain what AMPL program you are trying to run, or attach a copy of the program?

(Earlier you asked about plotting a graph of the objective value versus the iteration. The information for that graph is only available in the solver log, which cannot be accessed through the AMPL API for MATLAB. You would need to write the solver log to a text file and then create a MATLAB program to read the objective values from the file and make the plot.)


--
Robert Fourer
am...@googlegroups.com
{#HS:1775765496-108454#}
On Thu, Feb 3, 2022 at 4:23 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thankyou Sir,
Instead of using MS. Excel, I want to run the following AMPL program on MATLAB.
Is there any API which can integrate AMPL with MATLAB and run the following AMPL program.

On Wed, Feb 2, 2022 at 6:08 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
To plot objective values from a solver log, I would copy the relevant lines of the log, paste the lines into a spreadsheet program (like Excel), and use the "Text to Columns" feature to extract the iteration numbers and objective values. Then a plot can be created by using the many convenient plotting features in the spreadsheet program.

It is possible to automate some of this procedure, but that can be difficult, because the detailed iteration data from the solver log is only available as a text listing. Unless you have a really large number of plots to make, copying and pasting by hand is likely to be the easiest approach.


--
Robert Fourer
am...@googlegroups.com

Snehil Verma

unread,
Feb 3, 2022, 4:31:43 PM2/3/22
to am...@googlegroups.com
Thank you for your response Sir. 
Actually it's my final year project :
Model file contains : 42variable (non-negative), 42 constraints(linear) and 16 non-linear constraint. 
Objective function is non-linear. 
My requirement is to plot graph of Objective function value for each iteration vs iteration. 

My teacher is not allowing to use MS excel, he said to use any other software or method to plot the graph. 
I thought of AMPL API for MATLAB but you are saying I need to write the text file, to extract the graph. 
Sir is there any other software or method to plot the graph i.e. other than MS Excel. 

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.

AMPL Google Group

unread,
Feb 4, 2022, 1:45:58 PM2/4/22
to AMPL Modeling Language
MATLAB is a good choice for plotting the iterations of the solver. You can get started with just a few commands:

>> iter = 1:5;
>> objval = [4.57481E+00,1.96429E+01,1.91308E+01,1.90990E+01,1.90987E+01];
>> plot(iter,objval)

This gives the following plot:

cb78afb1ba1325a15b78deeb01c3d1dc.png

More options to the plot function are described at https://www.mathworks.com/help/matlab/ref/plot.html.

The main difficulty here is that, to create the objval vector, I had to copy the objective values from the solver log. There is no way to get around copying the values, except to write a clever MATLAB program that reads the log and extracts the values. This is not a problem specific to MATLAB, however; any program that can do plotting will encounter the same problem with copying or extracting the objective values from the log. Thus you can choose whatever plotting program is easiest for you to use.

(After "solve" you can write > followed by a filename, if you want to redirect the solver log to a file. For example, "solve >solver.log;" writes the solver's output to the file solver.log.)


--
Robert Fourer
am...@googlegroups.com
{#HS:1775765496-108454#}
On Thu, Feb 3, 2022 at 9:31 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you for your response Sir.
Actually it's my final year project :
Model file contains : 42variable (non-negative), 42 constraints(linear) and 16 non-linear constraint.
Objective function is non-linear.
My requirement is to plot graph of Objective function value for each iteration vs iteration.

My teacher is not allowing to use MS excel, he said to use any other software or method to plot the graph.
I thought of AMPL API for MATLAB but you are saying I need to write the text file, to extract the graph.
Sir is there any other software or method to plot the graph i.e. other than MS Excel.

On Thu, Feb 3, 2022 at 4:24 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
There is an AMPL API for MATLAB that can run AMPL programs, and can exchange data and results between AMPL and MATLAB.

It is not clear what you mean, however, when you say "run the following AMPL program on MATLAB." Can you explain what AMPL program you are trying to run, or attach a copy of the program?

(Earlier you asked about plotting a graph of the objective value versus the iteration. The information for that graph is only available in the solver log, which cannot be accessed through the AMPL API for MATLAB. You would need to write the solver log to a text file and then create a MATLAB program to read the objective values from the file and make the plot.)


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages