Class JFactory


public class JFactory extends BDDFactoryIntImpl
This is a 100% Java implementation of the BDD factory. It is based on the C source code for BuDDy. As such, the implementation is very ugly, but it works. Like BuDDy, it uses a reference counting scheme for garbage collection.
  • Field Details

    • FLUSH_CACHE_ON_GC

      public static boolean FLUSH_CACHE_ON_GC
      Flush the operation cache on every garbage collection. If this is false, we only clean the collected entries on every GC, rather than emptying the whole cache. For most problems, you should keep this set to true.
  • Method Details

    • init

      public static BDDFactory init(int nodenum, int cachesize)
    • makePair

      public BDDPairing makePair()
      Description copied from class: BDDFactory
      Make a new BDDPairing object.

      Compare to bdd_newpair.

      Specified by:
      makePair in class BDDFactory
      Returns:
      BDD pairing
    • addref_impl

      protected void addref_impl(int v)
      Specified by:
      addref_impl in class BDDFactoryIntImpl
    • delref_impl

      protected void delref_impl(int v)
      Specified by:
      delref_impl in class BDDFactoryIntImpl
    • zero_impl

      protected int zero_impl()
      Specified by:
      zero_impl in class BDDFactoryIntImpl
    • one_impl

      protected int one_impl()
      Specified by:
      one_impl in class BDDFactoryIntImpl
    • universe_impl

      protected int universe_impl()
      Overrides:
      universe_impl in class BDDFactoryIntImpl
    • invalid_bdd_impl

      protected int invalid_bdd_impl()
      Specified by:
      invalid_bdd_impl in class BDDFactoryIntImpl
    • var_impl

      protected int var_impl(int v)
      Specified by:
      var_impl in class BDDFactoryIntImpl
    • level_impl

      protected int level_impl(int v)
      Specified by:
      level_impl in class BDDFactoryIntImpl
    • low_impl

      protected int low_impl(int v)
      Specified by:
      low_impl in class BDDFactoryIntImpl
    • high_impl

      protected int high_impl(int v)
      Specified by:
      high_impl in class BDDFactoryIntImpl
    • ithVar_impl

      protected int ithVar_impl(int var)
      Specified by:
      ithVar_impl in class BDDFactoryIntImpl
    • nithVar_impl

      protected int nithVar_impl(int var)
      Specified by:
      nithVar_impl in class BDDFactoryIntImpl
    • makenode_impl

      protected int makenode_impl(int lev, int lo, int hi)
      Specified by:
      makenode_impl in class BDDFactoryIntImpl
    • ite_impl

      protected int ite_impl(int v1, int v2, int v3)
      Specified by:
      ite_impl in class BDDFactoryIntImpl
    • apply_impl

      protected int apply_impl(int v1, int v2, BDDFactory.BDDOp opr)
      Specified by:
      apply_impl in class BDDFactoryIntImpl
    • not_impl

      protected int not_impl(int v1)
      Specified by:
      not_impl in class BDDFactoryIntImpl
    • applyAll_impl

      protected int applyAll_impl(int v1, int v2, BDDFactory.BDDOp opr, int v3)
      Specified by:
      applyAll_impl in class BDDFactoryIntImpl
    • applyEx_impl

      protected int applyEx_impl(int v1, int v2, BDDFactory.BDDOp opr, int v3)
      Specified by:
      applyEx_impl in class BDDFactoryIntImpl
    • applyUni_impl

      protected int applyUni_impl(int v1, int v2, BDDFactory.BDDOp opr, int v3)
      Specified by:
      applyUni_impl in class BDDFactoryIntImpl
    • compose_impl

      protected int compose_impl(int v1, int v2, int var)
      Specified by:
      compose_impl in class BDDFactoryIntImpl
    • constrain_impl

      protected int constrain_impl(int v1, int v2)
      Specified by:
      constrain_impl in class BDDFactoryIntImpl
    • restrict_impl

      protected int restrict_impl(int v1, int v2)
      Specified by:
      restrict_impl in class BDDFactoryIntImpl
    • simplify_impl

      protected int simplify_impl(int v1, int v2)
      Specified by:
      simplify_impl in class BDDFactoryIntImpl
    • support_impl

      protected int support_impl(int v)
      Specified by:
      support_impl in class BDDFactoryIntImpl
    • exist_impl

      protected int exist_impl(int v1, int v2)
      Specified by:
      exist_impl in class BDDFactoryIntImpl
    • forAll_impl

      protected int forAll_impl(int v1, int v2)
      Specified by:
      forAll_impl in class BDDFactoryIntImpl
    • unique_impl

      protected int unique_impl(int v1, int v2)
      Specified by:
      unique_impl in class BDDFactoryIntImpl
    • fullSatOne_impl

      protected int fullSatOne_impl(int v)
      Specified by:
      fullSatOne_impl in class BDDFactoryIntImpl
    • replace_impl

      protected int replace_impl(int v, BDDPairing p)
      Specified by:
      replace_impl in class BDDFactoryIntImpl
    • veccompose_impl

      protected int veccompose_impl(int v, BDDPairing p)
      Specified by:
      veccompose_impl in class BDDFactoryIntImpl
    • nodeCount_impl

      protected int nodeCount_impl(int v)
      Specified by:
      nodeCount_impl in class BDDFactoryIntImpl
    • pathCount_impl

      protected double pathCount_impl(int v)
      Specified by:
      pathCount_impl in class BDDFactoryIntImpl
    • satCount_impl

      protected double satCount_impl(int v)
      Specified by:
      satCount_impl in class BDDFactoryIntImpl
    • satOne_impl

      protected int satOne_impl(int v)
      Specified by:
      satOne_impl in class BDDFactoryIntImpl
    • satOne_impl2

      protected int satOne_impl2(int v1, int v2, boolean pol)
      Specified by:
      satOne_impl2 in class BDDFactoryIntImpl
    • nodeCount_impl2

      protected int nodeCount_impl2(int[] v)
      Specified by:
      nodeCount_impl2 in class BDDFactoryIntImpl
    • varProfile_impl

      protected int[] varProfile_impl(int v)
      Specified by:
      varProfile_impl in class BDDFactoryIntImpl
    • printTable_impl

      protected void printTable_impl(int v)
      Specified by:
      printTable_impl in class BDDFactoryIntImpl
    • initialize

      protected void initialize(int initnodesize, int cs)
      Description copied from class: BDDFactory
      Compare to bdd_init.
      Specified by:
      initialize in class BDDFactory
      Parameters:
      initnodesize - the initial number of BDD nodes
      cs - the size of caches used by the BDD operators
    • addVarBlock

      public void addVarBlock(int first, int last, boolean fixed)
      Description copied from class: BDDFactory
      Adds a new variable block for reordering.

      Creates a new variable block with the variables numbered first through last, inclusive.

      The fixed parameter sets the block to be fixed (no reordering of its child blocks is allowed) or free.

      Compare to bdd_intaddvarblock.

      Specified by:
      addVarBlock in class BDDFactory
      Parameters:
      first - first variable number
      last - last variable number
      fixed - fixed or free
    • varBlockAll

      public void varBlockAll()
      Description copied from class: BDDFactory
      Add a variable block for all variables.

      Adds a variable block for all BDD variables declared so far. Each block contains one variable only. More variable blocks can be added later with the use of addVarBlock -- in this case the tree of variable blocks will have the blocks of single variables as the leafs.

      Compare to bdd_varblockall.

      Specified by:
      varBlockAll in class BDDFactory
    • clearVarBlocks

      public void clearVarBlocks()
      Description copied from class: BDDFactory
      Clears all the variable blocks that have been defined by calls to addVarBlock.

      Compare to bdd_clrvarblocks.

      Specified by:
      clearVarBlocks in class BDDFactory
    • printOrder

      public void printOrder()
      Description copied from class: BDDFactory
      Prints an indented list of the variable blocks.

      Compare to bdd_printorder.

      Specified by:
      printOrder in class BDDFactory
    • getNodeTableSize

      public int getNodeTableSize()
      Description copied from class: BDDFactory
      Get the number of allocated nodes. This includes both dead and active nodes.

      Compare to bdd_getallocnum.

      Specified by:
      getNodeTableSize in class BDDFactory
      Returns:
      number of allocated nodes
    • setNodeTableSize

      public int setNodeTableSize(int size)
      Description copied from class: BDDFactory
      Sets the node table size.
      Specified by:
      setNodeTableSize in class BDDFactory
      Parameters:
      size - new size of table
      Returns:
      old size of table
    • setCacheSize

      public int setCacheSize(int v)
      Description copied from class: BDDFactory
      Sets cache size.
      Specified by:
      setCacheSize in class BDDFactory
      Parameters:
      v - new cache size
      Returns:
      old cache size
    • isZDD

      public boolean isZDD()
      Description copied from class: BDDFactory
      Returns true if this is a ZDD factory, false otherwise.
      Overrides:
      isZDD in class BDDFactory
      Returns:
      true if this is a ZDD factory, false otherwise
    • isInitialized

      public boolean isInitialized()
      Description copied from class: BDDFactory
      Returns true if this BDD factory is initialized, false otherwise.

      Compare to bdd_isrunning.

      Specified by:
      isInitialized in class BDDFactory
      Returns:
      true if this BDD factory is initialized
    • setError

      public void setError(int code)
      Description copied from class: BDDFactory
      Sets the error condition. This will cause the BDD package to throw an exception at the next garbage collection.
      Specified by:
      setError in class BDDFactory
      Parameters:
      code - the error code to set
    • clearError

      public void clearError()
      Description copied from class: BDDFactory
      Clears any outstanding error condition.
      Specified by:
      clearError in class BDDFactory
    • setMaxNodeNum

      public int setMaxNodeNum(int size)
      Description copied from class: BDDFactory
      Set the maximum available number of BDD nodes.

      Compare to bdd_setmaxnodenum.

      Specified by:
      setMaxNodeNum in class BDDFactory
      Parameters:
      size - maximum number of nodes
      Returns:
      old value
    • setMinFreeNodes

      public double setMinFreeNodes(double x)
      Description copied from class: BDDFactory
      Set minimum percentage of nodes to be reclaimed after a garbage collection. If this percentage is not reclaimed, the node table will be grown. The range of x is 0..1. The default is .20.

      Compare to bdd_setminfreenodes.

      Specified by:
      setMinFreeNodes in class BDDFactory
      Parameters:
      x - number from 0 to 1
      Returns:
      old value
    • setMaxIncrease

      public int setMaxIncrease(int x)
      Description copied from class: BDDFactory
      Set maximum number of nodes by which to increase node table after a garbage collection.

      Compare to bdd_setmaxincrease.

      Specified by:
      setMaxIncrease in class BDDFactory
      Parameters:
      x - maximum number of nodes by which to increase node table
      Returns:
      old value
    • setIncreaseFactor

      public double setIncreaseFactor(double x)
      Description copied from class: BDDFactory
      Set factor by which to increase node table after a garbage collection. The amount of growth is still limited by setMaxIncrease().
      Specified by:
      setIncreaseFactor in class BDDFactory
      Parameters:
      x - factor by which to increase node table after GC
      Returns:
      old value
    • getNodeNum

      public int getNodeNum()
      Description copied from class: BDDFactory
      Get the number of active nodes in use. Note that dead nodes that have not been reclaimed yet by a garbage collection are counted as active.

      Compare to bdd_getnodenum.

      Specified by:
      getNodeNum in class BDDFactory
      Returns:
      number of active nodes in use
    • getCacheSize

      public int getCacheSize()
      Description copied from class: BDDFactory
      Get the current size of the cache, in entries.
      Specified by:
      getCacheSize in class BDDFactory
      Returns:
      size of cache
    • reorderGain

      public int reorderGain()
      Description copied from class: BDDFactory
      Calculate the gain in size after a reordering. The value returned is (100*(A-B))/A, where A is previous number of used nodes and B is current number of used nodes.

      Compare to bdd_reorder_gain.

      Specified by:
      reorderGain in class BDDFactory
      Returns:
      gain in size after a reordering
    • printStat

      public void printStat()
      Description copied from class: BDDFactory
      Print cache statistics.

      Compare to bdd_printstat.

      Specified by:
      printStat in class BDDFactory
    • setCacheRatio

      public double setCacheRatio(double x)
      Description copied from class: BDDFactory
      Sets the cache ratio for the operator caches. When the node table grows, operator caches will also grow to maintain the ratio.

      Compare to bdd_setcacheratio.

      Specified by:
      setCacheRatio in class BDDFactory
      Parameters:
      x - cache ratio
      Returns:
      old cache ratio
    • varNum

      public int varNum()
      Description copied from class: BDDFactory
      Returns the number of defined variables.

      Compare to bdd_varnum.

      Specified by:
      varNum in class BDDFactory
      Returns:
      number of defined variables
    • setVarNum

      public int setVarNum(int num)
      Description copied from class: BDDFactory
      Set the number of used BDD variables. It can be called more than one time, but only to increase the number of variables.

      Compare to bdd_setvarnum.

      Specified by:
      setVarNum in class BDDFactory
      Parameters:
      num - new number of BDD variables
      Returns:
      old number of BDD variables
    • printAll

      public void printAll()
      Description copied from class: BDDFactory
      Prints all used entries in the node table.

      Compare to bdd_printall.

      Specified by:
      printAll in class BDDFactory
    • load

      public BDD load(BufferedReader in, int[] translate) throws IOException
      Description copied from class: BDDFactory
      Loads a BDD from the given input, translating BDD variables according to the given map.

      Compare to bdd_load.

      Overrides:
      load in class BDDFactory
      Parameters:
      in - reader
      translate - variable translation map
      Returns:
      BDD
      Throws:
      IOException - In case of an I/O error.
    • save

      public void save(BufferedWriter out, BDD b) throws IOException
      Description copied from class: BDDFactory
      Saves a BDD to an output writer.

      Compare to bdd_save.

      Overrides:
      save in class BDDFactory
      Parameters:
      out - writer
      b - BDD
      Throws:
      IOException - In case of an I/O error.
    • setVarOrder

      public void setVarOrder(int[] neworder)
      Description copied from class: BDDFactory
      This function sets the current variable order to be the one defined by neworder. The variable parameter neworder is interpreted as a sequence of variable indices and the new variable order is exactly this sequence. The array must contain all the variables defined so far. If, for instance the current number of variables is 3 and neworder contains [1; 0; 2] then the new variable order is v1 < v0 < v2.

      Note that this operation must walk through the node table many times, and therefore it is much more efficient to call this when the node table is small.

      Specified by:
      setVarOrder in class BDDFactory
      Parameters:
      neworder - new variable order
    • level2Var

      public int level2Var(int level)
      Description copied from class: BDDFactory
      Convert from a BDD level to a BDD variable.

      Compare to bdd_level2var.

      Specified by:
      level2Var in class BDDFactory
      Parameters:
      level - BDD level
      Returns:
      BDD variable
    • var2Level

      public int var2Level(int var)
      Description copied from class: BDDFactory
      Convert from a BDD variable to a BDD level.

      Compare to bdd_var2level.

      Specified by:
      var2Level in class BDDFactory
      Parameters:
      var - BDD variable
      Returns:
      BDD level
    • getReorderTimes

      public int getReorderTimes()
      Description copied from class: BDDFactory
      Returns the number of allowed reorderings left. This value can be defined by autoReorder.

      Compare to bdd_getreorder_times.

      Specified by:
      getReorderTimes in class BDDFactory
      Returns:
      number of allowed reorderings left
    • disableReorder

      public void disableReorder()
      Description copied from class: BDDFactory
      Disable automatic reordering until enableReorder is called. Reordering is enabled by default as soon as any variable blocks have been defined.

      Compare to bdd_disable_reorder.

      Specified by:
      disableReorder in class BDDFactory
    • enableReorder

      public void enableReorder()
      Description copied from class: BDDFactory
      Enable automatic reordering after a call to disableReorder.

      Compare to bdd_enable_reorder.

      Specified by:
      enableReorder in class BDDFactory
    • reorderVerbose

      public int reorderVerbose(int v)
      Description copied from class: BDDFactory
      Enables verbose information about reordering. A value of zero means no information, one means some information and greater than one means lots of information.
      Specified by:
      reorderVerbose in class BDDFactory
      Parameters:
      v - the new verbose level
      Returns:
      the old verbose level
    • reorder

      public void reorder(BDDFactory.ReorderMethod m)
      Description copied from class: BDDFactory
      Reorder the BDD with the given method.

      Compare to bdd_reorder.

      Specified by:
      reorder in class BDDFactory
      Parameters:
      m - reorder method
    • autoReorder

      public void autoReorder(BDDFactory.ReorderMethod method)
      Description copied from class: BDDFactory
      Enables automatic reordering. If method is REORDER_NONE then automatic reordering is disabled.

      Compare to bdd_autoreorder.

      Specified by:
      autoReorder in class BDDFactory
      Parameters:
      method - reorder method
    • autoReorder

      public void autoReorder(BDDFactory.ReorderMethod method, int max)
      Description copied from class: BDDFactory
      Enables automatic reordering with the given (maximum) number of reorderings. If method is REORDER_NONE then automatic reordering is disabled.

      Compare to bdd_autoreorder_times.

      Specified by:
      autoReorder in class BDDFactory
      Parameters:
      method - reorder method
      max - maximum number of reorderings
    • swapVar

      public void swapVar(int v1, int v2)
      Description copied from class: BDDFactory
      Swap two variables.

      Compare to bdd_swapvar.

      Specified by:
      swapVar in class BDDFactory
      Parameters:
      v1 - first variable
      v2 - second variable
    • getReorderMethod

      public BDDFactory.ReorderMethod getReorderMethod()
      Description copied from class: BDDFactory
      Returns the current reorder method as defined by autoReorder.

      Compare to bdd_getreorder_method.

      Specified by:
      getReorderMethod in class BDDFactory
      Returns:
      ReorderMethod
    • validateAll

      public void validateAll()
    • validateBDD

      public void validateBDD(BDD b)
    • cloneFactory

      public JFactory cloneFactory()
    • copyNode

      public BDD copyNode(BDD that)
      Use this function to translate BDD's from a JavaFactory into its clone. This will only work immediately after cloneFactory() is called, and before any other BDD operations are performed.
      Parameters:
      that - BDD in old factory
      Returns:
      a BDD in the new factory
    • reverseAllDomains

      public void reverseAllDomains()
    • reverseDomain

      public void reverseDomain(BDDDomain d)
    • reverseDomain0

      protected void reverseDomain0(BDDDomain d)
    • setVarOrder

      public void setVarOrder(String ordering)
    • setVarOrder

      public void setVarOrder(List<Object> domains)
      Set the variable order to be the given list of domains.
      Parameters:
      domains - domain order
    • getParent

      protected com.github.javabdd.JFactory.BddTree getParent(com.github.javabdd.JFactory.BddTree child)
    • getParent

      protected com.github.javabdd.JFactory.BddTree getParent(com.github.javabdd.JFactory.BddTree parent, com.github.javabdd.JFactory.BddTree child)
    • getBlock

      protected com.github.javabdd.JFactory.BddTree getBlock(com.github.javabdd.JFactory.BddTree t, int low, int high)
    • done

      public void done()
      Description copied from class: BDDFactory
      This function frees all memory used by the BDD package and resets the package to its uninitialized state. The BDD package is no longer usable after this call.

      Compare to bdd_done.

      Overrides:
      done in class BDDFactoryIntImpl