Beispiel #1
0
Graph* generate_candidates(Graph* graph, char** conflict_vt,
        int conflict_c, tabu_t** tabu_list, int* tabu_pos, 
        int best_cost){

    int sorted = rand() % conflict_c;

    char* vertex_name = conflict_vt[sorted];
    int new_color = rand() % best_cost;
    int is_tabu = 0;
    for (int j = 0; j < *tabu_pos; j++){
        if (strcmp(tabu_list[j]->vertex_name, 
                    vertex_name) == 0 
                && tabu_list[j]->color == new_color){

            is_tabu = 1;
        }
    }
    if (!is_tabu){
        Graph* candidate = copy_graph(graph);
        vertex_node_t* vertex_node = get_vertex(candidate, vertex_name);
        vertex_node->color = new_color;
        tabu_list[*tabu_pos] = (tabu_t*) malloc(sizeof(tabu_t));
        vertex_node_t* tmp_vet = get_vertex(graph, vertex_node->vertex->name);
        tabu_list[*tabu_pos]->vertex_name = tmp_vet->vertex->name;
        tabu_list[*tabu_pos]->color = vertex_node->color;
        *tabu_pos += 1;
        return candidate;
    }

    return NULL;

}
Beispiel #2
0
Graph* reduce_color(Graph* graph, int cost){
    Graph* s = copy_graph(graph);

    hash_iterator_t* iter = s->begin;

    while (iter != NULL){
        vertex_node_t* vertex_node = (vertex_node_t*) iter->hash_node->value;
        if (vertex_node->color == cost){
            vertex_node->color = rand() % cost;
        }
        iter = iter->next;
    }

    return s;
}
Beispiel #3
0
Graph* initial_solution(Graph* graph){
    Graph* solution = copy_graph(graph);

    hash_iterator_t* iter = solution->begin;
    
    int color = 0;
    while (iter != NULL){
        vertex_node_t* vertex_node = (vertex_node_t*) iter->hash_node->value;

        vertex_node->color = color++;

        iter = iter->next;
    }

    return solution;
}
void dgraph::graph_sort()
{
    dgraph copy_graph(*this);
    // swap (current and compared)
    // check if visitnum is smaller if smaller then
    for(int i = 0; i < countUsed; i++){
        for(int j = 0; j < countUsed; j++){
            if(copy_graph.Gtable[i].visit <= copy_graph.Gtable[j].visit)
                swap(copy_graph.Gtable[i], copy_graph.Gtable[j]);
        }
    }

    for(int x = 0; x < copy_graph.countUsed; x++){
        cout << copy_graph.Gtable[x].vertexName << '(' << copy_graph.Gtable[x].visit << ')'<< " -> ";
    }
    
    cout << "end\n";
}
Beispiel #5
0
int minimax_threat(int player, luint m[4], int depth, int hash, int u, int v){
	//minimax ale player musí hrat na hranu (u,v) ktera je volna
//	print_adjacency_matrix(m,"");

timer++;
	luint m2[4];
	int hash2;

	if ( NORMALIZATION_FREQUENCY > 0 && depth % NORMALIZATION_FREQUENCY == 0) 
		hash = normalization(m,hash);

	int winner;
	if ( (winner = get_from_cache(m,hash) ) != 42){
//	if ( depth % 3 == 1 && (winner = get_from_cache(m,hash) ) != 42 ) {
		//je v cachy
		return winner;
	}

	if (depth == (N*(N-1))/2 )
		//vse je obarvene remiza
		//TODO diky poctu zbylych hran a tomu jake jsou hrozby by mohlo jit skoncit driv
		return 0;

	int x,y;
	int t = threats(player,m,u,v,&x,&y);
	if (t > 1){
		if (player == GREEN)
			return 1;
		else
			return -1;
	}
	copy_graph(m2,m);
	hash2 = set_edge_color(player,m2,hash,u,v);

	if (t == 1){
		winner = minimax_threat(next(player),m2,depth+1,hash2,x,y);
	} else {
		winner = minimax(next(player),m2,depth+1,hash2);
	}

	if ( depth % 3 == 1 ) 
		put_into_cache(m2,hash2,winner);	
	return winner;
}
Beispiel #6
0
  void generate_random_graph1
    (MutableGraph& g, 
     typename graph_traits<MutableGraph>::vertices_size_type V,
     typename graph_traits<MutableGraph>::vertices_size_type E,
     RandNumGen& gen,
     bool allow_parallel = true,
     bool self_edges = false)
  {
    typedef graph_traits<MutableGraph> Traits;
    typedef typename Traits::vertices_size_type v_size_t;
    typedef typename Traits::edges_size_type e_size_t;
    typedef typename Traits::vertex_descriptor vertex_descriptor;

    // When parallel edges are not allowed, we create a new graph which
    // does not allow parallel edges, construct it and copy back.
    // This is not efficient if 'g' already disallow parallel edges,
    // but that's task for later.
    if (!allow_parallel) {

      typedef typename boost::graph_traits<MutableGraph>::directed_category dir;      
      typedef typename mpl::if_<is_convertible<dir, directed_tag>,
          directedS, undirectedS>::type select;
      adjacency_list<setS, vecS, select> g2;
      generate_random_graph1(g2, V, E, gen, true, self_edges);

      copy_graph(g2, g, vertex_copy(detail::dummy_property_copier()).
                        edge_copy(detail::dummy_property_copier()));

    } else {

      for (v_size_t i = 0; i < V; ++i)
        add_vertex(g);
      
      for (e_size_t j = 0; j < E; ++j) {
        vertex_descriptor a = random_vertex(g, gen), b;
        do {
          b = random_vertex(g, gen);
        } while (self_edges == false && a == b);
        add_edge(a, b, g);
      }
    }
  }
Beispiel #7
0
	bool are_uwv_ok(const VertexListGraph& graph, Vertex uwv[]) {
		// Checking whether the FIRST and THIRD are not heighbors.
		typedef typename graph_traits<VertexListGraph>::adjacency_iterator AdjIterator;
		
		AdjIterator n_v, n_vend;
		for(tie(n_v, n_vend) = adjacent_vertices(uwv[FIRST], graph); n_v != n_vend; ++n_v) {
			if(uwv[THIRD] == *n_v)
				return false;
		}
		
		// Removing FIRST and THIRD, then checking whether graph remains connected.
		VertexListGraph temp_graph;
		copy_graph(graph, temp_graph);

		clear_vertex(uwv[FIRST], temp_graph);
		clear_vertex(uwv[THIRD], temp_graph);
		remove_vertex(uwv[FIRST], temp_graph);
		remove_vertex(uwv[THIRD], temp_graph);

		return is_graph_connected(temp_graph);
	}
//NOTE: by calling this function, the graph is modified (all connections to the root are disabled)
std::vector<Edge> Graph::getMST(int root) {
	Graph copy_graph(*this);
	std::vector<Edge> result;
	std::vector<Edge> lowest_incoming_edges;
	//first, remove all parallel edges with a single one (unimplemented)
	//second, remove all edges ending at the root 
	copy_graph.remove_edges_ending_in(root);
	//third, get a single lowest incoming edge for each vertex other than the root
	lowest_incoming_edges = copy_graph.get_min_incoming_edge();
	//delete the lowest incoming edge that ends at the root
	//Edge * temporary_edge = get_min_incoming_edge(root);
	/*for (int i = 0; i < copy_graph.no_of_vertices; i++) {
		if (i != root) {
			if (copy_graph.get_min_incoming_edge(i) != nullptr) {
				lowest_incoming_edges.push_back(*(copy_graph.get_min_incoming_edge(i)));
			}
			
		}	
	} */
	//fourth, construct a graph consisting of all the vertices and only the lowest incoming edges for all vertices except the root
	Graph lowest_edges_graph(no_of_vertices, lowest_incoming_edges);
	//lowest_edges_graph.printGraph();
	//if the graph with only the lowest incoming edges have no cycle, then the process terminates and the lowest incoming edges is the result
	//check for cycles
	//there is no cycle, then result is simply those lowest incoming edges
	if (!lowest_edges_graph.does_cycle_exist()) {
		result = lowest_incoming_edges;
		lowest_incoming_edges.clear();
	}
	/*if (!lowest_edges_graph.does_cycle_exist()) {
		result = lowest_incoming_edges;
		lowest_incoming_edges.clear(); */
	else { //otherwise, a cycle exists. Identify the cycle
		std::pair<int, int> cycle = lowest_edges_graph.get_First_Cycle();
		//define a new directed graph where the two vertices that form a cycle is "condensed" into one vertex
		/*Recreate the same graph, BUT with the two vertices that form a cycle as declared above "condensed together" in the internal representation of the graph 
		Recall that the parameter for the constructor of the graph is the number of tokens, which is number of vertices - 2
		This is because the new graph would then have precisely n-1 vertices, which is exactly what we want (condensed)*/
		Graph temp_graph(no_of_vertices - 2); 
		//clear all the edges from temp_graph to start from the beginning
		temp_graph.arr_edge.clear();
		//create a mapping for the vertices (such as vertex 1 in the original graph is equivalent with vertex 2 in the temp graph)
		//IMPLEMENT MAPPING
		std::map<int, int> mapping;
		int j = 0;
		for (int i = 0; i < copy_graph.no_of_vertices; i++) {
			if (i != std::get<0> (cycle) && i != std::get<1> (cycle)) { //if the current vertex is not one of the nodes that form a cycle
				mapping[i] = j;
				j++;
			} else {
				mapping[i] = temp_graph.no_of_vertices - 1; //reserve the last vertex of temp_graph for the "condensed vertex"
			}
		}
		//iterate over all the edges in the original graph, add the edges according to the rules for the Edmond's algorithm page in Wikipedia
		int new_idx1 = 0;
		int new_idx2 = 0;
		double temp_weight = 0.0;
		for (std::vector<Edge>::iterator it = copy_graph.arr_edge.begin(); it != copy_graph.arr_edge.end(); it++) {
			new_idx1 = mapping.find(it->getSource())->second;
			new_idx2 = mapping.find(it->getDestination())->second;
			//case 1: both vertices connected by the particular edge are not in the cycle
			if (it->getSource() != std::get<0>(cycle) && it->getSource() != std::get<1>(cycle) && it->getDestination() != std::get<1>(cycle) && it->getDestination() != std::get<0>(cycle)) {
				temp_graph.Connect(new_idx1, new_idx2, it->getWeight()); //add the edge, including its weight, (and thus both vertices) into the condensed graph
				//case 2: the source vertex belongs to the cycle but the target vertex doesn't
			} else if ((it->getSource() == std::get<0>(cycle) || it->getSource() == std::get<1>(cycle)) && it->getDestination() != std::get<0>(cycle) && it->getDestination() != std::get<1>(cycle)) { 
				temp_graph.Connect(new_idx1, new_idx2, it->getWeight());
				//case 3: the source vertex does not belong to the cycle but the target vertex does
			} else if (it->getSource() != std::get<0>(cycle) && it->getSource() != std::get<1>(cycle) && (it->getDestination() == std::get<0>(cycle) || it->getDestination() == std::get<1>(cycle))) {
				//as defined in Wikipedia, the weight is then: the weight of the edge - the weight of the lowest-weighting edge that ends at the destination vertex
				temp_weight = it->getWeight() - copy_graph.get_min_incoming_edge(it->getDestination())->getWeight();
				temp_graph.Connect(new_idx1, new_idx2, temp_weight);
			}
		}
			//perform a recursive call to find the minimum spanning tree of temp_graph
			std::vector<Edge> temp_MST = temp_graph.getMST(root);
			//First, include all the edges in the cycle:
			Edge * temp_edge = copy_graph.get_Edge(std::get<0>(cycle), std::get<1>(cycle));
			if (temp_edge != nullptr) {
				result.push_back(*temp_edge);
			}
			temp_edge = copy_graph.get_Edge(std::get<1>(cycle), std::get<0>(cycle));
			if (temp_edge != nullptr) {
				result.push_back(*temp_edge);
			}
			//second, mark all the "common edges" between copy_graph and temp_graph
			int temp_idx1;
			int temp_idx2;
			Edge * tmp_edge;
			for (std::vector<Edge>::iterator it = copy_graph.arr_edge.begin(); it != copy_graph.arr_edge.end(); it++) {
				temp_idx1 = mapping.find(it->getSource())->second;
				temp_idx2 = mapping.find(it->getDestination())->second;
				if (does_edge_exist(temp_idx1, temp_idx2, temp_MST)) { //this is a common edge between the minimum incoming edges in temp_MST and the original graph
					// get the particular edge that is being examined
					tmp_edge = get_Edge_Vector(temp_idx1, temp_idx2, temp_MST);
					//case 1: both temp_idx1 and temp_idx2 are not the "condensed" node
					if (temp_idx1 != (temp_graph.no_of_vertices - 1) && temp_idx2 != (temp_graph.no_of_vertices - 1)) {
						//then simply push the edge into the result
						result.push_back(*it);
						//case 2: the source is the condensed node but the destination is not
					} else if (temp_idx1 == (temp_graph.no_of_vertices - 1) && temp_idx2 != (temp_graph.no_of_vertices - 1)) {
						if (it->getWeight() == tmp_edge->getWeight()) { 
							result.push_back(*it);
						}
						//case 3: the source is not the condensed node but the destination is the condesed node
					} else if (temp_idx1 != (temp_graph.no_of_vertices - 1) && temp_idx2 == (temp_graph.no_of_vertices - 1)) {
						if (tmp_edge->getWeight() == (it->getWeight() - copy_graph.get_min_incoming_edge(it->getDestination())->getWeight())) {
							result.push_back(*it);
							delete_Edge(copy_graph.get_min_incoming_edge(it->getDestination())->getSource(), it->getDestination(), result);
						}
					}
				}
			}
		lowest_incoming_edges.clear();
	}
	return result;
}
 void transpose_graph(const VertexListGraph& G, MutableGraph& G_T,
                      const bgl_named_params<P, T, R>& params)
 {
   reverse_graph<VertexListGraph> Rev(G);
   copy_graph(Rev, G_T, params);
 }
 void transpose_graph(const VertexListGraph& G, MutableGraph& G_T)
 {
   reverse_graph<VertexListGraph> R(G);
   copy_graph(R, G_T);
 }
Graph * NFA_Generator::build_new_input_graph(string temp_string)
{
    Graph *temp_graph;
    if( language_map.find(temp_string) != language_map.end())  // diffinition of predefined expression
    {
        temp_graph = copy_graph(language_map.find(temp_string)->second);
    }
    else   // New input
    {
        cout<< temp_string.length() << endl;
        if( temp_string.length() > 1)
        {
            /**
            *   1- Range e.g a-z or 1-9
            *   2- Add or Multiply operation e.g \+ or \*
            *   3- Relational operation e.g \=\= or !\= or > or >\= or < or <\=
            **/
            int i = 0;
            if( temp_string[i] == '\\' || temp_string[i] == '!' ||
                    temp_string[i] == '>' || temp_string[i] == '<')  //case 2 or 3
            {

                if( temp_string[i] == '\\')
                    i++;

                if( input_map.find(temp_string[i]) == input_map.end() ) // this character not added before
                    input_map.insert(pair<char,int>(temp_string[i], input_count++));
                temp_graph = graph_builder.init_graph(string(1,temp_string[i++]));

                for( ; i < temp_string.length() ; i++ )
                {
                    if( temp_string[i] != '\\')
                    {
                        if( input_map.find(temp_string[i]) == input_map.end() ) // this character not added before
                            input_map.insert(pair<char,int>(temp_string[i], input_count++));
                        temp_graph = graph_builder.and_operation(temp_graph , graph_builder.init_graph(string(1,temp_string[i])));
                    }
                }
            }
            else  //Case 1 or error
            {
                char c = temp_string[i];
                temp_graph = graph_builder.init_graph(string(1,temp_string[i++]));

                if( input_map.find(c) == input_map.end() ) // this character not added before
                    input_map.insert(pair<char,int>(c, input_count++));
                c++;

                // skip white spaces after exp name
                while(i < temp_string.length() && (temp_string[i] == ' ' || temp_string[i] == '\t') )
                    i++;

                if( temp_string[i++] != '-')
                {
                    cout<< "Error in Grammar!" <<endl;
                    return NULL;
                }

                // skip white spaces after exp name
                while(i < temp_string.length() && (temp_string[i] == ' ' || temp_string[i] == '\t') )
                    i++;

                for(  ; c <= temp_string[i] ; c++ )  // Range a-z OR 1-9
                {
                    if( input_map.find(c) == input_map.end() ) // this character not added before
                        input_map.insert(pair<char,int>(c, input_count++));

                    temp_graph = graph_builder.or_operation(temp_graph , graph_builder.init_graph(string(1, c)));
                }
            }

        }
        else   // one char
        {
            if( input_map.find(temp_string[0]) == input_map.end() ) // this character not added before
                input_map.insert(pair<char,int>(temp_string[0], input_count++));
            temp_graph = graph_builder.init_graph(temp_string);
        }
    }
    return temp_graph;
}
void k_shell_snapshot(Graph& G, vector<int>& core, int core_num, string filename)
{
  srand(time(NULL));
  vector<int> keep_core;
  int size = num_vertices(G);
  //  long edgeCount = num_edges(G);
  vector<float> s(size,0);
  vector<float> p;
  vector<int> count(size,0);
  vector<int> indOrig(size,0);
  int ind;
  //float alpha = .2;
  //float eps   = .001;

  for(int i=0;i<core.size();i++)
    {
      if(core[i]==core_num)
	keep_core.push_back(i);
    }

  int r = 0;

  if(keep_core.size()>0)
    r = rand() % keep_core.size();
  else
    return;

  ind = keep_core[r];
  s[ind] = 1;
  /*
  p = approxPR(G,s,alpha,eps);

  for(int j=0; j<size; j++)
    {
      Vert v = vertex(j,G);
      count[j] = j;
      graph_traits<Graph>::degree_size_type outDegree = out_degree(v,G);
      p[j] = p[j]/outDegree;
    }
  

  sort(count.begin(),count.end(),compareInd<vector<float>&>(p));

  for(int j=0;j<size;j++)
    indOrig[count[j]] = j;

  long vol = 0;
  long out = 0;
  int maxC = 200;


  float c = 1.0;
  int cutInd = 0;
  for(int j=0; j<maxC; j++)
    {
      //   cout<<"Comm: "<<j<<"\n";
      vector<int>::iterator it;
	   
      Vert v    = vertex(count[j],G);
      //  cout<<"index: "<<index<<"\n";

      //Out edge iterators
      graph_traits<Graph>::out_edge_iterator out_i, out_e;

      //Create index map for Graph
      property_map<Graph, vertex_index_t>::type index = get(vertex_index, G);

      //Count outgoing edges for v
      graph_traits<Graph>::degree_size_type outDegree = out_degree(v,G);

      //update edges leaving cut set (out)
      out += outDegree;
      //update internal volume of cut set (vol)
      vol += outDegree;

      //Iterate over out going edges of v
      for(tie(out_i,out_e)=out_edges(v,G);out_i!=out_e;++out_i)
	{
	  Edge e = *out_i;
	  //	cout<<"node: "<<node1<<"\n";

	  Vert vt = target(e,G);

	  //Check if edge crosses set boundary, if so, update out and vol accordingly
	  if(indOrig[index[vt]]<j && indOrig[index[vt]]>=0)
	    {
	      out -= 2;  //note that 2 is due to outgoing/incoming edge as G is a directed graph representation of an undirected graph.
	      vol--;
	    }
	}
      //cout<<edgeCount<<"\n";
	
      //Pick minimum of cut set and complement volume
      if(vol>(edgeCount-vol))
	vol = edgeCount - vol;
      // cout<<"Comm size "<<j<<": "<<ctime2-ctime1<<"\n";
	    
	    
      //conductance c is now given by: c = out/vol
      float tempC = float(out)/vol;
	    
      //Check if this beats previous minimum
      if(tempC<c)
	{
	  c = tempC;
	  cutInd = j;
	}
    }

for(int j=0;j<=cutInd;j++)
    S.push_back(vertex(count[j],G));
  */
  vector<Vert> S;

  for(int j=0;j<=core.size();j++)
    {
      if(core[j]==core_num)
	S.push_back(vertex(j,G));
    }
  Graph localG = subset(G,S);
  //localG = connected(localG,-1);

  adjacency_list<vecS, vecS, undirectedS> localUGraph;

  copy_graph(localG,localUGraph);

  ofstream outViz;
  
  outViz.open(filename.c_str());


  write_graphviz(outViz,localUGraph);
  outViz.close();
}
Beispiel #13
0
void evaluateGeodesicDist(GridSpecs grid_specs, std::vector<Polygon_2> polygons,
                          std::vector<Point> ref_points, IOSpecs io_specs)
{

  // -- grid definition --
 
  // no. of rows and columns
  int no_rows, no_cols;
  no_rows = (int)grid_specs.getGridSpecs().at(0);
  no_cols = (int)grid_specs.getGridSpecs().at(1);

  // grid points
  int no_gpoints;
  no_gpoints = (no_rows*no_cols);

  // spatial locations of the grid points
  std::vector<Point_2> grid_points;


  // evaluating the spatial locations of the grid points
  initGrid(grid_specs, grid_points);



  //--

  // -- graph definition --

  //
  // note that two different graphs need to be considered:
  //
  // 1) effective graph -
  //    graph associated with the complementary domain;
  //    the nodes of this graph do not include the grid points
  //    associated with the polygon(s);
  //
  // 2) BGL graph -
  //    graph processed by the BGL library;
  //    this graph coincides with the grid;
  //    the nodes of this graph coincide the grid points;
  //    the nodes associated with the polygon(s) are nodes
  //    with no edges, i.e. they are nodes of degree zero;
  //
  //
  //  no. of nodes (effective graph) < no. of nodes (BGL graph)
  //  no. of edges (effective graph) = no. of edges (BGL graph)
  //


  // grid points IDs associated with the polygon(s)
  std::vector<Polygon_gp_id> gpoints_id_pgn;
  // grid points IDs associated with the graph
  std::vector<int> gpoints_id_graph;


  // project the data to the grid;
  // evaluate the grid points IDs associated with the polygon(s) and
  // those associated with the complementary domain (graph)
  projectDataToGrid(grid_points, polygons, gpoints_id_pgn, gpoints_id_graph);


  // no. of grid points associated with the polygon
  int no_gpoints_png = gpoints_id_pgn.at(0).size();
  // no. of grid points associated with the graph
  int no_gpoints_graph = gpoints_id_graph.size();

  // writing output file `Dreses.dat'
  std::string outfile_name_1("Dreses.dat");

  OutputProcess_Dreses out1(io_specs.getAbsolutePathName(outfile_name_1));
  out1.toOutput(ref_points, polygons,
                grid_specs, no_gpoints_png, no_gpoints_graph);


  grid_points.clear();
  polygons.clear();

  
  // names of the nodes (vertices)
  std::vector<std::string> node_names;
  // edges
  std::vector<Edge> edges;

  // evaluating the node names and the edges of the `effective graph'
  initGraph(grid_specs, gpoints_id_pgn, gpoints_id_graph, node_names, edges);


  gpoints_id_pgn.clear();
  gpoints_id_graph.clear();


  // number of edges
  int no_edges;
  no_edges = edges.size();

  // weights
  float* weights = new float[no_edges];

  for (int i=0; i<no_edges; i++) {
    weights[i] = grid_specs.getGridSpecs().at(2);
  }


  // BGL graph
  GridGraph g(edges.begin(), edges.end(), weights, no_gpoints);
  GridGraph g_copy(edges.begin(), edges.end(), weights, no_gpoints);


  //--
  #ifdef DEBUG_GRAPH

    std::cout << "\n>> debug - graph" << std::endl;

    std::cout << "no. of nodes (effective graph): " << node_names.size() << std::endl;
    std::cout << "no. of nodes (BGL graph): " << no_gpoints << std::endl;
    std::cout << "no. of edges: " << edges.size() << std::endl;
    write_graphviz(std::cout, g);

  #endif // DEBUG_GRAPH
  //--


  // parents of the nodes
  std::vector<vertex_descriptor> parents(num_vertices(g));

  // source node ID
  // note that node ID = (grid point ID - 1)
  int s_node_id;
  s_node_id = (getGridPointID(ref_points.at(0).first, ref_points.at(0).second, grid_specs) - 1);

  // source node
  vertex_descriptor s_node = vertex(s_node_id, g);
  // the parent of `s_node' is `s_node' (distance = 0)
  parents[s_node] = s_node;

  // distances from the source to each node
  // (including the null distances - i.e. the distance from the source to itself
  // and the distances from the source to the nodes of degree zero)
  vertices_size_type distances[no_gpoints];
  std::fill_n(distances, no_gpoints, 0);

  // evaluating the distances by using the Breadth-First Search (BFS) algorithm
  breadth_first_search(g,
                       s_node,
                       visitor(make_bfs_visitor(std::make_pair(record_distances(distances,
                                                                                on_tree_edge()),
                                                               std::make_pair(record_predecessors(&parents[0],
                                                                                                  on_tree_edge()),
                                                                              copy_graph(g_copy,
                                                                                         on_examine_edge())
                                                                             )
                                                              )
                                               )
                              )
                      );


  // writing output file `distances.dat'
  std::string outfile_name_2("distances.dat");

  OutputProcess_Distances out2(io_specs.getAbsolutePathName(outfile_name_2));
  out2.toOutput(grid_specs, no_gpoints, s_node_id, node_names, distances);


  delete [] weights;


}
Beispiel #14
0
 void transpose_graph(const VertexListGraph& G, MutableGraph& G_T)
 {
   copy_graph(make_reverse_graph(G), G_T);
 }
Beispiel #15
0
int minimax(int player, luint m[4], int depth, int hash){
	//1 zeleny vyhraje 
	//0 remiza obarvene bez k4 
	//-1 cerveny vyhraje
//	print_adjacency_matrix(m,"");
timer++;
	int max = -1;
	int min = 1;
	luint m2[4];
	int hash2 = 0;

	if ( NORMALIZATION_FREQUENCY > 0 && depth % NORMALIZATION_FREQUENCY == 0) 
		hash = normalization(m,hash);

	int winner;
	if ( (winner = get_from_cache(m,hash) ) != 42 && depth > 0){
//	if ( depth % 3 == 1 && (winner = get_from_cache(m,hash) ) != 42 ) {
		//je v cachy a zaroven neni prazdny
		return winner;
	}
	if ( depth == (N*(N-1))/2 )
		//vse je obarvene remiza
		return 0;

	for (uint i=0; i<N; i++)
		for (uint j=i+1; j<N; j++){
			if (get_edge_color(m,i,j) == 0){
				//pro vsechny neobarvene hrany (i,j)
				int x,y;
				int t = threats(player,m,i,j,&x,&y);
				if (t > 1){
					if (player == GREEN)
						return 1;
					else
						return -1;
				}
/*
				if (win(player,m,i,j)){
					if (player == GREEN)
						return 1;
					else
						return -1;
				}				
*/				copy_graph(m2,m);
				hash2 = set_edge_color(player,m2,hash,i,j);
				int tmp;
				if (t == 1){
					tmp = minimax_threat(next(player),m2,depth+1,hash2,x,y);
				} else {
					tmp = minimax(next(player),m2,depth+1,hash2);
				}
				if (tmp > max)
					max = tmp;
				if (tmp < min)
					min = tmp;
			}

				
		}
	if (player == GREEN)
		winner = max;
	else
		winner = min;

	if ( depth % 3 == 1 ) 
		put_into_cache(m2,hash2,winner);	
	return winner;
}
Beispiel #16
0
int main(int , char* [])
{
    typedef boost::adjacency_list<
    boost::mapS, boost::vecS, boost::bidirectionalS,
          boost::property<boost::vertex_color_t, boost::default_color_type,
          boost::property<boost::vertex_degree_t, int,
          boost::property<boost::vertex_in_degree_t, int,
          boost::property<boost::vertex_out_degree_t, int> > > >
          > Graph;

    Graph G(5);
    boost::add_edge(0, 2, G);
    boost::add_edge(1, 1, G);
    boost::add_edge(1, 3, G);
    boost::add_edge(1, 4, G);
    boost::add_edge(2, 1, G);
    boost::add_edge(2, 3, G);
    boost::add_edge(2, 4, G);
    boost::add_edge(3, 1, G);
    boost::add_edge(3, 4, G);
    boost::add_edge(4, 0, G);
    boost::add_edge(4, 1, G);

    typedef Graph::vertex_descriptor Vertex;

    Graph G_copy(5);
    // Array to store predecessor (parent) of each vertex. This will be
    // used as a Decorator (actually, its iterator will be).
    std::vector<Vertex> p(boost::num_vertices(G));
    // VC++ version of std::vector has no ::pointer, so
    // I use ::value_type* instead.
    typedef std::vector<Vertex>::value_type* Piter;

    // Array to store distances from the source to each vertex .  We use
    // a built-in array here just for variety. This will also be used as
    // a Decorator.
    boost::graph_traits<Graph>::vertices_size_type d[5];
    std::fill_n(d, 5, 0);

    // The source vertex
    Vertex s = *(boost::vertices(G).first);
    p[s] = s;
    boost::breadth_first_search
    (G, s,
     boost::visitor(boost::make_bfs_visitor
                    (std::make_pair(boost::record_distances(d, boost::on_tree_edge()),
                                    std::make_pair
                                    (boost::record_predecessors(&p[0],
                                            boost::on_tree_edge()),
                                     copy_graph(G_copy, boost::on_examine_edge())))) ));

    boost::print_graph(G);
    boost::print_graph(G_copy);

    if (boost::num_vertices(G) < 11) {
        std::cout << "distances: ";
#ifdef BOOST_OLD_STREAM_ITERATORS
        std::copy(d, d + 5, std::ostream_iterator<int, char>(std::cout, " "));
#else
        std::copy(d, d + 5, std::ostream_iterator<int>(std::cout, " "));
#endif
        std::cout << std::endl;

        std::for_each(boost::vertices(G).first, boost::vertices(G).second,
                      print_parent<Piter>(&p[0]));
    }

    return 0;
}
Beispiel #17
0
  void transpose_graph(const VertexListGraph& G, MutableGraph& G_T,
		       const bgl_named_params<P, T, R>& params)
  {
    copy_graph(make_reverse_graph(G), G_T, params);
  }