コード例 #1
0
// takes a dfs stack and a transaction that is visited twice, and returns the corresponding cycle
// last access in the dfs stack belongs to tx
// the first and last access in the cycle belong to tx
Cycle* AspEventHandler::extract_cycle(DFSStack& stack, Transaction* tx) {
	num_cycles_++; // all cycles

	// if we have seen another cycle with tx as the revisited transaction, skip reporting this cycle
	if(txset_in_cycle.find(tx) != txset_in_cycle.end()) {
		return NULL;
	}
	// record this transaction, so we do not report cycles with the same revisited transaction
	txset_in_cycle.insert(tx);

	//----------------------------
	Cycle* cycle = new Cycle();
	num_unique_cycles_++; // unique cycles

	DFSStack::iterator itr = stack.begin();
	for(; itr < stack.end(); ++itr) {
		DFSStackElement current_elt = (*itr);
		if(current_elt.tx_ == tx) {
			break;
		}
	}

	for(; itr < stack.end(); ++itr) {
		DFSStackElement current_elt = (*itr);
		Edge edge = *(current_elt.begin_);
		cycle->push_back(edge.first);
		cycle->push_back(edge.second);
	}

	assert(cycle->front()->tx() == tx);
	assert(cycle->back()->tx() == tx);

	return cycle;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Kyslik/ads-assignment-2
Cycle greedIt(const Matrix &mat)
{
    size_t n = mat.size();
    Cycle cycle;
    vector<bool> visited(n, false);

    visited[0] = true;
    int i = 0;

    while (cycle.size() != n)
    {
        int best_j = 0;
        int best_val = INT32_MAX;
        for (int j = 0; j < n; j++) {
            if (visited[j] || best_val < mat[i][j]) continue;
            best_j = j;
            best_val = mat[i][j];
        }
        cycle.push_back(best_j);
        visited[best_j] = true;
        i = best_j;
    }

    cycle.push_front(0);
    return cycle;
}
コード例 #3
0
ファイル: simplex.hpp プロジェクト: veldanie/Dionysus-python3
typename SimplexWithVertices<V>::Cycle	
SimplexWithVertices<V>::
boundary() const
{
	Cycle bdry;
	if (dimension() == 0)	return bdry;

	for (typename VertexContainer::const_iterator cur = vertices_.begin(); cur != vertices_.end(); ++cur)
	{
		bdry.push_back(*this);
		Self& s = bdry.back();
		s.vertices_.erase(*cur);
	}

	return bdry;
}
コード例 #4
0
ファイル: permutation.hpp プロジェクト: Mizuchi/SBL
 std::vector< value_type >
 cycle_notation() const {
     typedef value_type Cycle;
     const value_type &p = oneLineNotation;
     const size_t n = p.size();
     std::vector<bool> v(n, false);
     std::vector<Cycle> ret;
     for (size_t i = 0; i < n; ++i)
         if (v[i] == false) {
             Cycle cycle;
             size_t j = i;
             do {
                 cycle.push_back(j);
                 v[j] = true;
                 j = p[j];
             } while (j != i);
             ret.push_back(cycle);
         }
     return ret;
 }
コード例 #5
0
ファイル: static-persistence.hpp プロジェクト: ramja/TDA-1
void
StaticPersistence<D, CT, OT, E, Cmp>::
initialize(const Filtration& filtration)
{ 
    order_.assign(filtration.size(), OrderElement());
    rLog(rlPersistence, "Initializing persistence");

    OffsetMap<typename Filtration::Index, iterator>                         om(filtration.begin(), begin());
    for (typename Filtration::Index cur = filtration.begin(); cur != filtration.end(); ++cur)
    {
        Cycle z;   
        BOOST_FOREACH(const typename Filtration::Simplex& s, std::make_pair(cur->boundary_begin(), cur->boundary_end()))
            z.push_back(index(om[filtration.find(s)]));
        z.sort(ocmp_); 

        iterator ocur = om[cur];
        swap_cycle(ocur, z);
        set_pair(ocur,   ocur);
    }
}