本文整理汇总了C++中GraphType类的典型用法代码示例。如果您正苦于以下问题:C++ GraphType类的具体用法?C++ GraphType怎么用?C++ GraphType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: map_reduce_vertices
ReductionType map_reduce_vertices(GraphType& g,
MapFunctionType mapfunction,
const vertex_set& vset = GraphType::complete_set()) {
BOOST_CONCEPT_ASSERT((graphlab::Serializable<ReductionType>));
BOOST_CONCEPT_ASSERT((graphlab::OpPlusEq<ReductionType>));
typedef typename GraphType::vertex_type vertex_type;
if(!g.is_finalized()) {
logstream(LOG_FATAL)
<< "\n\tAttempting to run graph.map_reduce_vertices(...) "
<< "\n\tbefore calling graph.finalize()."
<< std::endl;
}
g.dc().barrier();
bool global_result_set = false;
ReductionType global_result = ReductionType();
#ifdef _OPENMP
#pragma omp parallel
#endif
{
bool result_set = false;
ReductionType result = ReductionType();
#ifdef _OPENMP
#pragma omp for
#endif
for (int i = 0; i < (int)g.num_local_vertices(); ++i) {
auto lvertex = g.l_vertex(i);
if (lvertex.owned() && vset.l_contains(lvid_type(i))) {
if (!result_set) {
vertex_type vtx(lvertex);
result = mapfunction(vtx);
result_set = true;
}
else if (result_set){
const vertex_type vtx(lvertex);
const ReductionType tmp = mapfunction(vtx);
result += tmp;
}
}
}
#ifdef _OPENMP
#pragma omp critical
#endif
{
if (result_set) {
if (!global_result_set) {
global_result = result;
global_result_set = true;
}
else {
global_result += result;
}
}
}
}
conditional_addition_wrapper<ReductionType>
wrapper(global_result, global_result_set);
g.dc().all_reduce(wrapper);
return wrapper.value;
} // end of map_reduce_vertices
示例2: breadth_first_search
static void breadth_first_search(const GraphType& graph,
const VertexIndexType& source,
const int& k_steps,
AssociativeContainer& visited_vertices) {
/* CHECK: AssociativeContainer::value_type == VertexIndexType */
std::queue<VertexIndexType> even_epoch_queue;
std::queue<VertexIndexType> odd_epoch_queue;
std::queue<VertexIndexType>& current_queue = even_epoch_queue;
std::queue<VertexIndexType>& next_queue = odd_epoch_queue;
current_queue.push (source);
int step_number = 0;
while (step_number<k_steps) {
while (!current_queue.empty ()) {
const int vertex = current_queue.front ();
current_queue.pop ();
visited_vertices.insert (vertex);
for (int target_index=graph.begin(vertex);
target_index<graph.end(vertex);
++target_index) {
const int target = graph.get_target (target_index);
if (visited_vertices.end()==visited_vertices.find (target)) {
next_queue.push (target);
}
}
}
++step_number;
current_queue = (step_number&0x10)?even_epoch_queue:odd_epoch_queue;
next_queue = (step_number&0x01)?even_epoch_queue:odd_epoch_queue;
}
}
示例3: makeGraph
static void makeGraph(GraphType &graph, double** input, int matrix_size) {
std::vector<SGNode> nodes;
nodes.resize(matrix_size);
for(int i = 0; i<matrix_size; i++){
Node n;
n.id = i;
SGNode node = graph.createNode(n);
graph.addNode(node);
nodes[i] = node;
}
int numEdges = 0;
for(int i = 0; i<matrix_size; i++){
SGNode src = nodes[i];
for(int j = i; j<matrix_size; j++){
if(input[i][j] != 0){
typename GraphType::edge_iterator it = graph.addEdge(src, nodes[j], Galois::MethodFlag::NONE);
graph.getEdgeData(it) = input[i][j];
numEdges++;
}
}
}
//#if BORUVKA_DEBUG
std::cout << "Final num edges " << numEdges << std::endl;
//#endif
}
示例4: main
int main()
{
typedef Graph<int,int,int> GraphType;
GraphType *g = new GraphType(/*estimated # of nodes*/ 2, /*estimated # of edges*/ 1);
g -> add_node();
g -> add_node();
g -> add_tweights( 0, /* capacities */ 1, 5 );
g -> add_tweights( 1, /* capacities */ 2, 6 );
g -> add_edge( 0, 1, /* capacities */ 3, 4 );
int flow = g -> maxflow();
printf("Flow = %d\n", flow);
printf("Minimum cut:\n");
if (g->what_segment(0) == GraphType::SOURCE)
printf("node0 is in the SOURCE set\n");
else
printf("node0 is in the SINK set\n");
if (g->what_segment(1) == GraphType::SOURCE)
printf("node1 is in the SOURCE set\n");
else
printf("node1 is in the SINK set\n");
delete g;
return 0;
}
示例5: create_graph
GraphType* create_graph(std::vector< EdgeType >& edges,
std::vector<int>& curr_edge_cap,
std::vector<int>& curr_lambda_cap,
const std::vector<int>& fg_nodes, const int INFTY,
const int NUM_NODES, const bool fg_cap_inf) {
bool is_fg;
GraphType *g = new GraphType(NUM_NODES, edges.size());
g->add_node(NUM_NODES);
for (unsigned int i = 0; i < NUM_NODES; ++i) {
is_fg = false;
for (unsigned int j = 0; j < fg_nodes.size(); ++j) {
if (i == fg_nodes[j]) {
is_fg = true;
break;
}
}
if (is_fg)
g->add_tweights(i, /* capacities */(fg_cap_inf ? INFTY : curr_lambda_cap[i]), 0);
else
g->add_tweights(i, /* capacities */0, curr_lambda_cap[i]);
}
/* capacity edges */
for (unsigned int i = 0; i < edges.size(); ++i) {
g->add_edge(edges[i].first, edges[i].second, curr_edge_cap[i],
curr_edge_cap[i]);
}
return g;
}
示例6: mexFunction
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// Variable Initializations
int *inp_param;
double *t_links, *n_links;
int i;
if ( (nrhs != 3) || ( mxGetClassID(prhs[0]) != mxINT32_CLASS ) )
mexErrMsgTxt("ERROR1");
inp_param = (int*)mxGetPr(prhs[0]);
t_links = (double*)mxGetPr(prhs[1]);
n_links = (double*)mxGetPr(prhs[2]);
typedef Graph<double,double,double> GraphType; // Declaring the graph ...
GraphType *g = new GraphType( inp_param[1], (2*inp_param[1]) + (2*inp_param[2]) );
g -> add_node(inp_param[1]); // Creating the grid of all nodes put together ...
for(i=0; i<inp_param[1] ; i++)
g -> add_tweights(i, t_links[2*i], t_links[2*i+1] );
for(i=0;i<inp_param[2];i++)
g -> add_edge( n_links[3*i] , n_links[3*i+1] , n_links[3*i+2] , n_links[3*i+2] );
int flow = g -> maxflow();
mexPrintf("Value of flow is %d \n",flow);
// RETURN VARIABLE
plhs[0] = mxCreateDoubleMatrix(inp_param[1], 1, mxREAL);
double* outArray = (double*)mxGetPr(plhs[0]);
for(i=0;i<inp_param[1];i++)
outArray[i] = g->what_segment(i);
delete g;
return;
}
示例7: rand_gen
/**
* A method that samples uniformly from the given graph without replacement.
* This sampling scheme is used as a baseline to measure the performance of
* other sampling schemes --- they have to perform at least as well as this.
*
* \param[in] graph The graph that we are sampling from.
* \param[in] num_samples The number of samples to take.
* \param[in] rand_seed The seed for the random number generator.
* \param[in] sample A vector containing the edges that were sampled.
*/
static void uniform_sample
(const GraphType& graph,
const int& num_samples,
const int& rand_seed,
const bool& symmetrize,
std::vector<bool>& samples) {
/* The range for the random number generator is [0..num_edges) */
const int lower = 0;
const int upper = graph.get_num_edges ();
/* Keep a record of all the edges that have been sampled */
samples.resize (upper);
for (int i=0; i<upper; ++i) samples [i] = false;
/* Generate 'num_samples' random numbers and pick an edge each time */
prng rand_gen (rand_seed);
for (int i=0; i<num_samples; ++i) {
int current_edge_index;
do {
current_edge_index = floor (rand_gen.next (lower, upper));
} while (samples [current_edge_index]);
samples [current_edge_index] = true;
if (symmetrize) {
const int reverse_edge_index =
graph.get_reverse_target_index (current_edge_index);
samples[reverse_edge_index] = true;
}
}
}
示例8: sgl_random_edge
static typename GraphType::EdgeNodeIterator
sgl_random_edge(GraphType &g)
{
size_t n = g.nEdges();
assert(n>0);
size_t id = rand() % n;
return g.findEdge(id);
}
示例9: sgl_random_vertex
static typename GraphType::VertexNodeIterator
sgl_random_vertex(GraphType &g)
{
size_t n = g.nVertices();
assert(n>0);
size_t id = rand() % n;
return g.findVertex(id);
}
示例10: operator
/** Set Fixed Constraint.
* @param[in] g Valid graph.
* @param[in] t Valid time.
* @post The velocity of Point(0,0,0) and Point(1,0,0) are 0.
*/
void operator()(GraphType& g, double t) {
(void) t; // silence compiler warnings
for (GraphType::NodeIterator it = g.node_begin(); it != g.node_end(); ++it) {
Node n = (*it);
if (n.position() == Point(0,0,0) || n.position() == Point(1,0,0)) {
n.value().vel = Point(0,0,0);
}
}
}
示例11: indexList
GraphType* FinleyDomain::createTrilinosGraph(bool reducedOrder) const
{
index_t myNumTargets;
index_t numTargets;
const index_t* target;
const_TrilinosMap_ptr rowMap;
const_TrilinosMap_ptr colMap;
if (reducedOrder) {
myNumTargets = m_nodes->getNumReducedDegreesOfFreedom();
numTargets = m_nodes->getNumReducedDegreesOfFreedomTargets();
target = m_nodes->borrowTargetReducedDegreesOfFreedom();
rowMap = m_nodes->trilinosReducedRowMap;
colMap = m_nodes->trilinosReducedColMap;
} else {
myNumTargets = m_nodes->getNumDegreesOfFreedom();
numTargets = m_nodes->getNumDegreesOfFreedomTargets();
target = m_nodes->borrowTargetDegreesOfFreedom();
rowMap = m_nodes->trilinosRowMap;
colMap = m_nodes->trilinosColMap;
}
boost::scoped_array<IndexList> indexList(new IndexList[numTargets]);
#pragma omp parallel
{
// insert contributions from element matrices into columns in
// index list
IndexList_insertElements(indexList.get(), m_elements, reducedOrder,
target, reducedOrder, target);
IndexList_insertElements(indexList.get(), m_faceElements,
reducedOrder, target, reducedOrder, target);
IndexList_insertElements(indexList.get(), m_contactElements,
reducedOrder, target, reducedOrder, target);
IndexList_insertElements(indexList.get(), m_points, reducedOrder,
target, reducedOrder, target);
}
Teuchos::ArrayRCP<size_t> rowPtr(myNumTargets + 1);
for (size_t i = 0; i < myNumTargets; i++) {
rowPtr[i+1] = rowPtr[i] + indexList[i].count(0, numTargets);
}
Teuchos::ArrayRCP<LO> colInd(rowPtr[myNumTargets]);
#pragma omp parallel for
for (index_t i = 0; i < myNumTargets; i++) {
indexList[i].toArray(&colInd[rowPtr[i]], 0, numTargets, 0);
std::sort(&colInd[rowPtr[i]], &colInd[rowPtr[i+1]]);
}
GraphType* graph = new GraphType(rowMap, colMap, rowPtr, colInd);
Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
params->set("Optimize Storage", true);
graph->fillComplete(rowMap, rowMap, params);
return graph;
}
示例12: sgl_random_graph
static void
sgl_random_graph(GraphType &g, size_t max_vertices, int vertex_time_limit, double edge_to_vertex_ratio)
{
start_deadman(vertex_time_limit);
for (size_t i=0; i<max_vertices && !had_alarm; ++i)
g.insertVertex(0);
for (size_t i=g.nVertices()*edge_to_vertex_ratio; i>0; --i)
g.insertEdge(sgl_random_vertex(g), sgl_random_vertex(g), 0);
}
示例13: yagi_random_graph
static void
yagi_random_graph(GraphType &g, size_t max_vertices, int vertex_time_limit, double edge_to_vertex_ratio)
{
start_deadman(vertex_time_limit);
for (size_t i=0; i<max_vertices && !had_alarm; ++i)
g.add_vertex();
for (size_t i=g.num_vertices()*edge_to_vertex_ratio; i>0; --i)
g.add_edge(yagi_random_vertex(g), yagi_random_vertex(g));
}
示例14: run_GridCut_3D_6C
void run_GridCut_3D_6C(MFI* mfi,unsigned char* out_label,int* out_maxflow,double* time_init,double* time_maxflow,double* time_output)
{
const int w = mfi->width;
const int h = mfi->height;
const int d = mfi->depth;
const type_terminal_cap* cap_source = (type_terminal_cap*)mfi->cap_source;
const type_terminal_cap* cap_sink = (type_terminal_cap*)mfi->cap_sink;
const type_neighbor_cap* cap_neighbor[6] = { (type_neighbor_cap*)(mfi->cap_neighbor[0]),
(type_neighbor_cap*)(mfi->cap_neighbor[1]),
(type_neighbor_cap*)(mfi->cap_neighbor[2]),
(type_neighbor_cap*)(mfi->cap_neighbor[3]),
(type_neighbor_cap*)(mfi->cap_neighbor[4]),
(type_neighbor_cap*)(mfi->cap_neighbor[5]) };
typedef GridGraph_3D_6C<type_terminal_cap,type_neighbor_cap,int> GraphType;
CLOCK_START();
GraphType* graph = new GraphType(w,h,d);
for(int z=0;z<d;z++)
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
const int node = graph->node_id(x,y,z);
graph->set_terminal_cap(node,cap_source[x+y*w+z*(w*h)],cap_sink[x+y*w+z*(w*h)]);
if (x>0 ) graph->set_neighbor_cap(node,-1, 0, 0,cap_neighbor[MFI::ARC_LEE][x+y*w+z*(w*h)]);
if (x<w-1) graph->set_neighbor_cap(node,+1, 0, 0,cap_neighbor[MFI::ARC_GEE][x+y*w+z*(w*h)]);
if (y>0 ) graph->set_neighbor_cap(node, 0,-1, 0,cap_neighbor[MFI::ARC_ELE][x+y*w+z*(w*h)]);
if (y<h-1) graph->set_neighbor_cap(node, 0,+1, 0,cap_neighbor[MFI::ARC_EGE][x+y*w+z*(w*h)]);
if (z>0 ) graph->set_neighbor_cap(node, 0, 0,-1,cap_neighbor[MFI::ARC_EEL][x+y*w+z*(w*h)]);
if (z<d-1) graph->set_neighbor_cap(node, 0, 0,+1,cap_neighbor[MFI::ARC_EEG][x+y*w+z*(w*h)]);
}
CLOCK_STOP(time_init);
CLOCK_START();
graph->compute_maxflow();
CLOCK_STOP(time_maxflow)
CLOCK_START();
*out_maxflow = graph->get_flow();
for(int z=0;z<d;z++)
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
out_label[x+y*w+z*(w*h)] = graph->get_segment(graph->node_id(x,y,z));
}
delete graph;
CLOCK_STOP(time_output);
}
示例15: sgl_time_add_vertex
Totals
sgl_time_add_vertex()
{
GraphType g;
start_deadman(2);
Sawyer::Stopwatch t;
while (!had_alarm && g.nVertices()<MAX_VERTICES)
g.insertVertex(0);
t.stop();
return report("add vertex", sgl_size(g), g.nVertices(), t, "verts/s");
}