inline void writeXGMMLFile( const G &g, const std::string &filename, const VV &vv, const EV &ev ) { using boost::format; std::ofstream file(filename); if(!file.good()) { throw GraphIOException(std::string("Could not open file: ") + filename); } file << "<?xml version=\"1.0\"?>\n"; if(g[boost::graph_bundle].label.size() > 0) { file << "<graph label=\"" << g[boost::graph_bundle].label << "\" "; } else { file << "<graph label=\"" << basename(filename) << "\" "; } file << "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" "; file << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" "; file << "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "; file << "xmlns=\"http://www.cs.rpi.edu/XGMML\" "; file << "directed=\"0\">\n"; for(size_t i = 0; i < num_vertices(g); ++i) { file << format("\t<node id=\"%d\" label=\"%s\">\n") % (i+1) % g[i].label; for(size_t a = 0; a < vv.count(); ++a) { file << format("\t\t<att name=\"%s\" type=\"%s\" value=\"%s\"/>\n") % vv.name(a) % vv.type(a) % vv.value_str(g[i], a); } file << "\t</node>\n"; } for(size_t i = 0; i < num_vertices(g); ++i) { for(auto it = out_edges(i, g); it.first != it.second; ++it.first) { size_t j = target(*it.first, g); if(i <= j) { file << format("\t<edge source=\"%d\" target=\"%d\" label=\"%s\">\n") % (i+1) % (j+1) % g[*it.first].label; for(size_t a = 0; a < ev.count(); ++a) { file << format("\t\t<att name=\"%s\" type=\"%s\" value=\"%s\" />\n") % ev.name(a) % ev.type(a) % ev.value_str(g[*it.first], a); } file << "\t</edge>\n"; } } } file << "</graph>"; file.close(); }
// Minimum Spanning Tree void kruskal_mst(int n, i64 &ans) { sort(edges.begin(), edges.end()); Set uf(n); int nedges = 0; ans = 0; EV mst; cFor (EV, e, edges) { if (uf.find(e->u) == uf.find(e->v)) continue; mst.push_back(*e); uf.merge(e->u, e->v); ans += e->w; if (++nedges == n - 1) break; } if (nedges < n - 1) ans = -1; else edges = mst; }
int main() { Obs o1 = Obs(); Obs o2 = Obs(); Obs o3 = Obs(); EV e = EV(); uint32_t eventIDs[2] = { 0, 1 }; e.RegisterObserver(eventIDs[0], &o1); e.RegisterObserver(eventIDs[1], &o2); e.RegisterObserver(eventIDs[0], &o3); e.NotifyObservers(eventIDs[0]); e.NotifyObservers(eventIDs[1]); getchar(); }
static void flux_jacobian_eigen_values(const MODEL::Properties& p, const GV& direction, EV& Dv, OP& op ) { Dv = p.v * direction; Dv = Dv.unaryExpr( op ); }
inline void writeTabFile( const G &g, const std::string &filename, const VV &vv, const EV &ev ) { std::ofstream file(filename); if(!file.good()) { throw GraphIOException(std::string("Could not open file: ") + filename); } file << "INTERACTOR_A\tINTERACTOR_B\tlabel"; for(size_t a = 0; a < ev.count(); ++a) { file << "\t" << ev.name(a); } file << "\n"; for(size_t i = 0; i < num_vertices(g); ++i) { for(auto it = out_edges(i, g); it.first != it.second; ++it.first) { size_t j = target(*it.first, g); if(i <= j) { file << g[i].label << "\t" << g[j].label; if(g[*it.first].label.length() > 0) { file << "\t" << g[*it.first].label; } else { file << "\tNA"; } for(size_t a = 0; a < ev.count(); ++a) { file << "\t" << ev.value_str(g[*it.first], a); } file << "\n"; } } } file.close(); }
void add(int u, int v, w_t w) { edges.push_back(Edge(u, v, w)); }
void Selector_sel::select(EV & ready, int timeout) { SOCKET max = -1; fd_set rfds, wfds; FD_ZERO(&rfds); FD_ZERO(&wfds); SelMap::iterator it; for (it = m_selects.begin(); it != m_selects.end(); ++it) { if (!it->second) continue; assert(it->first->socket().isValid()); SOCKET s = it->first->socket().getsocket(); // XXX check FD_SETSIZE if (it->second & SEL_READ) FD_SET(s, &rfds); if (it->second & SEL_WRITE) FD_SET(s, &wfds); if (max < s) max = s; } struct timeval tvo; if (timeout >= 0) { tvo.tv_sec = timeout / 1000; tvo.tv_usec = (timeout % 1000) * 1000; } int nready = ::select(int(max) + 1, &rfds, &wfds, NULL, (timeout < 0 ? NULL: &tvo)); if (nready < 0) { if (errno == EINTR) return; throw exception_errno(socket_error::getLastError(), "select"); } for (it = m_selects.begin(); nready > 0 && it != m_selects.end(); ++it) { SOCKET s = it->first->socket().getsocket(); bool b=false; if (FD_ISSET(s, &rfds)) { b=true; ready.push_back(Event(it->first, SEL_READ)); } if (FD_ISSET(s, &wfds)) { b=true; ready.push_back(Event(it->first, SEL_WRITE)); } if (b) -- nready; } }