48#ifndef __ADS_interop_metis_Metis
49 #define __ADS_interop_metis_Metis
56#if ! __has_include( <metis.h> )
57 #error "the interoperation with METIS needs the header of METIS"
106 ADS_PRE( ( ! g.directed() ) && ( k >= 1 ) && ( k <= g.n() ) );
111 idx_t n = idx_t( g.n() ) , ncon = 1 , parts = idx_t( k ) , cut = 0;
112 real_t ub = real_t( o.imbalance );
113 idx_t opt[ METIS_NOPTIONS ];
114 METIS_SetDefaultOptions( opt );
115 opt[ METIS_OPTION_NUMBERING ] = 0;
116 opt[ METIS_OPTION_SEED ] = idx_t( o.seed );
117 std::vector< idx_t > part( std::size_t( g.n() ) , 0 );
119 auto * xadj =
const_cast< idx_t *
>( I.
offsets() );
120 auto * adjncy =
const_cast< idx_t *
>( I.
heads() );
121 auto * adjwgt = o.weights ?
const_cast< idx_t *
>( I.
weights() ) :
nullptr;
124 r = ( o.recursive ? METIS_PartGraphRecursive : METIS_PartGraphKway )(
125 &n , &ncon , xadj , adjncy ,
nullptr ,
nullptr , adjwgt , &parts ,
127 opt , &cut , part.data() );
129 throw( std::runtime_error(
"ADS::metis::partition: METIS returned " +
130 std::to_string( r ) ) );
131 P.
part.assign( part.begin() , part.end() );
132 P.
cut =
static_cast< long long >( cut );
143 const Input I( g , o.weights );
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The compressed rows of a StaticGraph handed to a library that takes them as plain arrays,...
A static GRAPH for the engineered algorithms, beyond the book [see Graph.h]: the compressed sparse ro...
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
Partition partition(const G &g, const Input &I, int k, const Options &o=Options())
the partition of the nodes of into parts by METIS, on the input of (whose arrays it reads in plac...
Definition Metis.h:103
CsrInput< idx_t, idx_t > Input
the arrays of a graph for METIS: in place where the layouts agree
Definition Metis.h:96
a partition of the nodes of a graph into parts
Definition Csr.h:150
int k
the number of the parts
Definition Csr.h:153
long long cut
the weight of the edges between two parts
Definition Csr.h:152
std::vector< int > part
the part of each node, in
Definition Csr.h:151
the options of a partition by METIS
Definition Metis.h:84
int seed
the seed of METIS
Definition Metis.h:88
bool recursive
recursive bisection instead of k-way
Definition Metis.h:85
bool weights
the weights of the arcs, if any, as adjwgt
Definition Metis.h:86
double imbalance
the largest part over the mean, ubvec
Definition Metis.h:87