[PPL-devel] assign a variable

Roberto Bagnara bagnara at cs.unipr.it
Sun Jan 25 18:59:09 CET 2004


fersman at lsv.ens-cachan.fr wrote:
> In my program I need to assign a variable, say x, a new value, say y+k, in
> a polyhedron.
> As far as I understand, to do this i need to free x, i.e. romove
> constraints on x, and after that intersect with the constraint x==y+k.
> Using functions from the library, a can first remove dimension x, then add
> a new dimension and add a constraint. After that the representation of the
> polyhedron when it is printed changes, i.e. if A represented x before, 
> now it would represent y. How to avoid this problem? Is there a better way
> of freeing a variable than removing the dimension and adding it again?

Dear Elena,

if I understand correctly you want to model the destructive assignment
of a linear expression to one variable.  If this is the case, what you want
is the method

     Polyhedron::affine_image()

For instance, if you want to update a polyhedron ph so as to reflect the
assignment of y+k to x, all you have to do is

     ph.affine_image(x, y+k)

You can play with the small test program under the signature so as to
familiarize with that method.  The program now prints

     ph before:
     -x >= -3, y >= 0, x - y >= 0
     ph after ph.affine_image(x, y-7):
     x - y = -7, -y >= -3, y >= 0

I may have misunderstood your question, of course.
Please, don't hesitate to come back to us if that is the case.
All the best,

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it


#include <ppl.hh>

using namespace std;
using namespace Parma_Polyhedra_Library;
using namespace Parma_Polyhedra_Library::IO_Operators;

void
my_output_function(ostream& s, const Variable& v) {
   s << char('x' + v.id());
}

int
main() {
   // Install the alternate output function.
   Variable::set_output_function(my_output_function);

   Variable x(0);
   Variable y(1);

   C_Polyhedron ph(2);
   ph.add_constraint(x >= y);
   ph.add_constraint(y >= 0);
   ph.add_constraint(x <= 3);

   cout << "ph before: " << endl << ph << endl;

   ph.affine_image(x, y-7);

   cout << "ph after ph.affine_image(x, y-7): " << endl << ph << endl;
}




More information about the PPL-devel mailing list