Exemplo n.º 1
0
void TimeSliceObservableCDT::process(const std::vector<Vertex*>& state) {
    // define a timelike direction that is the future
    Vertex* cur = state[0];
    Vertex* future = cur->getNeighbouringVertex();
    Triangle *f, *p;
    Vertex::getAdjacentTriangles(cur, future, &f, &p);
    if (!f->isTimelike(cur, future)) future = f->getThirdVertex(cur, future);

    for (unsigned int t = 0; t < T; t++) {
        unsigned int count = 0;

        // find spacelike loop at cur
        Vertex::getAdjacentTriangles(cur, future, &f, &p);
        VertSet n = cur->getSectorVertices(f, future, false);
        BOOST_ASSERT(n.size() == 1); // CDT constraint

        Vertex* prev = *n.begin();
        Vertex* lc = cur;
        do {
            VertSet sec = lc->getOtherSectorVertices(prev);
            BOOST_ASSERT(sec.size() == 1); // CDT constraint
            prev = lc;
            lc = *sec.begin();
            count++;
        } while (lc != cur);

        Vertex* newfut = *future->getOtherSectorVertices(cur).begin();
        cur = future;
        future = newfut;

        volumeProfile[t] = count;
    }
}
Exemplo n.º 2
0
int Network::Dinic()
{
    int maxflow = 0;
    int u,v,e,ee,f;
    IntArray q;
    _E.resize(_E.size()+1);
    _E.back().v = _s;
    while (true)
    {
        for (u = 0;u < _V.size();u++)
            _V[u].l = -1;
        _V[_s].l = f = 0;
        _V[_s].o = _V[_s].e;
        q.clear();
        q.push_back(_s);
        while (f < (int)q.size())
        {
            u = q[f++];
            for (e = _V[u].e;e != -1;e = _E[e].n)
            {
                v = _E[e].v;
                if (_V[v].l == -1 && _E[e].c > 0)
                {
                    _V[v].o = _V[v].e;
                    _V[v].l = _V[u].l+1;
                    q.push_back(v);
                }
            }
        }
        if (_V[_t].l == -1) break;
        q.clear();
        q.push_back(_E.size()-1);
        while (!q.empty())
        {
            u = _E[q.back()].v;
            if (u == _t)
            {
                for (f = INT_MAX,e = 1;e < (int)q.size();e++)
                    if (_E[q[e]].c < f)
                        f = _E[q[e]].c,u = e;
                for (e = 1;e < q.size();e++)
                {
                    _E[q[e]].c -= f;
                    _E[q[e]^1].c += f;
                }
                maxflow += f;
                q.resize(u);
            }
            else
            {
                for (e = _V[u].o;e != -1;e = _E[e].n)
                {
                    if (_V[_E[e].v].l < 0 || _E[e].c < 1)
                        continue;
                    if (_V[_E[e].v].l == _V[u].l+1)
                        break;
                }
                if ((_V[u].o = e) != -1)
                    q.push_back(e);
                else
                {
                    q.pop_back();
                    _V[u].l = -1;
                }
            }
        }
    }
    return maxflow;
}