-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* also: Advanced Logic Synthesis and Optimization tool | ||
* Copyright (C) 2019- Ningbo University, Ningbo, China */ | ||
|
||
/** | ||
* @file stochastic.hpp | ||
* | ||
* @brief stochastic circuit synthesis | ||
* | ||
* @author Zhufei | ||
* @since 0.1 | ||
*/ | ||
|
||
#ifndef STOCHASTIC_HPP | ||
#define STOCHASTIC_HPP | ||
|
||
#include <fstream> | ||
|
||
namespace alice | ||
{ | ||
|
||
class stochastic_command : public command | ||
{ | ||
public: | ||
explicit stochastic_command( const environment::ptr& env ) : command( env, "stochastic circuit synthesis" ) | ||
{ | ||
add_option( "filename, -f", filename, "the input txt file name" ); | ||
} | ||
|
||
protected: | ||
void execute() | ||
{ | ||
std::string line; | ||
std::ifstream myfile( filename ); | ||
|
||
if( myfile.is_open() ) | ||
{ | ||
unsigned line_index = 0u; | ||
|
||
while( std::getline( myfile, line ) ) | ||
{ | ||
if( line_index == 0u ) { num_vars = std::stoi( line ); } | ||
if( line_index == 1u ) { n = std::stoi( line ); } | ||
if( line_index == 2u ) { m = std::stoi( line ); } | ||
|
||
if( line_index == 3u ) | ||
{ | ||
std::stringstream ss( line ); | ||
|
||
unsigned tmp; | ||
|
||
while( ss >> tmp ) | ||
{ | ||
vector.push_back( tmp ); | ||
} | ||
} | ||
line_index++; | ||
} | ||
|
||
myfile.close(); | ||
|
||
std::cout << " num_vars : " << num_vars << "\n" | ||
<< " n : " << n << "\n" | ||
<< " m : " << m << std::endl; | ||
} | ||
else | ||
{ | ||
std::cerr << "Cannot open input file \n"; | ||
} | ||
} | ||
|
||
private: | ||
std::string filename = "vector.txt"; | ||
unsigned num_vars; //the number of variables | ||
unsigned n; //the highest power | ||
unsigned m; //the number control the accuracy | ||
std::vector<unsigned> vector; | ||
}; | ||
|
||
ALICE_ADD_COMMAND( stochastic, "Various" ) | ||
} | ||
|
||
#endif |