コード例 #1
0
graph::graph(const string &filename)
{
	ifstream graph_file(filename.c_str());
	if (!graph_file.is_open())
	{
		cout << "can't open file ..";
		return ;
	}

	stringstream convertor;
	string line_data;	
	while (getline(graph_file, line_data))
	{
		std::vector<int> inputs;
		std::istringstream in(line_data);
		std::copy(std::istream_iterator<int>(in), std::istream_iterator<int>(),
			std::back_inserter(inputs));
		size_t count_vert = 0;
		size_t count_edge = 0;
		if (inputs.size() == 1)
		{
			addVertex(inputs[0]);
			//cout << "Vertex " << ++count_vert << "-> " << inputs[0] << endl;
		}
		if (inputs.size() == 3)
		{
			addEdge(inputs[0], inputs[1], inputs[2]);
			//cout << "Edge " << ++count_edge << "-> (" << inputs[0] << " ," << inputs[1] << " ," << inputs[2] << ")\n";
		}
	}
	cout << "Graph loaded ... \n";
	graph_file.close();
}
コード例 #2
0
plotter::plotter(QWidget *parent)
    : QWidget(parent)
{
    setBackgroundRole(QPalette::Shadow);
    setAutoFillBackground(true);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    setFocusPolicy(Qt::StrongFocus);
    QString filename = QFileDialog::getOpenFileName(this, tr("Choose a Results File"),
                       "", tr("DAT Files (*.dat)"));
    QFile graph_file(filename);
    int count = 0;
    if(graph_file.open(QIODevice::ReadOnly|QIODevice::Text)) {
        while (!graph_file.atEnd()) {
            QString line = graph_file.readLine();
            QStringList fields = line.split(QRegExp("\\s+"));
            if (fields.size() == 5) {
                fields.takeFirst();
                step.push_back(fields.takeFirst().toDouble());
                rmsd.push_back(fields.takeFirst().toDouble());
                energy.push_back(fields.takeFirst().toDouble());
                count++;
            }
        }
    }
}
コード例 #3
0
ファイル: graph.cpp プロジェクト: xulifan/personal
//----------------------------------------------------------------------
//----------------------------------------------------------------------
bool Graph::load_graph() {
	std::string line, token;
	// open file
	std::ifstream graph_file(graph_fname.c_str(), std::ifstream::in);
	if (graph_file.good()) {
		// read first line (nodes and feats)
		read_trimmed_line(graph_file, line);
		std::istringstream iss(line, std::istringstream::in);
		iss >> n_nodes >> n_feats;
		// create space for all feature vectors
		feat_vecs = new DMatrix(n_nodes, n_feats);
		// read all feature vectors
		for (int i = 0 ; i < n_nodes ; i ++) {
			read_trimmed_line(graph_file, line);
			std::istringstream feats(line, std::istringstream::in);
			for (int j = 0 ; j < n_feats ; j ++) {
				feats >> feat_vecs->at(i,j);
			}
		}
		// create space for adjacency matrix
		adj_mat = new DMatrix(n_nodes, n_nodes);
		// read adjacency matrix
		for (int i = 0 ; i < n_nodes ; i ++) {
			read_trimmed_line(graph_file, line);
			std::istringstream weights(line, std::istringstream::in);
			for (int j = 0 ; j < n_nodes ; j ++) {
				weights >> adj_mat->at(i,j);
			}
		}
		// create space for shortest path adjacency matrix
		sp_adj_mat = new DMatrix(n_nodes, n_nodes);
		// transform sp adjacency matrix before applying flod warshall
		for (int i = 0 ; i < n_nodes ; i ++) {
			for (int j = 0 ; j < n_nodes ; j ++) {
				if (i != j) {
					if (adj_mat->at(i,j) == 0) {
						sp_adj_mat->set(i, j, std::numeric_limits<double>::infinity());
					} else {
						sp_adj_mat->set(i, j, adj_mat->at(i, j));
					}
				}
				// else ignore self-loops (already 0)
			}
		}
		// apply floyd warshal to the adj matrix
		for (int k = 0 ; k < n_nodes ; k ++) {
			for (int i =  0 ; i < n_nodes ; i ++) {
				for (int j = 0 ; j < n_nodes ; j ++) {
					sp_adj_mat->set(i, j, std::min(sp_adj_mat->at(i,j), sp_adj_mat->at(i,k)+sp_adj_mat->at(k,j)));
				}
			}
		}
		// close file
		graph_file.close();
		std::cout << "Log: " << n_nodes << " nodes read from " << graph_fname << std::endl;
		return true;
	}
コード例 #4
0
ファイル: gen_graph.cpp プロジェクト: hagemt/bilskirnir
int
main(int argc, char ** argv)
{
  /* Accept only two arguments */
  if (argc != 3) {
    std::cerr << "USAGE: " << argv[0] << " graph_file N" << std::endl;
    return EXIT_FAILURE;
  }

  /* Specify an output file */
  std::ofstream graph_file(argv[1]);
  if (!graph_file) {
    std::cerr << "ERROR: cannot write to '" << argv[1] << "'" << std::endl;
    return EXIT_FAILURE;
  }

  /* Parse the vertex number */
  char * residue;
  long n = 0, count = 0;
  n = strtol(argv[2], &residue, 10);
  if (n < 1 || *residue != '\0') {
    std::cerr << "ERROR: invalid N '" << argv[2] << "'" << std::endl;
    return EXIT_FAILURE;
  }

  /* Generate a graph of n possible vertices (0.5 chance of each edge) */
  std::cout << "INFO: generating graph_file '" << argv[1]
            << "' (N=" << argv[2] << ")" << std::endl;
  srand(static_cast<unsigned int>(time(NULL)));
  for (long i = 1; i <= n; ++i) {
    for (long j = i + 1; j <= n; ++j) {
      if (rand() % 2) {
        graph_file << i << ";" << j << ";" << ++count << std::endl;
      }
    }
  }

  return EXIT_SUCCESS;
}
コード例 #5
0
int main(int argc, char **argv) {
  unsigned int minsup = 1;
  unsigned int minp = 0;
  unsigned int maxpat = 10;
  bool out_instances = false;
  bool percent=false;
  int opt;
  int wildcard_num = 0;
  unsigned int maxitr = 500000;
  double nu = 0.4; 
  double conv_epsilon = 1e-2;
  unsigned int coocitr = maxitr;
  bool end_of_cooc = false;
  bool onceflag = false;

  clock_t allstart, allend;

  while ((opt = getopt(argc, argv, "m:p:w:e:oc:n:x:i")) != -1) {
    switch (opt) {
    case 'm':
      minsup = atoi (optarg);
      break;
    case 'p':
      minp = atoi (optarg);
      percent = true;
      break;
    case 'n':
      nu = atof(optarg);
      break;
    case 'c':
      coocitr = atoi(optarg);
      break;
    case 'e':
      conv_epsilon = atof(optarg);
      break;
    case 'o':
      end_of_cooc = true;
      break;
    case 'x':
      maxpat = atoi (optarg);
      break;
    case 'w':
      wildcard_num = atoi (optarg);
      break;
    case 'i':
      out_instances = true;
      break;
    default:
      std::cerr << "Usage: "<< argv[0] << OPT<< std::endl;
      return -1;
    }
  }
	
  if(argc-optind != 1){
    std::cerr << "Usage: "<< argv[0] << OPT<< std::endl;
    return -1;
  }
	
  std::ifstream graph_file(argv[optind++]);
  if(graph_file.fail()){
    std::cerr << "File not found: " << argv[optind-1] << std::endl;
    return -1;
  }
  allstart = clock();
  Gspan gspan;
  gspan.wildcard_r = wildcard_num;
  gspan.maxpat = maxpat;
  gspan.out_instances = out_instances;
  gspan.max_itr = maxitr;
  gspan.set_data(graph_file);
  gspan.minsup = minsup;
  gspan.nu = nu;
  gspan.conv_epsilon = conv_epsilon;
  gspan.coocitr = coocitr;
  gspan.end_of_cooc = end_of_cooc;
  if(percent==true){
    gspan.minsup = gspan.gdata.size() * minp * 0.9 /100;
    //std::cout<<gspan.minsup<<std::endl;
  }
  //std::cout<<gspan.gdata.size()<<std::endl;
  //gspan.run();
  gspan.lpboost();
  allend = clock();
  std::cout << "ALLTIME: " << (double)(allend - allstart)/(double)CLOCKS_PER_SEC << std::endl;
  std::cout << "Given options::" << "maxpat: " << maxpat << " minsup: " << minsup << " nu: " << nu << " conv_epsilon: " << conv_epsilon << " maxitr: " << maxitr << " once flag: " << onceflag << std::endl;

  return 0;
}