<!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> <font face="Arial" size="2">MP_model lp(new
OsiCbcSolverInterface) ;</font>
<br>
<font face="Arial" size="2">MP_set T(123);</font>
<br>
<font face="Arial" size="2">MP_variable
dispatch_period_volume(T);</font>
<br>
<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> <font face="Arial" size="2">lp.attach(); </font>
<br>
<font face="Arial" size="2">lp.Solver->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, …, dp_volume_124, but what I get is
only x1, …, 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> <font face="Arial" size="2">x <= abs_x</font>
<br>
<font face="Arial" size="2">-1.0*x <= abs_x</font>
<br>
<font face="Arial" size="2">0 <= 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>
<font face="Arial" size="2">MP_variable& x,</font>
<br>
<font face="Arial" size="2">MP_data&
weight,</font>
<br>
<font face="Arial" size="2">MP_model&
lp/*=MP_model::getDefaultModel()*/,</font>
<br>
<font face="Arial" size="2">const string&
prefix/*="abs_"*/) {</font>
<br>
<font face="Arial" size="2">if (x.size() > 0) {</font>
<br>
<font face="Arial" size="2">if
(x.getName().empty()) {</font>
<br>
<font face="Arial" size="2">string
message;</font>
<br>
<font face="Arial" size="2">message +=
"decision variable(s) or affine expression(s) is/are not
named";</font>
<br>
<font face="Arial" size="2">throw
BmtException(message.c_str());</font>
<br>
<font face="Arial" size="2">}</font>
<br>
<font face="Arial" size="2">MP_set D(x.size());</font>
<br>
<font face="Arial" size="2">MP_variable
abs_x(D);</font>
<br>
<font face="Arial" size="2">abs_x.setName(prefix
+ x.getName());</font>
<br>
<font face="Arial" size="2">abs_x.lowerLimit(D)
= 0.0;</font>
<br>
<font face="Arial" size="2">MP_constraint
abs_x_linctr_a(D);</font>
<br>
<font face="Arial" size="2">MP_constraint
abs_x_linctr_b(D);</font>
<br>
<font face="Arial" size="2">abs_x_linctr_a(D) =
x(D) <= abs_x(D);</font>
<br>
<font face="Arial" size="2">abs_x_linctr_b(D) =
-1.0*x(D) <= abs_x(D);</font>
</p>
<p> <font face="Arial" size="2">lp.add(abs_x_linctr_a);</font>
<br>
<font face="Arial" size="2">lp.add(abs_x_linctr_b);</font>
</p>
<p> <font face="Arial" size="2">return sum(D,
weight(D)*abs_x(D));</font>
<br>
<font face="Arial" size="2">} else {</font>
<br>
<font face="Arial" size="2">return
MP_expression();</font>
<br>
<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> <font face="Arial" size="2">MP_expression objective;</font>
<br>
<font face="Arial" size="2">MP_data UNIT_WEIGHT_X(T);</font>
<br>
<font face="Arial" size="2">UNIT_WEIGHT_X(T) = 1.0;</font>
<br>
<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üßen</font>
<br>
<b><font face="Arial" size="2">Marc Roth</font></b><br>
<font face="Arial" size="2">External Consultant,<br>
Structuring & 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 & 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ü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>