Skip to content

Commit

Permalink
command
Browse files Browse the repository at this point in the history
  • Loading branch information
zfchu committed Oct 15, 2020
1 parent 0580098 commit dd46f9b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/also.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "commands/xmgcost2.hpp"
#include "commands/xagrw.hpp"
#include "commands/xagban.hpp"
#include "commands/stochastic.hpp"

ALICE_MAIN( also )

82 changes: 82 additions & 0 deletions src/commands/stochastic.hpp
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

0 comments on commit dd46f9b

Please sign in to comment.