lsils / mockturtle

C++ logic network library
MIT License
210 stars 139 forks source link

Cut enumeration before and after node substitution in AIG #526

Closed nitabukoshi closed 2 years ago

nitabukoshi commented 2 years ago

The issue is the following:

Following is the code:

#include <mockturtle/mockturtle.hpp>
using namespace std;
int main(int argc, char *argv[])
{ 
  //AIG from file 
  mockturtle::aig_network aig;
  lorina::read_aiger("file.aig", mockturtle::aiger_reader(aig));

  //Cut enumeration parameters
  mockturtle::cut_enumeration_params cp;
  cp.cut_size = 3u;   //maximum number of leaves
  cp.cut_limit = 100u; //maximum number of computed cuts for a node

  //Cut enumeration algorithm from mockturtle
  auto cuts = mockturtle::cut_enumeration<mockturtle::aig_network, true>(aig, cp);
  cout<<"Number of cuts: "<<cuts.total_cuts()<<"\n"; 

  //Node to be substituted, index 21
  int node_index = 21;

  auto old_node = aig.index_to_node(node_index);
  auto& old_node_storage = aig._storage->nodes[old_node];
  int child0 = aig._storage->nodes[node_index].children[0u].index;
  int child1 = aig._storage->nodes[node_index].children[1u].index;
  auto child0_sig = aig.make_signal(aig.index_to_node(child0));
  auto child1_sig = aig.make_signal(aig.index_to_node(child1));

  //The new node we want instead of the old node
  auto new_node = aig.create_and(child0_sig, child1_sig); 

  aig.substitute_node( old_node, new_node );  

  cout<<"\nNode substituted...\n";
  cleanup_dangling(aig);

  cuts = mockturtle::cut_enumeration<mockturtle::aig_network, true>(aig, cp);
  cout<<"\nNumber of cuts after substitution: "<<cuts.total_cuts()<<"\n";  
}

Original AIG with node 21 Substituted 21 to 54 AIG terminal output

Thank you in advance for any help!

hriener commented 2 years ago
nitabukoshi commented 2 years ago
hriener commented 2 years ago
nitabukoshi commented 2 years ago

Thank you very much for your help!