Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
random_graph.h
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// A collection of functions to be used in unit tests involving the
15// ortools/graph/... library.
16
17#ifndef UTIL_GRAPH_RANDOM_GRAPH_H_
18#define UTIL_GRAPH_RANDOM_GRAPH_H_
19
20#include <memory>
21
22#include "absl/random/bit_gen_ref.h"
23#include "ortools/graph/graph.h"
24
25namespace util {
26
27// Generates a random graph where multi-arcs and self-arcs are allowed (and
28// therefore expected): exactly "num_arcs" are generated, each from a node
29// picked uniformly at random to another node picked uniformly at random.
30// Calls Build() on the graph iff "finalized" is true.
31std::unique_ptr<StaticGraph<>> GenerateRandomMultiGraph(int num_nodes,
32 int num_arcs,
33 bool finalized,
34 absl::BitGenRef gen);
35
36// Like GenerateRandomMultiGraph(), but with neither multi-arcs nor self-arcs:
37// the generated graph will have exactly num_arcs arcs. It will be picked
38// uniformly at random from the set of all simple graphs with that number of
39// nodes and arcs.
40std::unique_ptr<StaticGraph<>> GenerateRandomDirectedSimpleGraph(
41 int num_nodes, int num_arcs, bool finalized, absl::BitGenRef gen);
42
43// Like GenerateRandomDirectedSimpleGraph(), but where an undirected edge is
44// represented by two arcs: a->b and b->a. As a result, the amount of arcs in
45// the generated graph is 2*num_edges.
46std::unique_ptr<StaticGraph<>> GenerateRandomUndirectedSimpleGraph(
47 int num_nodes, int num_edges, bool finalized, absl::BitGenRef gen);
48
49} // namespace util
50
51#endif // UTIL_GRAPH_RANDOM_GRAPH_H_
A collections of i/o utilities for the Graph classes in ./graph.h.
std::unique_ptr< StaticGraph<> > GenerateRandomMultiGraph(int num_nodes, int num_arcs, bool finalized, absl::BitGenRef gen)
std::unique_ptr< StaticGraph<> > GenerateRandomDirectedSimpleGraph(int num_nodes, int num_arcs, bool finalized, absl::BitGenRef gen)
std::unique_ptr< StaticGraph<> > GenerateRandomUndirectedSimpleGraph(int num_nodes, int num_edges, bool finalized, absl::BitGenRef gen)