viterbi_module::viterbi_module(int outputBits, int inputBits, int registersCount, int parallelism)
{
	_outputBits = outputBits;
	_inputBits = inputBits;
	_registersCount = registersCount;
	_parallelism = parallelism;

	// calculate constrain length
	_constrainLength = _inputBits * _registersCount;

	if (_constrainLength > 32) 
	{
		cout << "ERROR: Constrain Length is limited to 32!\n";
		exit(1);
	}

	// initilize polynomials with random sets of bits to xor
	_xors.resize(_outputBits);
	srand(time(NULL));
	for (int i = 0; i < _outputBits; i++)
	{
		uint32_t numOfBits = pow(2, _constrainLength);
		_xors[i] = rand() % numOfBits;

		if (_xors[i] == 0) 
		{
			i--;
		}
	}

	_encoder = encoder(_inputBits, _outputBits, _constrainLength, _xors);
	_automata = automata(_inputBits, _outputBits, _constrainLength, _xors);
	_decoder = decoder(_inputBits, _outputBits, _constrainLength, _automata.GetAutomata(), _automata.GetInverseAutomata());
}
Esempio n. 2
0
void test_determinisation()
{
	std::cout << "Testing determinisation..." << std::endl << std::endl;

	State zero("0", state_type::NONFINAL);
	State one("1", state_type::NONFINAL);
	State two("2", state_type::NONFINAL);
	State three("3", state_type::FINAL);

	std::vector<State*> states;

	std::set<State*> zeroStatesA;
	std::set<State*> zeroStatesB;
	std::set<State*> oneStatesA;
	std::set<State*> twoStatesB;

	states.push_back(&zero);
	states.push_back(&one);
	states.push_back(&two);
	states.push_back(&three);

	zeroStatesA.insert(&zero);
	zeroStatesB.insert(&zero);
	zeroStatesB.insert(&one);
	oneStatesA.insert(&two);
	twoStatesB.insert(&three);

	std::unordered_map<char , std::set<State*> > zeroTransitions;
	std::unordered_map<char , std::set<State*> > oneTransitions;
	std::unordered_map<char , std::set<State*> > twoTransitions;
	std::unordered_map<char , std::set<State*> > threeTransitions;

	zeroTransitions['a'] = zeroStatesA;
	zeroTransitions['b'] = zeroStatesB;
	oneTransitions['a'] = oneStatesA;
	twoTransitions['b'] = twoStatesB;

	std::unordered_map< State*,  std::unordered_map<char , std::set<State*> > > transitions;

	transitions[&zero] = zeroTransitions;
	transitions[&one] = oneTransitions;
	transitions[&two] = twoTransitions;
	transitions[&three] = threeTransitions;

	Automata automata(transitions);
	automata.setInitial(&zero);
	automata.setCurrentState(&zero);
	automata.setStates(states);

	std::cout << "Before:" << std::endl << automata << std::endl;

	std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
	automata.determinise();
	std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();

	std::cout << "After: " << std::endl << automata << std::endl;
	
	auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();
	std::cout << "Execution time: " << duration << " milliseconds." << std::endl << std::endl;
}
Esempio n. 3
0
TOKEN Scanner(void)
{

   while(feof(in)==0)
   {
      caracter=getc(in);
      c = caracter;

      estado_actual=automata(columna(c),estado_actual);

      switch(estado_actual){
         case 1 : case 3:
            AgregarCaracter(caracter);
         break;
         case 2 :
            ungetc(c,in);
            estado_actual=0;
            //Verificar si es Palabra reservada o un identificador
            //Si es un identificador, verificar que no excedio los 32 caracteres
            //Si es un identificador correcto almacenarlo en la Tabla de Simbolos
            return EsReservada();
         break;
         case 4:
            ungetc(c,in);
            estado_actual=0;
            //Almacenar Secuencia de Digitos en Tabla de Simbolos
            LimpiarBuffer();
            return 5;
         break;
         case 5:
            estado_actual=0;
            return 11;
         break;
         case 6:
            estado_actual=0;
            return 12;
         break;
         case 7:
            estado_actual=0;
            return 6;
         break;
         case 8:
            estado_actual=0;
            return 7;
         break;
         case 9:
            estado_actual=0;
            return 9;
         break;
         case 10:
            estado_actual=0;
            return 8;
         break;
         case 12:
            estado_actual=0;
            return 10;
         break;
         case 14:
            return -4;
         break;
         default:
         break;
      }
   }
   if (estado_actual==13 || feof(in)!=0) return 13;

}
Esempio n. 4
0
void test_epsilon_deleting()
{
	std::cout << "Testing epsilon deleting..." << std::endl << std::endl;

	State zero("0", state_type::NONFINAL);
	State one("1", state_type::NONFINAL);
	State two("2", state_type::FINAL);
	State three("3", state_type::NONFINAL);
	State four("4", state_type::FINAL);
	State five("5", state_type::NONFINAL);

	std::vector<State*> states;

	std::set<State*> zeroStatesEps;
	std::set<State*> oneStatesA;
	std::set<State*> twoStatesEps;
	std::set<State*> twoStatesA;
	std::set<State*> threeStatesEps;
	std::set<State*> fourStates;
	std::set<State*> fiveStatesEps;
	std::set<State*> fiveStatesB;

	states.push_back(&zero);
	states.push_back(&one);
	states.push_back(&two);
	states.push_back(&three);
	states.push_back(&four);
	states.push_back(&five);

	zeroStatesEps.insert(&one);
	zeroStatesEps.insert(&two);
	zeroStatesEps.insert(&three);
	oneStatesA.insert(&four);
	twoStatesEps.insert(&four);
	twoStatesA.insert(&five);
	threeStatesEps.insert(&five);
	fiveStatesEps.insert(&three);
	fiveStatesB.insert(&four);

	std::unordered_map<char , std::set<State*> > zeroTransitions;
	std::unordered_map<char , std::set<State*> > oneTransitions;
	std::unordered_map<char , std::set<State*> > twoTransitions;
	std::unordered_map<char , std::set<State*> > threeTransitions;
	std::unordered_map<char , std::set<State*> > fourTransitions;
	std::unordered_map<char , std::set<State*> > fiveTransitions;

	zeroTransitions[0] = zeroStatesEps;
	oneTransitions['a'] = oneStatesA;
	twoTransitions[0] = twoStatesEps;
	twoTransitions['a'] = twoStatesA;
	threeTransitions[0] = threeStatesEps;
	fiveTransitions[0] = fiveStatesEps;
	fiveTransitions['b'] = fiveStatesB;

	std::unordered_map< State*,  std::unordered_map<char , std::set<State*> > > transitions;

	transitions[&zero] = zeroTransitions;
	transitions[&one] = oneTransitions;
	transitions[&two] = twoTransitions;
	transitions[&three] = threeTransitions;
	transitions[&four] = fourTransitions;
	transitions[&five] = fiveTransitions;

	Automata automata(transitions);
	automata.setInitial(&zero);
	automata.setStates(states);

	std::cout << "Before:" << std::endl << automata << std::endl;

	std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
	
	automata.removeEpsilonTransitions();

	std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();

	std::cout << "After: " << std::endl << automata << std::endl;
	
	auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();
	std::cout << "Execution time: " << duration << " milliseconds." << std::endl << std::endl;
}
Esempio n. 5
0
void test_parsing()
{
	std::cout << "Testing parsing..." << std::endl << std::endl;

	State zero("0", state_type::NONFINAL);
	State one("1", state_type::NONFINAL);
	State two("2", state_type::NONFINAL);
	State three("3", state_type::FINAL);

	std::vector<State*> states;

	std::set<State*> zeroStatesA;
	std::set<State*> zeroStatesB;
	std::set<State*> oneStatesA;
	std::set<State*> twoStatesB;

	states.push_back(&zero);
	states.push_back(&one);
	states.push_back(&two);
	states.push_back(&three);

	zeroStatesA.insert(&zero);
	zeroStatesB.insert(&zero);
	zeroStatesB.insert(&one);
	oneStatesA.insert(&two);
	twoStatesB.insert(&three);

	std::unordered_map<char , std::set<State*> > zeroTransitions;
	std::unordered_map<char , std::set<State*> > oneTransitions;
	std::unordered_map<char , std::set<State*> > twoTransitions;
	std::unordered_map<char , std::set<State*> > threeTransitions;

	zeroTransitions['a'] = zeroStatesA;
	zeroTransitions['b'] = zeroStatesB;
	oneTransitions['a'] = oneStatesA;
	twoTransitions['b'] = twoStatesB;

	std::unordered_map< State*,  std::unordered_map<char , std::set<State*> > > transitions;

	transitions[&zero] = zeroTransitions;
	transitions[&one] = oneTransitions;
	transitions[&two] = twoTransitions;
	transitions[&three] = threeTransitions;

	Automata automata(transitions);
	automata.setInitial(&zero);
	automata.setCurrentState(&zero);
	automata.setStates(states);

	std::cout << "Avant: " << std::endl << automata << std::endl;
	automata.determinise();
	std::cout << "après: " << std::endl << automata << std::endl;
	automata.minimise();
	std::cout << "après après: " << std::endl << automata << std::endl;

	std::set<std::string> words;
	words.insert("bab");
	words.insert("ba");
	words.insert("");
	words.insert("aaaaaabbbab");
	words.insert("bbbb");

	for(auto word : words)
	{
		std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
		std::cout << "\"" << word << "\"";
		std::cout << " accepted ? --> " << automata.isAcceptedWord(word) << std::endl;
		std::cout << "word: ";
		std::cout << word << std::endl;
		std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();

		auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();
		std::cout << "Execution time: " << duration << " milliseconds." << std::endl << std::endl;
	}
}