cudd  3.0.0
The University of Colorado Decision Diagram Package
Macros | Typedefs | Functions
mtr.h File Reference

Multiway-branch tree manipulation. More...

#include <stdio.h>
Include dependency graph for mtr.h:

Go to the source code of this file.

Macros

#define MTR_DEFAULT   0x00000000
 
#define MTR_TERMINAL   0x00000001
 
#define MTR_SOFT   0x00000002
 
#define MTR_FIXED   0x00000004
 
#define MTR_NEWNODE   0x00000008
 

Typedefs

typedef struct MtrNode_ MtrNode
 multi-way tree node.
 

Functions

MtrNodeMtr_AllocNode (void)
 Allocates new tree node. More...
 
void Mtr_DeallocNode (MtrNode *node)
 Deallocates tree node. More...
 
MtrNodeMtr_InitTree (void)
 Initializes tree with one node. More...
 
void Mtr_FreeTree (MtrNode *node)
 Disposes of tree rooted at node. More...
 
MtrNodeMtr_CopyTree (MtrNode const *node, int expansion)
 Makes a copy of tree. More...
 
void Mtr_MakeFirstChild (MtrNode *parent, MtrNode *child)
 Makes child the first child of parent. More...
 
void Mtr_MakeLastChild (MtrNode *parent, MtrNode *child)
 Makes child the last child of parent. More...
 
MtrNodeMtr_CreateFirstChild (MtrNode *parent)
 Creates a new node and makes it the first child of parent. More...
 
MtrNodeMtr_CreateLastChild (MtrNode *parent)
 Creates a new node and makes it the last child of parent. More...
 
void Mtr_MakeNextSibling (MtrNode *first, MtrNode *second)
 Makes second the next sibling of first. More...
 
void Mtr_PrintTree (MtrNode const *node)
 Prints a tree, one node per line. More...
 
MtrNodeMtr_InitGroupTree (int lower, int size)
 Allocate new tree. More...
 
MtrNodeMtr_MakeGroup (MtrNode *root, unsigned int low, unsigned int high, unsigned int flags)
 Makes a new group with size leaves starting at low. More...
 
MtrNodeMtr_DissolveGroup (MtrNode *group)
 Merges the children of ‘group’ with the children of its parent. More...
 
MtrNodeMtr_FindGroup (MtrNode *root, unsigned int low, unsigned int high)
 Finds a group with size leaves starting at low, if it exists. More...
 
int Mtr_SwapGroups (MtrNode *first, MtrNode *second)
 Swaps two children of a tree node. More...
 
void Mtr_ReorderGroups (MtrNode *treenode, int *permutation)
 Fix variable tree at the end of tree sifting. More...
 
void Mtr_PrintGroups (MtrNode const *root, int silent)
 Prints the groups as a parenthesized list. More...
 
int Mtr_PrintGroupedOrder (MtrNode const *root, int const *invperm, FILE *fp)
 Prints the variable order as a parenthesized list. More...
 
MtrNodeMtr_ReadGroups (FILE *fp, int nleaves)
 Reads groups from a file and creates a group tree. More...
 

Detailed Description

Multiway-branch tree manipulation.

This package provides two layers of functions. Functions of the lower level manipulate multiway-branch trees, implemented according to the classical scheme whereby each node points to its first child and its previous and next siblings. These functions are collected in mtrBasic.c.

Functions of the upper layer deal with group trees, that is the trees used by group sifting to represent the grouping of variables. These functions are collected in mtrGroup.c.

See also
The CUDD package documentation; specifically on group sifting.
Author
Fabio Somenzi

Function Documentation

◆ Mtr_AllocNode()

MtrNode* Mtr_AllocNode ( void  )

Allocates new tree node.

Returns
pointer to node.
Side effects None
See also
Mtr_DeallocNode

◆ Mtr_CopyTree()

MtrNode* Mtr_CopyTree ( MtrNode const *  node,
int  expansion 
)

Makes a copy of tree.

If parameter expansion is greater than 1, it will expand the tree by that factor. It is an error for expansion to be less than 1.

Returns
a pointer to the copy if successful; NULL otherwise.
Side effects None
See also
Mtr_InitTree

◆ Mtr_CreateFirstChild()

MtrNode* Mtr_CreateFirstChild ( MtrNode parent)

Creates a new node and makes it the first child of parent.

Returns
pointer to new child.
Side effects None
See also
Mtr_MakeFirstChild Mtr_CreateLastChild

◆ Mtr_CreateLastChild()

MtrNode* Mtr_CreateLastChild ( MtrNode parent)

Creates a new node and makes it the last child of parent.

Returns
pointer to new child.
Side effects None
See also
Mtr_MakeLastChild Mtr_CreateFirstChild

◆ Mtr_DeallocNode()

void Mtr_DeallocNode ( MtrNode node)

Deallocates tree node.

Side effects None
See also
Mtr_AllocNode
Parameters
nodenode to be deallocated

◆ Mtr_DissolveGroup()

MtrNode* Mtr_DissolveGroup ( MtrNode group)

Merges the children of ‘group’ with the children of its parent.

Disposes of the node pointed by group. If group is the root of the group tree, this procedure leaves the tree unchanged.

Returns
the pointer to the parent of ‘group’ upon successful termination; NULL otherwise.
Side effects None
See also
Mtr_MakeGroup
Parameters
groupgroup to be dissolved

◆ Mtr_FindGroup()

MtrNode* Mtr_FindGroup ( MtrNode root,
unsigned int  low,
unsigned int  size 
)

Finds a group with size leaves starting at low, if it exists.

This procedure relies on the low and size fields of each node. It also assumes that the children of each node are sorted in order of increasing low.

Returns
the pointer to the root of the group upon successful termination; NULL otherwise.
Side effects None
Parameters
rootroot of the group tree
lowlower bound of the group
sizeupper bound of the group

◆ Mtr_FreeTree()

void Mtr_FreeTree ( MtrNode node)

Disposes of tree rooted at node.

Side effects None
See also
Mtr_InitTree

◆ Mtr_InitGroupTree()

MtrNode* Mtr_InitGroupTree ( int  lower,
int  size 
)

Allocate new tree.

Allocate new tree with one node, whose low and size fields are specified by the lower and size parameters.

Returns
pointer to tree root.
Side effects None
See also
Mtr_InitTree Mtr_FreeTree

◆ Mtr_InitTree()

MtrNode* Mtr_InitTree ( void  )

Initializes tree with one node.

Returns
pointer to node.
Side effects None
See also
Mtr_FreeTree Mtr_InitGroupTree

◆ Mtr_MakeFirstChild()

void Mtr_MakeFirstChild ( MtrNode parent,
MtrNode child 
)

Makes child the first child of parent.

Side effects None
See also
Mtr_MakeLastChild Mtr_CreateFirstChild

◆ Mtr_MakeGroup()

MtrNode* Mtr_MakeGroup ( MtrNode root,
unsigned int  low,
unsigned int  size,
unsigned int  flags 
)

Makes a new group with size leaves starting at low.

If the new group intersects an existing group, it must either contain it or be contained by it. This procedure relies on the low and size fields of each node. It also assumes that the children of each node are sorted in order of increasing low. In case of a valid request, the flags of the new group are set to the value passed in ‘flags.’

Returns
the pointer to the root of the new group upon successful termination; NULL otherwise. If the group already exists, the pointer to its root is returned.
Side effects None
See also
Mtr_DissolveGroup Mtr_ReadGroups Mtr_FindGroup
Parameters
rootroot of the group tree
lowlower bound of the group
sizesize of the group
flagsflags for the new group

◆ Mtr_MakeLastChild()

void Mtr_MakeLastChild ( MtrNode parent,
MtrNode child 
)

Makes child the last child of parent.

Side effects None
See also
Mtr_MakeFirstChild Mtr_CreateLastChild

◆ Mtr_MakeNextSibling()

void Mtr_MakeNextSibling ( MtrNode first,
MtrNode second 
)

Makes second the next sibling of first.

Second becomes a child of the parent of first.

Side effects None

◆ Mtr_PrintGroupedOrder()

int Mtr_PrintGroupedOrder ( MtrNode const *  root,
int const *  invperm,
FILE *  fp 
)

Prints the variable order as a parenthesized list.

After each group, the group's flag are printed, preceded by a ‘|’. For each flag (except MTR_TERMINAL) a character is printed.

  • F: MTR_FIXED
  • N: MTR_NEWNODE
  • S: MTR_SOFT

The second argument, gives the map from levels to variable indices.

Returns
1 if successful; 0 otherwise.
Side effects None
See also
Mtr_PrintGroups
Parameters
rootroot of the group tree
invpermmap from levels to indices
fpoutput file

◆ Mtr_PrintGroups()

void Mtr_PrintGroups ( MtrNode const *  root,
int  silent 
)

Prints the groups as a parenthesized list.

After each group, the group's flag are printed, preceded by a ‘|’. For each flag (except MTR_TERMINAL) a character is printed.

  • F: MTR_FIXED
  • N: MTR_NEWNODE
  • S: MTR_SOFT

The second argument, silent, if different from 0, causes Mtr_PrintGroups to only check the syntax of the group tree.

Side effects None
See also
Mtr_PrintTree
Parameters
rootroot of the group tree
silentflag to check tree syntax only

◆ Mtr_PrintTree()

void Mtr_PrintTree ( MtrNode const *  node)

Prints a tree, one node per line.

Side effects None
See also
Mtr_PrintGroups

◆ Mtr_ReadGroups()

MtrNode* Mtr_ReadGroups ( FILE *  fp,
int  nleaves 
)

Reads groups from a file and creates a group tree.

Each group is specified by three fields:

 low size flags.

Low and size are (short) integers. Flags is a string composed of the following characters (with associated translation):

  • D: MTR_DEFAULT
  • F: MTR_FIXED
  • N: MTR_NEWNODE
  • S: MTR_SOFT
  • T: MTR_TERMINAL

Normally, the only flags that are needed are D and F. Groups and fields are separated by white space (spaces, tabs, and newlines).

Returns
a pointer to the group tree if successful; NULL otherwise.
Side effects None
See also
Mtr_InitGroupTree Mtr_MakeGroup
Parameters
fpfile pointer
nleavesnumber of leaves of the new tree

◆ Mtr_ReorderGroups()

void Mtr_ReorderGroups ( MtrNode treenode,
int *  permutation 
)

Fix variable tree at the end of tree sifting.

Fix the levels in the variable tree sorting siblings according to them. It should be called on a non-NULL tree. It then maintains this invariant. It applies insertion sorting to the list of siblings The order is determined by permutation, which is used to find the new level of the node index. Index must refer to the first variable in the group.

Side effects The tree is modified.

◆ Mtr_SwapGroups()

int Mtr_SwapGroups ( MtrNode first,
MtrNode second 
)

Swaps two children of a tree node.

Adjusts the high and low fields of the two nodes and their descendants. The two children must be adjacent. However, first may be the younger sibling of second.

Returns
1 in case of success; 0 otherwise.
Side effects None
Parameters
firstfirst node to be swapped
secondsecond node to be swapped