Exemplo n.º 1
0
int main()
{
	ptrGraph G;
	Indegree inDegree[MAXVEX];
	int tmp;

	G = InitializeGraph(7);
	AddVertex(1, 0, G);
	AddVertex(2, 1, G);
	AddVertex(3, 2, G);
	AddVertex(4, 3, G);
	AddVertex(5, 4, G);
	AddVertex(6, 5, G);
	AddVertex(7, 6, G);
	
	AddEdge(1, 2, G);
	AddEdge(1, 3, G);
	AddEdge(1, 4, G);

	AddEdge(2, 4, G);
	AddEdge(2, 5, G);
	AddEdge(3, 6, G);

	AddEdge(4, 7, G);
	AddEdge(4, 3, G);
	AddEdge(4, 6, G);

	AddEdge(5, 4, G);
	AddEdge(5, 7, G);
	AddEdge(7, 6, G);

	GetIndegree(inDegree, G->numVertexes, G);
	//tmp = FindNewVertexOfIndegreeZero(inDegree, G->numVertexes);
	TopSort(inDegree, G->numVertexes, G);
}
Exemplo n.º 2
0
int main (int argc,  const char* argv[] ) {
  ucam::util::initLogger ( argc, argv );
  FORCELINFO ( argv[0] << " starts!" );
  ucam::util::RegistryPO rg ( argc, argv );
  FORCELINFO ( rg.dump ( "CONFIG parameters:\n=====================",
                         "=====================" ) )  ;
  ucam::util::PatternAddress<unsigned> pi (rg.get<std::string>
      (HifstConstants::kInput) );
  ucam::util::PatternAddress<unsigned> po (rg.get<std::string>
      (HifstConstants::kOutput) );
  for ( ucam::util::IntRangePtr ir (ucam::util::IntRangeFactory ( rg,
                                    HifstConstants::kRangeOne ) );
        !ir->done();
        ir->next() ) {
    fst::VectorFst<fst::StdArc> *mfst = fst::VectorFstRead<fst::StdArc> (pi (
                                          ir->get() ) );
    if (!mfst) return 1;
    TopSort (mfst);
    boost::multiprecision::uint128_t j =
      countstrings<fst::StdArc, boost::multiprecision::uint128_t> (*mfst);
    std::stringstream ss;
    ss << j;
    ucam::util::oszfstream o (po (ir->get() ), true);
    o << ss.str()  << std::endl;
    LINFO ( pi (ir->get() ) << ":" << ss.str() ) ;
    o.close();
    delete mfst;
  }
  FORCELINFO ( argv[0] << " ends!" );
}
Exemplo n.º 3
0
void run(ucam::util::RegistryPO const &rg) {

  ucam::util::PatternAddress<unsigned> pi (rg.get<std::string>
      (HifstConstants::kInput) );
  ucam::util::PatternAddress<unsigned> po (rg.get<std::string>
      (HifstConstants::kOutput) );
  for ( ucam::util::IntRangePtr ir (ucam::util::IntRangeFactory ( rg,
                                    HifstConstants::kRangeOne ) );
        !ir->done();
        ir->next() ) {
    fst::VectorFst<Arc> *mfst = fst::VectorFstRead<Arc> (pi (
                                          ir->get() ) );
    if (!mfst) {
      LERROR("Could not read file:" << ir->get());
      exit(EXIT_FAILURE);
    }
    TopSort (mfst);
    boost::multiprecision::uint128_t j =
      countstrings<Arc, boost::multiprecision::uint128_t> (*mfst);
    std::stringstream ss;
    ss << j;
    ucam::util::oszfstream o (po (ir->get() ), true);
    o << ss.str()  << std::endl;
    LINFO ( pi (ir->get() ) << ":" << ss.str() ) ;
    o.close();
    delete mfst;
  }
}
Exemplo n.º 4
0
void
M2MFstAligner::write_lattice(string lattice)
{
    //Write out the entire training set in lattice format
    //Perform the union first.  This output can then
    // be plugged directly in to a counter to obtain expected
    // alignment counts for the EM-trained corpus.  Yields
    // far higher-quality joint n-gram models, which are also
    // more robust for smaller training corpora.
    //Make sure you call this BEFORE any call to
    // write_all_alignments
    // as the latter function will override some of the weights

    //Chaining the standard Union operation, including using a
    // rational FST still performs very poorly in the log semiring.
    //Presumably it's running push or something at each step.  It
    // should be fine to do that just once at the end.
    //Rolling our own union turns out to be MUCH faster.
    VectorFst<LogArc> ufst;
    ufst.AddState();
    ufst.SetStart(0);
    int total_states = 0;
    for (int i = 0; i < fsas.size(); i++) {
        TopSort(&fsas[i]);
        for (StateIterator<VectorFst<LogArc> > siter(fsas[i]);
                !siter.Done(); siter.Next()) {
            LogArc::StateId q = siter.Value();
            LogArc::StateId r;
            if (q == 0)
                r = 0;
            else
                r = ufst.AddState();

            for (ArcIterator <VectorFst<LogArc> > aiter(fsas[i], q);
                    !aiter.Done(); aiter.Next()) {
                const LogArc & arc = aiter.Value();
                ufst.AddArc(r,
                            LogArc(arc.ilabel, arc.ilabel, arc.weight,
                                   arc.nextstate + total_states));
            }
            if (fsas[i].Final(q) != LogWeight::Zero())
                ufst.SetFinal(r, LogWeight::One());
        }
        total_states += fsas[i].NumStates() - 1;
    }
    //Normalize weights
    Push(&ufst, REWEIGHT_TO_INITIAL);
    //Write the resulting lattice to disk
    ufst.Write(lattice);
    //Write the syms table too.
    isyms->WriteText("lattice.syms");
    return;
}
int main()
{
    int i;
    Vertex TopOrder[MaxVertexNum];
    LGraph G = ReadG();

    if ( TopSort(G, TopOrder)==true )
        for ( i=0; i<G->Nv; i++ )
            printf("%d ", TopOrder[i]);
    else
        printf("ERROR");
    printf("\n");

    return 0;
}
Exemplo n.º 6
0
TupleArcFst* TuneSet::LoadLattice (const Sid s) const {
  boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
  in.push (boost::iostreams::gzip_decompressor() );
  in.push (boost::iostreams::file_source (ExpandPath (m_pattern, s) ) );
  std::istream is (&in);
  TupleArcFst32* fst32 = TupleArcFst32::Read (is, fst::FstReadOptions() );
  TopSort (fst32);
  if (!fst32) {
    cerr << "ERROR: unable to load vector lattice: " << ExpandPath (m_pattern,
         s) << '\n';
    exit (1);
  }
  if (fst32->Properties (fst::kNotTopSorted, true) ) {
    cerr << "ERROR: Input lattices are not topologically sorted: " << '\n';
    exit (1);
  }
  TupleArcFst* fst = new TupleArcFst;
  fst::Expand m;
  fst::Map (*fst32, fst, fst::ExpandMapper (m) );
  delete fst32;
  return fst;
}
Exemplo n.º 7
0
int Schedule(const ReadCircuit &readCircuit, int64_t no_core, int64_t **core) {

  const vector<ReadGate>& G = readCircuit.gate_list;
  int64_t no_task;

  int64_t input_size = readCircuit.g_init_size + readCircuit.e_init_size
      + readCircuit.g_input_size + readCircuit.e_input_size;

  int64_t no_of_input_dff = input_size + readCircuit.dff_size;
  no_task = readCircuit.gate_size;

  int64_t *index;
  index = new int64_t[no_task];
  TopSort(G, no_task, index);

  // start of scheduling
  int64_t *p0, *p1, *core_busy, *core_index;

  p0 = new int64_t[no_task];
  memset(p0, -1, no_task * sizeof(int64_t));
  p1 = new int64_t[no_task];
  memset(p1, -1, no_task * sizeof(int64_t));

  core_index = new int64_t[no_core];
  memset(core_index, 0, no_core * sizeof(int64_t));
  core_busy = new int64_t[no_core];
  memset(core_busy, 0, no_core * sizeof(int64_t));

  int64_t scheduled = 0;
  while (scheduled < no_task) {
    for (int64_t i = 0; i < no_task; i++) {
      if (p0[index[i]] == ((int64_t)-1))  // not assigned yet
          {
        if (((G[index[i]].input[0] - no_of_input_dff < 0)
            || (p0[G[index[i]].input[0] - no_of_input_dff] != int64_t(-1)))) {
          if ((G[index[i]].input[1] - no_of_input_dff < 0)
              || (p0[G[index[i]].input[1] - no_of_input_dff] != int64_t(-1)))  //ready
              {
            p1[index[i]] = GetMinIndex(core_busy, no_core);
            core[p1[index[i]]][core_index[p1[index[i]]]] = index[i];
            core_index[p1[index[i]]]++;
            core_busy[p1[index[i]]] = core_busy[p1[index[i]]] + 1;
            scheduled++;
          }
        }
      }
    }

    for (int64_t i = 0; i < no_task; i++) {
      p0[i] = p1[i];
    }
  }

  delete[] index;
  delete[] p0;
  delete[] p1;
  delete[] core_index;
  delete[] core_busy;

  return SUCCESS;
}