Advertisement
mamamaria

Untitled

Apr 17th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <random>
  5. #include <ctime>
  6. #include <string>
  7. #include <fstream>
  8. using namespace std;
  9.  
  10. default_random_engine eng(1);
  11. using Graph = vector<vector<double>>;
  12. string str = "C:\\Users\\asus\\Desktop\\petya\\Coursework\\Coursework\\graph.txt";
  13. Graph GraphGenerator(const int N) {
  14.     Graph graph(N);
  15.     for (int i = 0; i < N; i++) {
  16.         graph[i].resize(N);
  17.     }
  18.     uniform_real_distribution<double> distr(1, 10);
  19.     for (int i = 0; i < N; i++) {
  20.         for (int j = 0; j < N; j++) {
  21.             if (i == j) {
  22.                 graph[i][j] = 0;
  23.                 continue;
  24.             }
  25.             graph[i][j] = distr(eng);
  26.         }
  27.     }
  28.     return graph;
  29. }
  30.  
  31. Graph HopfieldGraphGenerator(const int N) {
  32.     Graph graph(N);
  33.     for (int i = 0; i < graph.size(); i++) {
  34.         graph[i].resize(N);
  35.     }
  36.     uniform_real_distribution<double> distr(1, 10);
  37.     for (int i = 0; i < graph.size(); i++) {
  38.         for (int j = 0; j < i; j++) {
  39.             double dist = distr(eng);
  40.             graph[i][j] = dist;
  41.             graph[j][i] = dist;
  42.         }
  43.     }
  44.     return graph;
  45. }
  46. void GraphWiter(const int N, const Graph& graph, const string stw) {
  47.     ofstream gout(stw);
  48.     gout << N << endl;
  49.     for (int i = 0; i < N; i++) {
  50.         for (int j = 0; j < N; j++) {
  51.             gout << graph[i][j] << "\t";
  52.         }
  53.         gout << endl;
  54.     }
  55.     gout.close();
  56. }
  57. void GraphReader(Graph& graph, int& N) {
  58.     ifstream gin(str);
  59.     gin >> N;
  60.     graph.resize(N);
  61.     for (int i = 0; i < N; i++) {
  62.         graph[i].resize(N);
  63.     }
  64.     double dub;
  65.     for (int i = 0; i < N; i++) {
  66.         for (int j = 0; j < N; j++) {
  67.             gin >> dub;
  68.             if (i == j) dub = INFINITY;
  69.             graph[i][j] = dub;
  70.         }
  71.     }
  72.     gin.close();
  73. }
  74.  
  75. int main()
  76. {
  77.  
  78.     string stw;
  79.     for (int n = 5; n <= 100; n++) {
  80.         for (int i = 0; i < 20; i++) {
  81.             stw = to_string(n) + "_" + to_string(i) + '.txt';
  82.             Graph graph = HopfieldGraphGenerator(n);
  83.             GraphWiter(n, graph, stw);
  84.         }
  85.     }
  86.    
  87.  
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement