Changeset 47a774 in git for gfanlib/gfanlib_zcone.cpp


Ignore:
Timestamp:
Aug 8, 2016, 2:14:52 PM (8 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
15813d0947d4221b8c060256fd6994a48e3c6605
Parents:
f73b0dba8fd582e1ebf4d2a1ed2067a19cab5a36
Message:
fix: includes, dd_global_constants
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gfanlib/gfanlib_zcone.cpp

    rf73b0d r47a774  
    1212#include <sstream>
    1313
    14 //extern "C"{
    15 #ifdef NOCDDPREFIX
    16 #include "setoper.h"
    17 #include "cdd.h"
     14#include <config.h>
     15#ifdef HAVE_CDD_SETOPER_H
     16#include <cdd/setoper.h>
     17#include <cdd/cdd.h>
    1818#else
    19 #include "cdd/setoper.h"
    20 #include "cdd/cdd.h"
    21 #endif
    22 //}
     19#ifdef HAVE_CDDLIB_SETOPER_H
     20#include <cddlib/setoper.h>
     21#include <cddlib/cdd.h>
     22#else
     23#include <setoper.h>
     24#include <cdd.h>
     25#endif //HAVE_CDDLIB_SETOPER_H
     26#endif //HAVE_CDD_SETOPER_H
     27
    2328
    2429namespace gfan{
    25         bool isCddlibRequired()
    26         {
    27                 return true;
    28         }
    29         void initializeCddlibIfRequired() // calling this frequently will cause memory leaks because deinitialisation is not possible with old versions of cddlib.
    30         {
    31                 dd_set_global_constants();
    32         }
    33         void deinitializeCddlibIfRequired()
    34         {
    35 //              dd_free_global_constants();
    36         }
     30        bool isCddlibRequired()
     31        {
     32                return true;
     33        }
     34        void initializeCddlibIfRequired() // calling this frequently will cause memory leaks because deinitialisation is not possible with old versions of cddlib.
     35        {
     36                dd_set_global_constants();
     37        }
     38        void deinitializeCddlibIfRequired()
     39        {
     40        #ifdef HAVE_DD_FREE_GLOBAL_CONSTANTS
     41                dd_free_global_constants();
     42        #endif
     43        }
    3744  static void ensureCddInitialisation()
    3845  {
    39           // A more complicated initialisation than the following (meaning attempts to count the number of times
    40           // cddlib was requested to be initialised) would require cddlib to be thread aware.
    41           // The error below is implemented with an assert(0) because throwing an exception may leave the impression that
    42           // it is possible to recover from this error. While that may be true, it would not work in full generality,
    43           // as the following if statement cannot test whether dd_free_global_constants() has also been called.
    44           // Moverover, in multithreaded environments it would be quite difficult to decide if cddlib was initialised.
    45           if(!dd_one[0]._mp_num._mp_d)
    46           {
    47                   std::cerr<<"CDDLIB HAS NOT BEEN INITIALISED!\n"
    48                                   "\n"
    49                                   "Fix this problem by calling the following function in your initialisation code:\n"
    50                                   "dd_set_global_constants();\n"
    51                                   "(after possibly setting the gmp allocators) and\n"
    52                                   "dd_free_global_constants()\n"
    53                                   "in your deinitialisation code (only available for cddlib version>=094d).\n"
    54                                   "This requires the header includes:\n"
    55                                   "#include \"cdd/setoper.h\"\n"
    56                                   "#include \"cdd/cdd.h\"\n"
    57                                   "\n"
    58                                   "Alternatively, you may call gfan:initializeCddlibIfRequired() and deinitializeCddlibIfRequired()\n"
    59                                   "if gfanlib is the only code using cddlib. If at some point cddlib is no longer required by gfanlib\n"
    60                                   "these functions may do nothing.\n"
    61                                   "Because deinitialisation is not possible in cddlib <094d, the functions may leak memory and should not be called often.\n"
    62                                   "\n"
    63                                   "This error message will never appear if the initialisation was done properly, and therefore never appear in a shipping version of your software.\n";
    64                   assert(0);
    65           }
    66           /*
    67           static bool initialized;
    68           if(!initialized)
     46          // A more complicated initialisation than the following (meaning attempts to count the number of times
     47          // cddlib was requested to be initialised) would require cddlib to be thread aware.
     48          // The error below is implemented with an assert(0) because throwing an exception may leave the impression that
     49          // it is possible to recover from this error. While that may be true, it would not work in full generality,
     50          // as the following if statement cannot test whether dd_free_global_constants() has also been called.
     51          // Moverover, in multithreaded environments it would be quite difficult to decide if cddlib was initialised.
     52          if(!dd_one[0]._mp_num._mp_d)
     53          {
     54                  std::cerr<<"CDDLIB HAS NOT BEEN INITIALISED!\n"
     55                                  "\n"
     56                                  "Fix this problem by calling the following function in your initialisation code:\n"
     57                                  "dd_set_global_constants();\n"
     58                                  "(after possibly setting the gmp allocators) and\n"
     59                                  "dd_free_global_constants()\n"
     60                                  "in your deinitialisation code (only available for cddlib version>=094d).\n"
     61                                  "This requires the header includes:\n"
     62                                  "#include \"cdd/setoper.h\"\n"
     63                                  "#include \"cdd/cdd.h\"\n"
     64                                  "\n"
     65                                  "Alternatively, you may call gfan:initializeCddlibIfRequired() and deinitializeCddlibIfRequired()\n"
     66                                  "if gfanlib is the only code using cddlib. If at some point cddlib is no longer required by gfanlib\n"
     67                                  "these functions may do nothing.\n"
     68                                  "Because deinitialisation is not possible in cddlib <094d, the functions may leak memory and should not be called often.\n"
     69                                  "\n"
     70                                  "This error message will never appear if the initialisation was done properly, and therefore never appear in a shipping version of your software.\n";
     71                  assert(0);
     72          }
     73          /*
     74          static bool initialized;
     75          if(!initialized)
    6976      {
    70                         dd_set_global_constants();
    71                         initialized=true;
     77                        dd_set_global_constants();
     78                        initialized=true;
    7279      }*/
    7380  }
     
    373380  void removeRedundantRows(ZMatrix &inequalities, ZMatrix &equations, bool removeInequalityRedundancies)
    374381  {
    375           ensureCddInitialisation();
     382          ensureCddInitialisation();
    376383
    377384    int numberOfEqualities=equations.getHeight();
     
    784791std::string ZCone::toString()const
    785792{
    786         std::stringstream f;
    787         f<<*this;
    788         return f.str();
     793        std::stringstream f;
     794        f<<*this;
     795        return f.str();
    789796}
    790797
     
    989996  }
    990997*/
    991 //        ZCone dual(newGenerators,linealitySpace);
    992           ZCone dual(generators,linealitySpace);
     998//          ZCone dual(newGenerators,linealitySpace);
     999          ZCone dual(generators,linealitySpace);
    9931000//  dual.findFacets();
    9941001//  dual.canonicalize();
Note: See TracChangeset for help on using the changeset viewer.