struct Network_Result* calculate_performacnce() {
	struct Graph *graph1, *graph2;
	int total_graph_pairs = 0, total_vertex_pairs = 0, vertex1, vertex2, count =
			0;
	struct Network_Result *results = malloc(
			sizeof(struct Network_Result) * TOTAL_RESULTS);
	if (results == NULL) {
		PRINT_TEXT("MEM ALLOCATION FAILED");
		exit(EXIT_FAILURE);
	}

	while (total_graph_pairs++ < GRAPH_PAIRS) {
		graph1 = generate_graph_type_1();
		graph2 = generate_graph_type_2();

		total_vertex_pairs = 0;
		while (total_vertex_pairs < VERTEX_PAIRS) {
			vertex1 = rand() % MAX_VERTICES;
			do {
				vertex2 = rand() % MAX_VERTICES;
			} while (vertex1 == vertex2);
			generate_path(graph1, vertex1, vertex2);
			generate_path(graph2, vertex1, vertex2);
			generate_results(results, count++, GRAPH_TYPE_1, graph1, vertex1,
					vertex2);
			generate_results(results, count++, GRAPH_TYPE_2, graph2, vertex1,
					vertex2);
			total_vertex_pairs++;
		}
	}
	return results;
}
Пример #2
0
int main(int argc, char* argv[])
{
   //example usage:
   //dsv_filter_example <dsv file name>
   //dsv_filter_example <dsv file name> <input delimiter>
   //dsv_filter_example <dsv file name> <input delimiter> <output delimiter>

   std::string file_name        = "";
   std::string input_delimiter  = "|";
   std::string output_delimiter = "|";

   if (2 == argc)
   {
      file_name = argv[1];
   }
   else if (3 == argc)
   {
      file_name = argv[1];
      input_delimiter = argv[2];
   }
   else if (4 == argc)
   {
      file_name = argv[1];
      input_delimiter = argv[2];
      output_delimiter = argv[3];
   }

   dsv_filter filter;

   filter.set_input_delimiter(input_delimiter);
   filter.set_output_delimiter(output_delimiter);

   if (!file_name.empty())
   {
      if (filter.load(file_name))
         std::cout << "Successfully loaded " << filter.file_name() << "\n";
      else
      {
         std::cerr << "Error - Failed to load: " << file_name << std::endl;
         return 1;
      }
   }

   std::vector<bool> selected_column_list(filter.column_count(),true);

   std::deque<std::string> query_history;
   std::string query;

   for ( ; ; )
   {
      std::cout << "\nEnter query: ";
      std::getline(std::cin,query);

      strtk::remove_leading_trailing(" \t\n\r",query);

      if (query.empty())
         continue;
      else if (query_history.empty() || (query_history.back() != query))
      {
         query_history.push_back(query);
      }

      if (0 == strtk::ifind("exec",query))
      {
         if (!lookup_history(query_history,query))
            continue;
      }

      if (strtk::imatch(query,"exit") || strtk::imatch(query,"quit"))
         break;
      else if (strtk::imatch(query,"help"))
      {
         print_help();
         continue;
      }
      else if (strtk::imatch(query,"list"))
      {
         display_columns(filter);
         continue;
      }
      else if (0 == strtk::ifind("load",query))
      {
         load_dsv(query,filter);
         continue;
      }
      else if (strtk::imatch(query,"history"))
      {
         query_history.pop_back();
         display_history(query_history);
         continue;
      }
      else if (0 == strtk::ifind("output_delimiter",query))
      {
         set_output_delimiter(query,filter);
         continue;
      }
      else if (0 == strtk::ifind("input_delimiter",query))
      {
         set_input_delimiter(query,filter);
         continue;
      }
      else if ((0 == strtk::ifind("information",query)) || (0 == strtk::ifind("info",query)))
      {
         information(filter);
         continue;
      }

      selected_column_list.resize(filter.column_count(),true);
      std::fill_n(selected_column_list.begin(),selected_column_list.size(),true);

      bool count_mode = false;

      if(!parse_query(query,selected_column_list,count_mode,filter))
         continue;
      else if(filter.add_filter(query))
         generate_results(selected_column_list,filter,count_mode);
      else
      {
         std::cout << filter.error() << std::endl;
         continue;
      }
   }

   return 0;
}