本文整理汇总了C++中AdjList::end方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjList::end方法的具体用法?C++ AdjList::end怎么用?C++ AdjList::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjList
的用法示例。
在下文中一共展示了AdjList::end方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dijkstra
void dijkstra(AdjList &G, int start)
{
VertexList V;
list<int> S; // Discovered shortest paths
list<int> Q; // Pool of unknown vertices
V[start] = Vertex(0, 0, 1);
S.push_back(start);
for(AdjList::iterator i = G.begin(); i != G.end(); ++i)
if (i->first != start)
{
V[i->first] = Vertex(INT_MAX, 0, 0);
Q.push_back(i->first);
}
cout << "Shortest path discovered " << start << endl;
while (!Q.empty())
{
int u = extract_min(G, V, S);
cout << "Shortest path discovered " << u << endl;
V[u].known = 1;
S.push_back(u);
Q.remove(u);
}
print_out(V);
}
示例2: print_AdjList
void print_AdjList(AdjList &adj_list) {
for(AdjList::iterator it = adj_list.begin(); it != adj_list.end(); ++it) {
vector<int> exist_list = it->second;
cout << " " << it->first << " -> ";
for(int i = 0; i < exist_list.size(); i++) {
cout << " " << exist_list[i] << ",";
}
cout << endl;
}
}
示例3: main
int main(int argc, char* argv[])
{
ifstream in;
in.open(argv[1]);
boost::regex re_start("^\\s*s\\s+(\\d+)\\s*$", boost::regex::perl);
boost::regex re_vertex("^\\s*v\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$", boost::regex::perl);
boost::cmatch matches;
AdjList G;
int start;
string str;
getline(in, str);
while ( in )
{
if (boost::regex_match(str.c_str(), matches, re_start))
start = boost::lexical_cast<int>(matches[1]);
else if (boost::regex_match(str.c_str(), matches, re_vertex))
{
int vertex = boost::lexical_cast<int>(matches[1]);
int node = boost::lexical_cast<int>(matches[2]);
int weight = boost::lexical_cast<int>(matches[3]);
// if node doesn't exist, create a linked list and attach the next item
if (G.find(vertex) == G.end()) // key doesn't exist
G[vertex] = new list<AdjNode>;
// if it does exist just add the next item and distance to the appropriate node
G[vertex]->push_back(AdjNode(node, weight));
}
getline(in, str);
}
in.close();
dijkstra(G, start);
cout << "Loops " << loop << endl;
for (AdjList::iterator i = G.begin(); i != G.end() ; ++i)
delete i->second;
G.clear();
return 0;
}
示例4: get_DAG
int get_DAG(AdjList &adj_list, TaskDAG &dag, string clientid) {
InDegree indegree;
for(AdjList::iterator it = adj_list.begin(); it != adj_list.end(); ++it) {
vector<int> exist_list = it->second;
int source_vertex = it->first;
if(indegree.find(source_vertex) == indegree.end()) {
indegree[source_vertex] = 0;
}
stringstream adj_ss;
for(int i = 0; i < exist_list.size(); i++) {
int dest_vertex = exist_list[i];
// add each vertex to string
adj_ss << exist_list[i] << clientid << "\'";
// update indegree count of each vertex in adjacency list
if(indegree.find(dest_vertex) == indegree.end()) {
indegree[dest_vertex] = 1;
}
else {
indegree[dest_vertex] = indegree[dest_vertex] + 1;
}
if(dag.find(dest_vertex) != dag.end()) {
TaskDAG_Value &value = dag[dest_vertex];
value.first = indegree[dest_vertex];
}
}
adj_ss << "\"";
string adjliststring(adj_ss.str()); // list of vertices delimited by \' with a final \"
// store info into DAG
TaskDAG_Value value(indegree[source_vertex], adjliststring);
dag[source_vertex] = value;
}
return indegree.size();
}
示例5: get_adjlist
void get_adjlist(int num_tasks, AdjList &adj_list, int DAG_choice) {
#define MAX_CHILDREN 100
if(DAG_choice == 0) { // bag of tasks
for (int i = 0; i < num_tasks; i++) { // New nodes of 'higher' rank than all nodes generated till now
// Edges from old nodes ('nodes') to new ones ('new_nodes')
vector<int> new_list;
adj_list.insert(make_pair(i, new_list));
}
}
else if(DAG_choice == 1) { // random DAG
#define MIN_PER_RANK 1 // Nodes/Rank: How 'fat' the DAG should be
#define MAX_PER_RANK 5
#define MIN_RANKS 3 // Ranks: How 'tall' the DAG should be
#define MAX_RANKS 5
#define PERCENT 30 // Chance of having an Edge
srand (time (NULL));
int height = floor(sqrt(num_tasks)); //height = MIN_RANKS + (rand () % (MAX_RANKS - MIN_RANKS + 1));
int new_nodes = ceil(sqrt(num_tasks)); //new_nodes = MIN_PER_RANK + (rand () % (MAX_PER_RANK - MIN_PER_RANK + 1));
int nodes = 0;
for (int i = 0; i < height; i++) { // New nodes of 'higher' rank than all nodes generated till now
// Edges from old nodes ('nodes') to new ones ('new_nodes')
for (int j = 0; j < nodes; j++) {
for (int k = 0; k < new_nodes; k++) {
if ( (rand () % 100) < PERCENT) {
if(adj_list.find(j) == adj_list.end()) {
vector<int> new_list;
new_list.push_back(k + nodes);
adj_list.insert(make_pair(j, new_list));
}
else {
vector<int> &exist_list = adj_list[j];
if(exist_list.size() < MAX_CHILDREN)
exist_list.push_back(k + nodes);
}
if(adj_list.find(k + nodes) == adj_list.end()) {
adj_list.insert(make_pair(k + nodes, vector<int>()));
}
}
}
}
nodes += new_nodes; // Accumulate into old node set
}
}
else if(DAG_choice == 2) { // pipeline DAG
int nodes = 0;
int num_pipeline = floor(sqrt(num_tasks));
int pipeline_height = ceil(sqrt(num_tasks));
for (int i = 0; i < num_pipeline; i++) {
for (int j = 0; j < pipeline_height; j++) { // New nodes of 'higher' rank than all nodes generated till now
// Edges from old nodes ('nodes') to new ones ('new_nodes')
if(adj_list.find(nodes) == adj_list.end()) {
vector<int> new_list;
new_list.push_back(nodes+1);
adj_list.insert(make_pair(nodes, new_list));
}
else {
vector<int> &exist_list = adj_list[nodes];
exist_list.push_back(nodes+1);
}
if(adj_list.find(nodes+1) == adj_list.end()) {
adj_list.insert(make_pair(nodes+1, vector<int>()));
}
nodes++; // Accumulate into old node set
}
nodes++;
}
}
else if(DAG_choice == 3) { // fan in DAG
AdjList adj_list1;
adj_list1.insert(make_pair(0, vector<int>()));
int index = 0; int count = pow(MAX_CHILDREN, 0);
int num_level = floor(log(num_tasks)/log(MAX_CHILDREN));
int j = 0; int num = 1;
while(j <= num_level) {
while(index < count) {
vector<int> &exist_list = adj_list1[index];
for (int i = num; i < num+MAX_CHILDREN; i++) {
exist_list.push_back(i);
if(adj_list1.find(i) == adj_list1.end()) {
adj_list1.insert(make_pair(i, vector<int>()));
}
if(i >= num_tasks) {
index = count; j = num_level+1; break;
}
} num += MAX_CHILDREN;
index++;
}
count += pow(MAX_CHILDREN, ++j);
}
for(AdjList::iterator it = adj_list1.begin(); it != adj_list1.end(); ++it) {
int vertex = it->first;
//.........这里部分代码省略.........