本文整理汇总了C++中Cycle类的典型用法代码示例。如果您正苦于以下问题:C++ Cycle类的具体用法?C++ Cycle怎么用?C++ Cycle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cycle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: greedIt
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;
}
示例2: Cycle
// 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;
}
示例3: displayCycle
void displayCycle(const Matrix &mat, Cycle cycle)
{
Cycle::const_iterator it;
for (it = cycle.begin(); it != cycle.end(); ++it)
cout << *it + 1 << endl;
}
示例4: strchr
ProgramComponent* CommandParser::ParseCycle(char* pBuffer) {
char countBuf[5];
//find first step
char* pStep = strchr(pBuffer, '[');
//get cycle count
int countLen = pStep - pBuffer;
strncpy(countBuf, pBuffer, countLen);
countBuf[countLen] = '\0';
int cycCount = atoi(countBuf);
Cycle* pCycle = gpThermocycler->GetCyclePool().AllocateComponent();
pCycle->SetNumCycles(cycCount);
//add steps
while (pStep != NULL) {
*pStep++ = '\0';
char* pStepEnd = strchr(pStep, ']');
*pStepEnd++ = '\0';
Step* pNewStep = ParseStep(pStep);
pCycle->AddComponent(pNewStep);
pStep = strchr(pStepEnd, '[');
}
return pCycle;
}
示例5: Cycle
Cycle * XeoTerm::defaultCycle(QString _context, QDateTime _time){
if(contain(_context)){
VariableContextSpec * pcs = (*this->contextCollection)[_context];
if(pcs->get_defCycle()!=NULL){
Cycle * v = new Cycle();
v->set_context(_context);
for(std::list<std::pair<QDateTime, QString> >::iterator it = pcs->get_defCycle()->get_vals()->begin();it!=pcs->get_defCycle()->get_vals()->end();++it)
{
std::pair<DynamicValueBase*,QDateTime> p =std::make_pair(new DynamicValue(it->first,it->second),_time);
v->add_cycleValue(p);
}
if(pcs->get_unitSet()->get_defUnit()!=NULL)
{
v->set_unit(pcs->get_unitSet()->get_defUnit()->get_symbol());
}
v->set_timepoint(_time);
return v;
}
else
return NULL;
}
else{
return NULL;
}
}
示例6: _getBorder
// Extract component border
void MoleculeLayoutGraph::_getBorder (Cycle &border) const
{
QS_DEF(Array<int>, vertices);
QS_DEF(Array<int>, edges);
int i, n = 0;
for (i = edgeBegin(); i < edgeEnd(); i = edgeNext(i))
if (_layout_edges[i].type == ELEMENT_BOUNDARY)
n++;
if (n == 0)
return;
vertices.clear();
edges.clear();
for (i = edgeBegin(); i < edgeEnd(); i = edgeNext(i))
if (_layout_edges[i].type == ELEMENT_BOUNDARY)
break;
Edge edge = getEdge(i);
vertices.push(edge.beg);
edges.push(i);
while (edge.end != vertices[0])
{
const Vertex &vert = getVertex(edge.end);
bool found = false;
for (int i = vert.neiBegin(); !found && i < vert.neiEnd(); i = vert.neiNext(i))
{
int nei_v = vert.neiVertex(i);
int nei_e = vert.neiEdge(i);
if (getEdgeType(nei_e) == ELEMENT_BOUNDARY && nei_v != edge.beg)
{
edge.beg = edge.end;
edge.end = nei_v;
vertices.push(edge.beg);
edges.push(nei_e);
found = true;
}
}
if (!found || vertices.size() > n)
throw Error("corrupted border");
}
border.copy(vertices, edges);
border.canonize();
}
示例7: countCycle
int countCycle(const Matrix &mat, Cycle cycle)
{
Cycle::const_iterator it;
int cycle_mat = 0;
for (it = cycle.begin(); it != cycle.end(); ++it)
{
if (it != cycle.begin())
cycle_mat += mat[*it][*prev(it)];
}
return cycle_mat;
}
示例8: strtok
Cycle* CommandParser::ParseProgram(char* pBuffer) {
Cycle* pProgram = gpThermocycler->GetCyclePool().AllocateComponent();
pProgram->SetNumCycles(1);
char* pCycBuf = strtok(pBuffer, "()");
while (pCycBuf != NULL) {
pProgram->AddComponent(ParseCycle(pCycBuf));
pCycBuf = strtok(NULL, "()");
}
return pProgram;
}
示例9: _get_square
double MoleculeLayoutGraphSmart::_get_square() {
Cycle cycle;
_getBorder(cycle);
int len = cycle.vertexCount();
double sq = 0;
for (int i = 1; i < len - 1; i++)
sq += Vec2f::cross(getPos(cycle.getVertex(i)) - getPos(cycle.getVertex(0)), getPos(cycle.getVertex(i + 1)) - getPos(cycle.getVertex(0)));
return abs(sq / 2);
}
示例10: _assignFirstCycle
void MoleculeLayoutGraph::_assignFirstCycle (const Cycle &cycle)
{
// TODO: Start drawing from vertex with maximum code and continue to the right with one of two which has maximum code
int i, n;
float phi;
n = cycle.vertexCount();
for (i = 0; i < n; i++)
{
_layout_vertices[cycle.getVertex(i)].type = ELEMENT_BOUNDARY;
_layout_edges[cycle.getEdge(i)].type = ELEMENT_BOUNDARY;
}
_first_vertex_idx = cycle.getVertex(0);
_layout_vertices[cycle.getVertex(0)].pos.set(0.f, 0.f);
_layout_vertices[cycle.getVertex(1)].pos.set(1.f, 0.f);
phi = (float)M_PI * (n - 2) / n;
for (i = 1; i < n - 1; i++)
{
const Vec2f &v1 = _layout_vertices[cycle.getVertex(i - 1)].pos;
const Vec2f &v2 = _layout_vertices[cycle.getVertex(i)].pos;
_layout_vertices[cycle.getVertex(i + 1)].pos.rotateAroundSegmentEnd(v1, v2, phi);
}
}
示例11: process
void process(NxF32 dtime)
{
_controlfp(_PC_64,_MCW_PC);
gJobSwarmContext->processSwarmJobs();
Cycle c;
c.Begin();
while ( !mFinished )
{
if ( mPreview )
{
mPreview = fc_process(mPreviewFractal,dtime);
if ( mPreview == false && mPreviewOnly )
{
mFinished = true;
NxU32 wid,hit;
terrainComplete(mPreviewTerrain, fc_getData(mPreviewFractal,wid,hit) );
NxF32 rot = getRotation(mPreviewTerrain);
setRotation(mTerrain,rot);
}
}
else
{
if ( mTexture && mFractal && !mPreviewOnly )
{
bool morework = fc_process(mFractal,dtime);
if ( !morework )
{
NxU32 wid,hit;
terrainComplete(mTerrain, fc_getData(mFractal,wid,hit) );
NxF32 rot = getRotation(mPreviewTerrain);
setRotation(mTerrain,rot);
mFinished = true;
NxF32 stopTime = CLOCK::getSystemTime();
NxF32 diff = stopTime-mStartTime;
gLog->Display("Fractal took: %0.2f seconds to process.\r\n", diff );
}
}
}
NxU64 cycles = c.End();
if ( cycles > gMaxClockCycles )
break;
}
}
示例12: graph
Grapher::CycleList Grapher::cycles() const
{
// vertex indices
QList<Vertex> indices = m_vertices.keys();
QTime swatch;
swatch.start();
int numEdges = 0;
// construct the graph using vertex indices as vertex identifiers
//
math::Graph graph(m_vertices.size());
for (VertexMap::const_iterator it = m_vertices.begin(); it != m_vertices.end(); ++it)
{
Vertex const & v1 = it.key();
AdjacencyList const & adjs = it.value();
for (AdjacencyList::const_iterator jt = adjs.begin(); jt != adjs.end(); ++jt)
{
Vertex const & v2 = jt->v;
// vertex identifiers
//
int gv1 = indices.indexOf(v1) + 1;
int gv2 = indices.indexOf(v2) + 1;
graph.connect(gv1,gv2);
++numEdges;
}
}
numEdges /= 2; // undirected graph
qDebug() << "graph contains" << m_vertices.size() << "vertices and" << numEdges << "edges";
// obtain the graph's MCB (this could take a while)
QList<math::Graph::VertexList> mcb = graph.minimumCycleBasis(CompareCycles(indices));
// construct cycle list from the graph's MCB
//
CycleList result;
foreach (math::Graph::VertexList gcycle, mcb)
{
Cycle cycle;
foreach (math::Graph::Vertex gv, gcycle)
{
cycle.append(indices[gv-1]);
}
示例13: addCycle
void KeyFace::addCycle(const Cycle & cycle)
{
cycles_ << cycle;
foreach(KeyCell * cell, cycle.cells())
addMeToSpatialStarOf_(cell);
geometryChanged_();
}
示例14: _get_square
float MoleculeLayoutGraphSmart::_get_square() {
Cycle cycle;
_getBorder(cycle);
int len = cycle.vertexCount();
float sq = 0;
for (int i = 1; i < len - 1; i++)
sq += Vec2f::cross(getPos(cycle.getVertex(i)) - getPos(cycle.getVertex(0)), getPos(cycle.getVertex(i + 1)) - getPos(cycle.getVertex(0)));
//printf("sq = %.20f\n", sq);
return fabs(sq / 2);
}
示例15: boundary
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;
}