Esempio n. 1
0
void createMACGraph(ListDigraph& g, int num_paths, int path_length, ListDigraph::ArcMap<int>& demands){

	srand(time(NULL));

	ListDigraph::Node prev[num_paths];
	ListDigraph::Node current[num_paths];

	for (int i = 0; i < num_paths; ++i)
	{
		prev[i] = g.addNode();
	}
	for (int i = 0; i < path_length-1; ++i)
	{
		for (int j = 0; j < num_paths; ++j)
		{
			current[j] = g.addNode();
			g.addArc(prev[j], current[j]);
		}
		for (int j = 0; j < num_paths; ++j)
		{
			if(rand()%100 < 50){
				int targetIndex  = j;
				while(targetIndex != j){
					targetIndex = rand()%num_paths;
				}
				g.addArc(prev[j], current[targetIndex]);
			}
		}
		for (int j = 0; j < num_paths; ++j)
		{
			prev[j] = current[j];
		}

	}

	//this splits every node and sets demand for the edge between the halves to 1
	for (ListDigraph::NodeIt n(g); n != INVALID; ++n){
		ListDigraph::Node new_node = g.split(n, false);
		ListDigraph::Arc new_edge = g.addArc(n, new_node);
		demands[new_edge] = 1;
	}

}
Esempio n. 2
0
void createKPathGraph(ListDigraph& g, int k, int n, int m, ListDigraph::ArcMap<int>& weights, ListDigraph::ArcMap<int>& demands){
	srand(time(NULL));

	ListDigraph::Node* nodes[k];
	for (int i = 0; i < k; ++i)
	{
		nodes[i] = (ListDigraph::Node*) calloc(n, sizeof(ListDigraph::Node));
	}
	for (int i = 0; i < k; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			nodes[i][j] = g.addNode();
			if(j != 0) g.addArc(nodes[i][j-1], nodes[i][j]);
		}
	}
	for (int i = 0; i < m; ++i)
	{
		int k1 = rand()%k;
		int k2 = rand()%k;
		int n1 = rand()%(n-1);
		int n2 = (rand()%(n-n1-1))+n1+1;

		if(findArc(g, nodes[k1][n1], nodes[k2][n2]) == INVALID){
			g.addArc(nodes[k1][n1], nodes[k2][n2]);
		}
	}
	for (ListDigraph::ArcIt a(g); a != INVALID; ++a)
	{
		weights[a] = rand()%1000;
	}
	
	//this splits every node and sets demand for the edge between the halves to 1
	for (ListDigraph::NodeIt n(g); n != INVALID; ++n){
		ListDigraph::Node new_node = g.split(n, false);
		ListDigraph::Arc new_edge = g.addArc(n, new_node);
		demands[new_edge] = 1;
	}
	

}