inducer / pymetis

A Python wrapper around Metis, a graph partitioning package
http://mathema.tician.de/software/pymetis
Other
156 stars 32 forks source link

Support partition weights and constraints #45

Open ChenNie99 opened 2 years ago

ChenNie99 commented 2 years ago

The PyMetis provides a 'part_graph' like this:

def part_graph(nparts, adjacency=None, xadj=None, adjncy=None,
        vweights=None, eweights=None, recursive=None, contiguous=None, options=None):

And I notice the original METIS in C provides the k-way partition function like this:

int METIS_PartGraphKway(idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, 
          idx_t *vwgt, idx_t *vsize, idx_t *adjwgt, idx_t *nparts, 
          real_t *tpwgts, real_t *ubvec, idx_t *options, idx_t *objval, idx_t *part)

According to the manual, the parameter 'tpwgts' specifies the weights for each partition, but seems missing in current API.

inducer commented 2 years ago

Indeed, there's no current support for that:

https://github.com/inducer/pymetis/blob/bfa7457e19236adb3231e1afddab80c4e1899afe/src/wrapper/wrapper.cpp#L162-L165

PRs welcome.

Huangbuffer commented 1 year ago

I checked the newest code, maybe you have added the function & params into it ? but The usage method of node constrain(vweights) is not exist?

inducer commented 1 year ago

Yep, I think I merged a PR that did that.

Huangbuffer commented 1 year ago

yes,Here's another question: does this code "idx_t ncon = 1; " means "len(vweights)==len(xadj)"?

so if I want to give every node two or more weights, what should I do with the input list in python?

inducer commented 1 year ago

That feature isn't currently exposed, but I would welcome a PR that does.