Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <random>
- #include <ctime>
- #include <string>
- #include <fstream>
- using namespace std;
- default_random_engine eng(1);
- using Graph = vector<vector<double>>;
- string str = "C:\\Users\\asus\\Desktop\\petya\\Coursework\\Coursework\\graph.txt";
- Graph GraphGenerator(const int N) {
- Graph graph(N);
- for (int i = 0; i < N; i++) {
- graph[i].resize(N);
- }
- uniform_real_distribution<double> distr(1, 10);
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- if (i == j) {
- graph[i][j] = 0;
- continue;
- }
- graph[i][j] = distr(eng);
- }
- }
- return graph;
- }
- Graph HopfieldGraphGenerator(const int N) {
- Graph graph(N);
- for (int i = 0; i < graph.size(); i++) {
- graph[i].resize(N);
- }
- uniform_real_distribution<double> distr(1, 10);
- for (int i = 0; i < graph.size(); i++) {
- for (int j = 0; j < i; j++) {
- double dist = distr(eng);
- graph[i][j] = dist;
- graph[j][i] = dist;
- }
- }
- return graph;
- }
- void GraphWiter(const int N, const Graph& graph, const string stw) {
- ofstream gout(stw);
- gout << N << endl;
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- gout << graph[i][j] << "\t";
- }
- gout << endl;
- }
- gout.close();
- }
- void GraphReader(Graph& graph, int& N) {
- ifstream gin(str);
- gin >> N;
- graph.resize(N);
- for (int i = 0; i < N; i++) {
- graph[i].resize(N);
- }
- double dub;
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- gin >> dub;
- if (i == j) dub = INFINITY;
- graph[i][j] = dub;
- }
- }
- gin.close();
- }
- int main()
- {
- string stw;
- for (int n = 5; n <= 100; n++) {
- for (int i = 0; i < 20; i++) {
- stw = to_string(n) + "_" + to_string(i) + '.txt';
- Graph graph = HopfieldGraphGenerator(n);
- GraphWiter(n, graph, stw);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement