<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Hello Marc,<br>
    <br>
    Am 05.11.2010 17:55, schrieb <a class="moz-txt-link-abbreviated" href="mailto:marc.roth@rwe.com:">marc.roth@rwe.com:</a>
    <blockquote
cite="mid:E7FDCCA07104474A92CCEE0903653F0B0995A404@s080a0022.group.rwe.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="MS Exchange Server version
        6.5.7654.12">
      <title>Using "symbolic" variable names.</title>
      <!-- Converted from text/rtf format -->
      <p><font face="Arial" size="2">Hi,</font>
      </p>
      <p><font face="Arial" size="2">I am developing a toy problem in
          order to figure out how FlopC++ has to be used. I consulted
          the example problems in the examples section to get started
          but have a couple of questions:</font></p>
      <p><font face="Arial" size="2">1) Use of symbolic names and LP
          file output: I would like to use the setName method on
          MP_variable, lets say, such as</font>
      </p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_model lp(new
          OsiCbcSolverInterface)&nbsp; ;</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_set T(123);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_variable
          dispatch_period_volume(T);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">x.setName("dp_volume_");</font>
      </p>
      <p><font face="Arial" size="2">Once the model has been set up, I
          write the problem to a file, such as</font>
      </p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">lp.attach();&nbsp;&nbsp;&nbsp; </font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">lp.Solver-&gt;writeLp("c:\\temp\\bmt);</font>
      </p>
      <p><font face="Arial" size="2">What I expect to see in the file
          bmt.lp is that the variable names are printed like
          dp_volume_1, dp_volume_2, &#8230;, dp_volume_124, but what I get is
          only x1, &#8230;, x124. Am I doing something wrong or is this
          feature not supported (in this case what is the
          MP_variable::setNames() method for?).</font></p>
    </blockquote>
    At the moment the feature is not yet supported, but it will be in
    the near future, at least in the stochastic branch of FlopC++. <br>
    <br>
    <blockquote
cite="mid:E7FDCCA07104474A92CCEE0903653F0B0995A404@s080a0022.group.rwe.com"
      type="cite">
      <p><font face="Arial" size="2">2) In the objective function in
          question some of the decision variables x are modelled by
          abs(x) (the absolute value of x). Obviously this is not a
          linear construct, but can be modelled as:</font></p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">x &lt;= abs_x</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">-1.0*x &lt;= abs_x</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">0 &lt;= abs_x</font>
      </p>
      <p><font face="Arial" size="2">Because I require various variables
          to be modelled as abs(.) I would like to implement a function
          that;</font>
        <br>
        <font face="Arial" size="2">A) creates the auxiliary variable(s)
          abs_x for each such x,</font>
        <br>
        <font face="Arial" size="2">B) adds above constraints/bounds to
          the model, and</font>
        <br>
        <font face="Arial" size="2">C) returns a MP_expression that can
          be added to the objective function expression in terms of the
          abs_x variables.</font>
      </p>
      <p><font face="Arial" size="2">I.e., I would like to
          delegate/encapsulate all issues to model the absolute value of
          a decision variable to a function.</font>
      </p>
      <p><font face="Arial" size="2">My initial approach, listed below,
          failed miserably because of the issue of automatic variables
          and copy constructors, etc., I guess boiling down to that
          FlopC++ elements are not "shallow" copied and reference
          counted on the one had and that MP_variables are not added to
          the model implicitly but only through their use in constraints
          and objective function. What is the proper way to accomplish
          this?</font></p>
    </blockquote>
    <br>
    In my opinion this could work, if you work with pointers instead of
    objects in your helper function. Create the MP_constraints and
    MP_variables in the function with new, otherwise they should be lost
    when the function goes out of scope. This is only a first thought
    about the topic. I can look into it someday next week.<br>
    <br>
    Hope this helps,<br>
    Christian<br>
    <blockquote
cite="mid:E7FDCCA07104474A92CCEE0903653F0B0995A404@s080a0022.group.rwe.com"
      type="cite">
      <br>
      <p><font face="Arial" size="2">static MP_expression</font>
        <br>
        <font face="Arial" size="2">lp_objective_absolute(</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_variable&amp; x,</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_data&amp;
          weight,</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_model&amp;
          lp/*=MP_model::getDefaultModel()*/,</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">const string&amp;
          prefix/*="abs_"*/) {</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">if (x.size() &gt; 0) {</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">if
          (x.getName().empty()) {</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">string
          message;</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">message +=
          "decision variable(s) or affine expression(s) is/are not
          named";</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">throw
          BmtException(message.c_str());</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">}</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_set D(x.size());</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_variable
          abs_x(D);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">abs_x.setName(prefix
          + x.getName());</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">abs_x.lowerLimit(D)
          = 0.0;</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_constraint
          abs_x_linctr_a(D);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_constraint
          abs_x_linctr_b(D);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">abs_x_linctr_a(D) =
          x(D) &lt;= abs_x(D);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">abs_x_linctr_b(D) =
          -1.0*x(D) &lt;= abs_x(D);</font>
      </p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">lp.add(abs_x_linctr_a);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">lp.add(abs_x_linctr_b);</font>
      </p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">return sum(D,
          weight(D)*abs_x(D));</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">} else {</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">return
          MP_expression();</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">}</font>
        <br>
        <font face="Arial" size="2">}</font>
      </p>
      <p><font face="Arial" size="2">And would be used such as</font>
      </p>
      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_expression objective;</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">MP_data UNIT_WEIGHT_X(T);</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">UNIT_WEIGHT_X(T) = 1.0;</font>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial" size="2">objective =
          lp_objective_absolute(dispatch_period_volume, UNIT_WEIGHT_X,
          lp);</font>
      </p>
      <p><font face="Arial" size="2">Best Regards/Mit freundlichen
          Gr&uuml;&szlig;en</font>
        <br>
        <b><font face="Arial" size="2">Marc Roth</font></b><br>
        <font face="Arial" size="2">External Consultant,<br>
          Structuring &amp; Valuation<br>
          Tel.: +41 55 534 44 82<br>
          Mob: +44 7795 276 136<br>
          Fax: +41 55 534 44 82<br>
        </font><a moz-do-not-send="true" href="mailto:marc.roth@rwe.com"><u><font
              color="#0000ff" face="Arial" size="2">mailto:marc.roth@rwe.com</font></u></a><br>
        <font face="Arial" size="2">yahoo:nerdyanorak</font>
        <br>
        <font face="Arial" size="1">RWE Supply &amp; Trading GmbH<br>
          London Branch<br>
          130 Wood Street<br>
          London EC2V 6DL<br>
          United Kingdom<br>
          <br>
          Advisory Board:<br>
          Dr. Ulrich Jobs (Chairman)</font>
      </p>
      <p><font face="Arial" size="1">Board of Directors:<br>
          Stefan Judisch (CEO)<br>
          Dr. Bernhard G&uuml;nther<br>
          Dr. Peter Kreuzberg<br>
          Richard Lewis</font>
        <br>
        <font face="Arial" size="1">Alan Robinson</font>
      </p>
      <p><font face="Arial" size="1">Head Office: Essen, Germany </font>
        <br>
        <font face="Arial" size="1">Registered at the County Court of
          Essen<br>
          Commercial Registry No.: HRB 14327<br>
          Sales Tax Identification No. DE 8130 22 070</font>
      </p>
      <p>
        <br>
      </p>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
FlopCpp mailing list
<a class="moz-txt-link-abbreviated" href="mailto:FlopCpp@list.coin-or.org">FlopCpp@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/flopcpp">http://list.coin-or.org/mailman/listinfo/flopcpp</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>