Witam,
Próbuję wygenerować proste dane reprezentujące strukturę grafu skierowanego. Problem polega na tym, iż przy ustawieniu ilości wierzchołków większej niż 32768, skrypt i tak wygeneruje maksymalny wierzchołek jako właśnie 32768. Rozumiem, że to wartość maksymalna int, lecz nie wiem w jaki sposób to zmienić. W skrypcie całość zapisywana jest do pliku. Zmienna odpowiedzialna za ilość wierzchołków to NUM, w poniższym kodzie ustawiona na 40000.
Pierwszy wiersz zapisywany to pliku do kolejno: minimalny wierzchołek, maksymalny wierzchołek, ilość krawędzi.
Jak przewinie się wygenerowany plik na sam koniec to minimalny wierzchołek kończy się na 32768, a powinien na 40000.
Przykładowy output z poniższego kodu (skrócony, zawiera tylko początek i koniec): https://pastebin.com/raw/c4Xp7wBC
Z góry dziękuję za pomoc.
Kod:
// A C++ Program to generate test cases for
// a weighted directed graph
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
// Define the number of runs for the test data
// generated
#define RUN 1
// Define the maximum number of vertices of the graph
#define MAX_VERTICES 50000
// Define the maximum number of edges
#define MAX_EDGES 100000
// Define the maximum weight of edges
#define MAXWEIGHT 50
int main()
{
set<pair<int, int> > container;
set<pair<int, int> >::iterator it;
// Uncomment the below line to store
// the test data in a file
freopen("test.txt", "w", stdout);
// For random values every time
srand(time(NULL));
int START = 1; // Start vertex
int NUM; // Number of Vertices
int NUMEDGE; // Number of Edges
for (int i=1; i<=RUN; i++)
{
// NUM = 1 + rand() % MAX_VERTICES;
NUM = 40000;
// Define the maximum number of edges of the graph
// Since the most dense graph can have N*(N-1)/2 edges
// where N = n number of vertices in the graph
// NUMEDGE = 1 + rand() % MAX_EDGES;
NUMEDGE = 100000;
while (NUMEDGE > NUM*(NUM-1)/2)
NUMEDGE = 1 + rand() % MAX_EDGES;
// First print the number of vertices and edges
printf("%d %d %d\n", START, NUM, NUMEDGE);
// Then print the edges of the form (a b)
// where 'a' is connected to 'b'
for (int j=1; j<=NUMEDGE; j++)
{
int a = 1 + rand() % NUM;
int b = 1 + rand() % NUM;
pair<int, int> p = make_pair(a, b);
// Search for a random "new" edge every time
// Note - In a tree the edge (a, b) is same
// as the edge (b, a)
while (container.find(p) != container.end())
{
a = 1 + rand() % NUM;
b = 1 + rand() % NUM;
p = make_pair(a, b);
}
container.insert(p);
}
for (it=container.begin(); it!=container.end(); ++it)
{
int wt = 1 + rand() % MAXWEIGHT;
printf("%d %d %d\n", it->first, it->second, wt);
}
container.clear();
// printf("\n");
}
// Uncomment the below line to store
// the test data in a file
fclose(stdout);
return(0);
}