[FlopCpp] Using "symbolic" variable names.

Christian Wolf kalmar at uni-paderborn.de
Sat Nov 6 13:33:32 EDT 2010


Hello Marc,

Am 05.11.2010 17:55, schrieb marc.roth at rwe.com:
>
> Hi,
>
> 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:
>
> 1) Use of symbolic names and LP file output: I would like to use the 
> setName method on MP_variable, lets say, such as
>
> MP_model lp(new OsiCbcSolverInterface)  ;
> MP_set T(123);
> MP_variable dispatch_period_volume(T);
> x.setName("dp_volume_");
>
> Once the model has been set up, I write the problem to a file, such as
>
> lp.attach();
> lp.Solver->writeLp("c:\\temp\\bmt);
>
> 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?).
>
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++.

> 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:
>
> x <= abs_x
> -1.0*x <= abs_x
> 0 <= abs_x
>
> Because I require various variables to be modelled as abs(.) I would 
> like to implement a function that;
> A) creates the auxiliary variable(s) abs_x for each such x,
> B) adds above constraints/bounds to the model, and
> C) returns a MP_expression that can be added to the objective function 
> expression in terms of the abs_x variables.
>
> I.e., I would like to delegate/encapsulate all issues to model the 
> absolute value of a decision variable to a function.
>
> 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?
>

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.

Hope this helps,
Christian
>
> static MP_expression
> lp_objective_absolute(
> MP_variable& x,
> MP_data& weight,
> MP_model& lp/*=MP_model::getDefaultModel()*/,
> const string& prefix/*="abs_"*/) {
> if (x.size() > 0) {
> if (x.getName().empty()) {
> string message;
> message += "decision variable(s) or affine expression(s) is/are not 
> named";
> throw BmtException(message.c_str());
> }
> MP_set D(x.size());
> MP_variable abs_x(D);
> abs_x.setName(prefix + x.getName());
> abs_x.lowerLimit(D) = 0.0;
> MP_constraint abs_x_linctr_a(D);
> MP_constraint abs_x_linctr_b(D);
> abs_x_linctr_a(D) = x(D) <= abs_x(D);
> abs_x_linctr_b(D) = -1.0*x(D) <= abs_x(D);
>
> lp.add(abs_x_linctr_a);
> lp.add(abs_x_linctr_b);
>
> return sum(D, weight(D)*abs_x(D));
> } else {
> return MP_expression();
> }
> }
>
> And would be used such as
>
> MP_expression objective;
> MP_data UNIT_WEIGHT_X(T);
> UNIT_WEIGHT_X(T) = 1.0;
> objective = lp_objective_absolute(dispatch_period_volume, 
> UNIT_WEIGHT_X, lp);
>
> Best Regards/Mit freundlichen Grüßen
> *Marc Roth*
> External Consultant,
> Structuring & Valuation
> Tel.: +41 55 534 44 82
> Mob: +44 7795 276 136
> Fax: +41 55 534 44 82
> _mailto:marc.roth at rwe.com_
> yahoo:nerdyanorak
> RWE Supply & Trading GmbH
> London Branch
> 130 Wood Street
> London EC2V 6DL
> United Kingdom
>
> Advisory Board:
> Dr. Ulrich Jobs (Chairman)
>
> Board of Directors:
> Stefan Judisch (CEO)
> Dr. Bernhard Günther
> Dr. Peter Kreuzberg
> Richard Lewis
> Alan Robinson
>
> Head Office: Essen, Germany
> Registered at the County Court of Essen
> Commercial Registry No.: HRB 14327
> Sales Tax Identification No. DE 8130 22 070
>
>
>
> _______________________________________________
> FlopCpp mailing list
> FlopCpp at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/flopcpp

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20101106/cc232b97/attachment.html 


More information about the FlopCpp mailing list