<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:inherit;
panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
code
{mso-style-priority:99;
font-family:"Courier New";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
mso-fareast-language:EN-GB;}
span.gmail-kwd
{mso-style-name:gmail-kwd;}
span.gmail-pln
{mso-style-name:gmail-pln;}
span.gmail-pun
{mso-style-name:gmail-pun;}
span.gmail-typ
{mso-style-name:gmail-typ;}
span.EmailStyle26
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">You can always share results of one calculation with others by using class variables (if you are using a class) or global variables.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Ipopt [mailto:ipopt-bounces@coin-or.org]
<b>On Behalf Of </b>Hisham Abdulla<br>
<b>Sent:</b> 29 December 2017 22:28<br>
<b>To:</b> ipopt@list.coin-or.org<br>
<b>Subject:</b> [Ipopt] Wrapping two functions together in Ipopt API<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">I'm a beginner in Ipopt as well as C++.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;vertical-align:baseline;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">in Ipopt, I've to write implementations of the following functions, in a class.<o:p></o:p></span></p>
<pre style="background:#EFF0F1;vertical-align:baseline;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit;max-height:600px;word-wrap:normal;overflow:auto"><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">virtual</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">bool</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> eval_f</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">(</span></span><span class="gmail-typ"><span style="font-family:"inherit",serif;color:#2B91AF;border:none windowtext 1.0pt;padding:0cm">Index</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> n</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">,</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">const</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-typ"><span style="font-family:"inherit",serif;color:#2B91AF;border:none windowtext 1.0pt;padding:0cm">Number</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">*</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> x</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">,</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">bool</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> new_x</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">,</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-typ"><span style="font-family:"inherit",serif;color:#2B91AF;border:none windowtext 1.0pt;padding:0cm">Number</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">&</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> obj_value</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">);</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></span></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">virtual</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">bool</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> eval_grad_f</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">(</span></span><span class="gmail-typ"><span style="font-family:"inherit",serif;color:#2B91AF;border:none windowtext 1.0pt;padding:0cm">Index</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> n</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">,</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">const</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-typ"><span style="font-family:"inherit",serif;color:#2B91AF;border:none windowtext 1.0pt;padding:0cm">Number</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">*</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> x</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">,</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-kwd"><span style="font-family:"inherit",serif;color:#101094;border:none windowtext 1.0pt;padding:0cm">bool</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> new_x</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">,</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> </span></span><span class="gmail-typ"><span style="font-family:"inherit",serif;color:#2B91AF;border:none windowtext 1.0pt;padding:0cm">Number</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">*</span></span><span class="gmail-pln"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm"> grad_f</span></span><span class="gmail-pun"><span style="font-family:"inherit",serif;color:#303336;border:none windowtext 1.0pt;padding:0cm">);</span></span><span style="font-family:Consolas;color:#393318"><o:p></o:p></span></pre>
<p style="margin:0cm;margin-bottom:.0001pt;vertical-align:baseline;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">In my problem, </span><code><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0cm;background:#EFF0F1">eval_grad_f</span></code><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729"> share
many calculations and results with </span><code><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0cm;background:#EFF0F1">eval_f</span></code><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">.
( For example, without </span><code><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0cm;background:#EFF0F1">obj_value</span></code><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729"> I
cannot calculate </span><code><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0cm;background:#EFF0F1">grad_f</span></code><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">). If
the both functions were in a single wrapped function, that would have been much easy for me. I want to reuse results and computation of </span><code><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0cm;background:#EFF0F1">eval_f</span></code><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729"> in
the </span><code><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0cm;background:#EFF0F1">eval_grad_fun</span></code><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">. Please suggest
an efficient way to do this.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;vertical-align:baseline;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729"><o:p> </o:p></span></p>
<p style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm;vertical-align:baseline;font-variant-numeric:inherit;font-stretch:inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">Hisham<o:p></o:p></span></p>
</div>
</div>
</body>
</html>