/usr/include/polybori/CCuddInterface.h is in libpolybori-dev 0.5~rc1-2.1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | // -*- c++ -*-
//*****************************************************************************
/** @file CCuddInterface.h
*
* @author Alexander Dreyer
* @date 2007-07-05
*
* This files defines a replacement for the decision diagram manager of CUDD's
* C++ interface.
*
* @par Copyright:
* (c) 2007 by The PolyBoRi Team
*
* @internal
* @version \$Id: CCuddInterface.h,v 1.9 2008/07/08 21:41:58 alexanderdreyer Exp $
*
* @par History:
* @verbatim
* $Log: CCuddInterface.h,v $
* Revision 1.9 2008/07/08 21:41:58 alexanderdreyer
* Merge: from developer's repository
*
* Revision 1.15 2008/01/16 17:10:17 dreyer
* CHANGE: term-iterators use correct manager now
*
* Revision 1.14 2008/01/11 16:58:56 dreyer
* CHANGE: Experimenting with iterators and correct rings
*
* Revision 1.13 2007/12/18 22:05:40 dreyer
* CHANGE: persistent variables computed on manaer initialization
*
* Revision 1.12 2007/12/18 10:20:16 dreyer
* CHANGE CNamedManager removed, names are in core now
*
* Revision 1.11 2007/11/06 16:36:55 dreyer
* + minor changes
*
* Revision 1.10 2007/07/19 11:41:47 dreyer
* CHANGE: clean-up
*
* Revision 1.9 2007/07/18 15:46:14 dreyer
* CHANGE: added documentation
*
* Revision 1.8 2007/07/18 15:11:00 dreyer
* CHANGE: simplified handle_error
*
* Revision 1.7 2007/07/18 07:36:34 dreyer
* CHANGE: some clean-ups
*
* Revision 1.6 2007/07/18 07:17:26 dreyer
* CHANGE: some clean-ups
*
* Revision 1.5 2007/07/17 15:56:59 dreyer
* ADD: header file for CCuddZDD; clean-up
*
* Revision 1.4 2007/07/13 15:05:23 dreyer
* CHANGE: cleaned up once more
*
* Revision 1.3 2007/07/12 15:32:31 dreyer
* CHANGE: cleanup using preprocessor meta-programming
*
* Revision 1.2 2007/07/10 14:53:27 dreyer
* CHANGE: clean-up
*
* Revision 1.1 2007/07/06 14:04:21 dreyer
* ADD: newly written C++_interface for Cudd
*
* @endverbatim
**/
//*****************************************************************************
// include basic definitions
#include "CCuddZDD.h"
#ifndef CCuddInterface_h_
#define CCuddInterface_h_
BEGIN_NAMESPACE_PBORI
/// @name Define templates for generating member functions from CUDD procedures
//@{
#define PB_CUDDMGR_READ(count, data, funcname) data funcname() const { \
return BOOST_PP_CAT(Cudd_, funcname)(getManager()); }
#define PB_CUDDMGR_SWITCH(count, data, funcname) void funcname() { \
BOOST_PP_CAT(Cudd_, funcname)(getManager()); }
#define PB_CUDDMGR_SET(count, data, funcname) void funcname(data arg) { \
BOOST_PP_CAT(Cudd_, funcname)(getManager(), arg); }
//@}
/** @class CCuddInterface
* @brief This class defines a C++ interface to @c CUDD's decicion diagram
* manager.
*
* The purpose of this wrapper is just to provide an efficient and save way of
* handling the decision diagram management. It corrects some short-comings of
* CUDD's built-in interface.
*
* @attention This class is intented for internal use only.
* Use the highlevel classes CDDManager<CCuddInterface> or BoolePolyRing
* instead.
**/
class CCuddInterface {
public:
PB_DECLARE_CUDD_TYPES(CCuddCore)
/// @name Generic names for related data types
//@{
typedef CCuddInterface self;
typedef CCuddCore core_type;
typedef core_type::mgrcore_ptr mgrcore_ptr;
typedef CCuddZDD dd_type;
typedef self tmp_ref;
//@}
/// Define type for storing names of variables
typedef CVariableNames variable_names_type;
/// Define type for getting names of variables
typedef variable_names_type::const_reference const_varname_reference;
/// Initialize CUDD-like decision diagram manager
CCuddInterface(size_type numVars = 0,
size_type numVarsZ = 0,
size_type numSlots = CUDD_UNIQUE_SLOTS,
size_type cacheSize = CUDD_CACHE_SLOTS,
unsigned long maxMemory = 0):
pMgr (new core_type(numVars, numVarsZ, numSlots, cacheSize, maxMemory)) {
}
/// Copy constructor
CCuddInterface(const self& rhs): pMgr(rhs.pMgr) {}
/// Construct interface for already initialized manager
CCuddInterface(mgrcore_ptr rhs): pMgr(rhs) {};
/// Destructor
~CCuddInterface() {}
/// Define function for error handling
errorfunc_type setHandler(errorfunc_type newHandler) {
errorfunc_type oldHandler = pMgr->errorHandler;
pMgr->errorHandler = newHandler;
return oldHandler;
}
/// Extract function for error handling
errorfunc_type getHandler() const { return pMgr->errorHandler; }
/// Get pure CUDD structure
mgrcore_type getManager() const { return pMgr->manager; }
/// Get (shared) pointer to initialized manager
mgrcore_ptr managerCore() const { return pMgr; }
/// @name Manage eloquence
//@{
void makeVerbose() { pMgr->verbose = true; }
void makeTerse() { pMgr->verbose = false; }
bool isVerbose() const { return pMgr->verbose; }
//@}
/// Print statistical information
void info() const { checkedResult(Cudd_PrintInfo(getManager(),stdout)); }
void checkReturnValue(const node_type result) const {
checkReturnValue(result != NULL);
}
void checkReturnValue(const int result) const {
if UNLIKELY(result == 0) {
handle_error<CUDD_MEMORY_OUT> tmp(pMgr->errorHandler);
tmp(Cudd_ReadErrorCode(getManager()));
}
}
/// Assignment operation
self& operator=(const self & right) {
pMgr = right.pMgr;
return *this;
}
/// Get ZDD variable
CCuddZDD zddVar(idx_type idx) const { return apply(Cudd_zddIthVar, idx); }
/// Get 1-terminal for ZDDs
CCuddZDD zddOne(idx_type iMax) const { return apply(Cudd_ReadZddOne, iMax); }
/// Get 0-terminal for ZDDs
CCuddZDD zddZero() const { return apply(Cudd_ReadZero); }
/// Get 1-terminal for ZDDs
CCuddZDD zddOne() const {
return checkedResult(DD_ONE(getManager()));
}
/// @name Member functions mimicking/interfacing with CUDD procedures
/// @note See preprocessor generated members below
//@{
int ReorderingStatusZdd(Cudd_ReorderingType * method) const {
return Cudd_ReorderingStatusZdd(getManager(), method);
}
idx_type ReadPermZdd(idx_type i) const {
return Cudd_ReadPermZdd(getManager(), i);
}
idx_type ReadInvPermZdd(idx_type i) const {
return Cudd_ReadInvPermZdd(getManager(), i);
}
void AddHook(DD_HFP f, Cudd_HookType where) {
checkedResult(Cudd_AddHook(getManager(), f, where));
}
void RemoveHook(DD_HFP f, Cudd_HookType where) {
checkedResult(Cudd_RemoveHook(getManager(), f, where));
}
int IsInHook(DD_HFP f, Cudd_HookType where) const {
return Cudd_IsInHook(getManager(), f, where);
}
void EnableReorderingReporting() {
checkedResult(Cudd_EnableReorderingReporting(getManager()));
}
void DisableReorderingReporting() {
checkedResult(Cudd_DisableReorderingReporting(getManager()));
}
void DebugCheck(){ checkedResult(Cudd_DebugCheck(getManager())); }
void CheckKeys(){ checkedResult(Cudd_CheckKeys(getManager())); }
void PrintLinear() { checkedResult(Cudd_PrintLinear(getManager())); }
int ReadLinear(int x, int y) { return Cudd_ReadLinear(getManager(), x, y); }
size_type Prime(size_type pr) const { return Cudd_Prime(pr); }
void PrintVersion(FILE * fp) const { cout.flush(); Cudd_PrintVersion(fp); }
MtrNode* MakeZddTreeNode(size_type low, size_type size, size_type type) {
return Cudd_MakeZddTreeNode(getManager(), low, size, type);
}
void zddPrintSubtable() const{
cout.flush();
Cudd_zddPrintSubtable(getManager());
}
void zddReduceHeap(Cudd_ReorderingType heuristic, int minsize) {
checkedResult(Cudd_zddReduceHeap(getManager(), heuristic, minsize));
}
void zddShuffleHeap(int * permutation) {
checkedResult(Cudd_zddShuffleHeap(getManager(), permutation));
}
void zddSymmProfile(int lower, int upper) const {
Cudd_zddSymmProfile(getManager(), lower, upper);
}
int SharingSize(dd_type* nodes, int nlen) const {
typedef boost::scoped_array<node_type> node_array;
node_array nodeArray(new node_type[nlen]);
std::transform(nodes, nodes + nlen, nodeArray.get(), get_node<dd_type>());
return checkedResult(Cudd_SharingSize(nodeArray.get(), nlen));
}
/// @note Preprocessor generated members
/// @code
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_SET, size_type,
(SetMinHit)(SetLooseUpTo)(SetMaxCacheHard)(SetMaxLive) )
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_SET, int,
(SetSiftMaxVar)(SetSiftMaxSwap)(SetRecomb)(SetSymmviolation)
(SetArcviolation)(SetPopulationSize)(SetNumberXovers)
)
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_SET, FILE*, (SetStdout)(SetStderr))
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_SWITCH, BOOST_PP_NIL,
(zddRealignEnable)(zddRealignDisable)
(AutodynDisableZdd)(FreeZddTree)
(EnableGarbageCollection)(DisableGarbageCollection)
(TurnOnCountDead)(TurnOffCountDead)(ClearErrorCode)
)
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, double,
(ReadCacheUsedSlots)(ReadCacheLookUps)(ReadCacheHits)
(ReadSwapSteps)(ReadMaxGrowth)(AverageDistance)
)
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, size_type,
(ReadCacheSlots)(ReadMinHit)(ReadLooseUpTo)(ReadMaxCache)
(ReadMaxCacheHard)(ReadSlots)(ReadKeys)(ReadDead)(ReadMinDead)
(ReadNextReordering)(ReadMaxLive)
)
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, int,
(zddRealignmentEnabled)(ReadZddSize)(ReadReorderings)(ReadSiftMaxVar)
(ReadSiftMaxSwap)(ReadGarbageCollections)(GarbageCollectionEnabled)
(DeadAreCounted)(ReadRecomb)
(ReadPopulationSize)(ReadSymmviolation)(ReadArcviolation)
(ReadNumberXovers)(ReorderingReporting)(ReadErrorCode)
)
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, long,
(ReadReorderingTime)(ReadGarbageCollectionTime)
(ReadPeakNodeCount)(zddReadNodeCount)
)
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, large_size_type,
(ReadMemoryInUse)(ReadMaxMemory) )
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, FILE*, (ReadStdout)(ReadStderr))
BOOST_PP_SEQ_FOR_EACH(PB_CUDDMGR_READ, MtrNode*, (ReadZddTree))
PB_CUDDMGR_SET(BOOST_PP_NIL, Cudd_ReorderingType, AutodynEnableZdd)
PB_CUDDMGR_SET(BOOST_PP_NIL, unsigned long, SetMaxMemory)
PB_CUDDMGR_SET(BOOST_PP_NIL, double, SetMaxGrowth)
PB_CUDDMGR_SET(BOOST_PP_NIL, MtrNode*, SetZddTree)
/** @endcode */
///
//@}
/// Set name of variable with index idx
void setName(idx_type idx, const_varname_reference varname) {
(pMgr->m_names).set(idx, varname);
}
/// Get name of variable with index idx
const_varname_reference getName(idx_type idx) const {
return (pMgr->m_names)[idx];
}
dd_type getVar(idx_type idx) const {
assert(idx < pMgr->m_vars.size());
return getDiagram(pMgr->m_vars[idx]);
}
/// Get number of managed variables
size_type nVariables() const {
return Cudd_ReadZddSize(getManager());
}
protected:
/// Convert to decision diagram
dd_type getDiagram(node_type result) const {
return dd_type(managerCore(), result);
}
/// Generate check result of previous node operation and convert
dd_type checkedResult(node_type result) const {
checkReturnValue(result);
return getDiagram(result);
}
/// Generate check numerical result of previous operation
idx_type checkedResult(idx_type result) const {
checkReturnValue(result);
return result;
}
/// Apply function to given index
dd_type apply(unary_int_function func, idx_type idx) const {
return checkedResult(func(getManager(), idx) );
}
/// Call function
dd_type apply(void_function func) const {
return checkedResult(func(getManager()) );
}
private:
mgrcore_ptr pMgr;
}; // CCuddInterface
#undef PB_CUDDMGR_READ
#undef PB_CUDDMGR_SWITCH
#undef PB_CUDDMGR_SET
END_NAMESPACE_PBORI
#endif
|