
Hosung Song wrote:
Greetings. I'm using your PPL library through C interface. I found there's no printing functions, so I tried to make my own, and it took me couple of hours why my interface didn't work, because my C++ knowledge is so old and premature. I think I finally got them correct, and I'd like to get some confirmation from you, and hopefully, ask you to incorporate the print functions in C interface. I put the following two functions at the end of ppl_c.cc, for printing constraints and polyhedra.
[...]
int ppl_print_Constraint(ppl_const_Constraint_t c); int ppl_print_Polyhedron(ppl_const_Polyhedron_t ph);
[...]
Would you confirm if these are correct interfaces for printing? I'm wondering if you could improve these so that we can pass a file pointer to the functions and redirect the output not just to stdout, but the file designated by the file pointer. Thank you very much for your invaluable libraries.
Dear Hosung,
you are right: currently the C interface does not provide functions to directly print PPL's object. The reason why we omitted them up to now is because whatever printing facility we provide, the chances that this is what the client application really needs are tiny to null. How should the constraint `-x+2y <= 7' in R^3 be written? As I wrote it? As `-x+2*y <= 7'? As `-1*x+2*y+0*z <= 7'? As `x-2y >= -7'? Want spaces around the `+' signs? Want spaces also around `*' signs? Want to use different symbols for the variables? Then think about constraint systems: do you want the individual constraints separated by commas? Semicolons? Commas and newline? Newline alone? The equalities first and then the inequalities? The equalities first, separated by commas, then a semicolon, if there are also inequalities, then the inequalities separated by commas with a final full stop?
As you can see, there is no way we can provide provide the "right" output function. In contrast, an output function that is completely configurable so as to accommodate the many variation outlined above plus a lot of others that were omitted plus an awful lot of others I cannot even think about now... well, such an output function would be such a monster that no one would like to use it.
Said that, a set of easy-to-use and reasonable output functions can be very useful when you start playing with the library and you just need to print something understandable that gives you an idea of what is going on. In the C++ interface we have confined this kind of output operators into a separate namespace: they are there, but will not inconvenience the user who wants to bake its own. We will thus add such functions to the C interface in time for the next release. There will be both the versions printing to `stdout' and the versions taking a FILE* argument.
In the interim, you may use the functions you wrote to print on `cout'. Notice, however, that printing on `stdout' and printing on `cout' is not the same thing. To make your functions work, you should add the line
std::ios_base::sync_with_stdio();
to the code for `ppl_initialize()'. Otherwise you risk your output to be messed up. That is, printing "The constraint is " on stdout and _then_ using your `ppl_print_Constraint()' may result in reversed output like
"x <= 7The constraint is "
If you are willing to alpha-test the new C output functions, please let us know: we will prepare a snapshot distribution you can play with. All the best,
Roberto
P.S. I don't know if you subscribed to the ppl-announce mailing list. This would be a good idea if you plan to work with a PPL on a non-casual basis. You can check by yourself at http://www.cs.unipr.it/mailman/listinfo/ppl-announce that it is a very low traffic, no noise, no spam, 100% relevant contents mailing list.