Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
gen_rand_graph.C
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
175# include <sys/resource.h>
176# include <tpl_sgraph.H>
177# include <tpl_agraph.H>
178# include <io_graph.H>
179# include <random_graph.H>
180# include <euclidian-graph-common.H>
181# include <tclap/CmdLine.h>
182
183bool verbose = false;
184
185using namespace Aleph;
186using namespace std;
187
188
190
191
192int main(int argc, char * argv[])
193{
194 TCLAP::CmdLine cmd("Generate random euclidian graph", ' ', "1.0");
195
196 TCLAP::ValueArg<size_t> nArg("n", "nodes", "Number of nodes", false, 100, "size_t");
197 TCLAP::ValueArg<size_t> mArg("m", "edges", "Number of edges", false, 1000, "size_t");
198 TCLAP::ValueArg<int> wArg("W", "width", "Width", false, 1000, "int");
199 TCLAP::ValueArg<int> hArg("H", "height", "Height", false, 1000, "int");
200 TCLAP::ValueArg<unsigned int> seedArg("s", "seed", "Random seed", false, 0, "unsigned int");
201 TCLAP::UnlabeledValueArg<string> fileArg("file", "Output file name", false, "", "string");
202
203 cmd.add(nArg);
204 cmd.add(mArg);
205 cmd.add(wArg);
206 cmd.add(hArg);
207 cmd.add(seedArg);
208 cmd.add(fileArg);
209
210 try {
211 cmd.parse(argc, argv);
212 } catch (TCLAP::ArgException &e) {
213 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
214 return 1;
215 }
216
217 size_t n = nArg.getValue();
218 size_t m = mArg.getValue();
219 int w = wArg.getValue();
220 int h = hArg.getValue();
221 unsigned int seed = seedArg.getValue();
222 string fileName = fileArg.getValue();
223
224 if (seed == 0)
225 seed = time(nullptr);
226
227 cout << argv[0] << " " << n << " " << m << " " << w << " " << h << " "
228 << seed << endl;
229
230 cout << "Preparing system stack size to 256 Mb ... " << endl
231 << endl;
232
233 const rlim_t kStackSize = 256 * 1024 * 1024; // min stack size = 16 MB
234 struct rlimit rl;
235 int result;
236
237 result = getrlimit(RLIMIT_STACK, &rl);
238 if (result == 0)
239 if (rl.rlim_cur < kStackSize)
240 {
241 rl.rlim_cur = kStackSize;
242 result = setrlimit(RLIMIT_STACK, &rl);
243 if (result != 0)
244 fprintf(stderr, "setrlimit returned result = %d\n", result);
245 else
246 cout << "OK. done!" << endl
247 << endl;
248 }
249
250 cout << "Generating graph ... " << endl;
251
252 Graph g = gen_random_euclidian_graph<Graph>(n, m, w, h, seed);
253
254 if (fileName != "")
255 {
256 ofstream out(fileName);
258 (g).save_in_text_mode(out);
259 }
260 else
262 (g).save_in_text_mode(cout);
263}
int main()
long double h
Definition btreepic.C:154
long double w
Definition btreepic.C:153
Graph serialization and deserialization class.
Definition io_graph.H:319
Common utilities for Euclidean graphs.
Array_Graph< Graph_Anode< My_P >, Graph_Aarc< int > > Graph
Graph serialization and deserialization utilities.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
bool verbose
Flag enabling verbose output.
Definition ahDefs.C:45
DynList< T > maps(const C &c, Op op)
Classic map operation.
STL namespace.
Random graph generation utilities.
Array-based graph implementation.
Simple graph implementation with adjacency lists.