Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Max flow with weighted graphs #40

Open
etiennedeg opened this issue Sep 28, 2020 · 8 comments
Open

Max flow with weighted graphs #40

etiennedeg opened this issue Sep 28, 2020 · 8 comments

Comments

@etiennedeg
Copy link
Member

It would be nice to specialize methods on weighted graphs, with weights representing the capacities. In a lot of situations, people who need flow algorithms work with weighted graphs. It also provide a sparse representation of the flow network. (without the need of an external sparse matrix).

(related : #9)

@gdalle
Copy link
Member

gdalle commented Feb 20, 2021

You should check out SimpleWeightedGraphs.jl, you may find what you are looking for.

Adapting the code yourself shouldn't be too hard, maybe something along the lines of

function maximum_flow(
        flow_graph:: swg.AbstractSimpleWeightedGraph,          # the input graph
        source::Integer,                       # the source vertex
        target::Integer,                       # the target vertex
        algorithm::AbstractFlowAlgorithm  =    # keyword argument for algorithm
        PushRelabelAlgorithm(),
        restriction::Real = 0                  # keyword argument for restriction max-flow
    )
    capacity_matrix = weights(flow_graph)'
    if restriction > 0
        return maximum_flow(flow_graph, source, target, min.(restriction, capacity_matrix), algorithm)
    end
    return maximum_flow(flow_graph, source, target, capacity_matrix, algorithm)
end

@gdalle
Copy link
Member

gdalle commented Feb 27, 2021

@matbesancon would this be a welcome addition to LightGraphsFlows or is the issue closable? (I warned you that I would tag you without mercy)

@matbesancon
Copy link
Member

Yes this can be added to this package, it's ok to make it depend on SimpleWeightedGraphs

@gdalle
Copy link
Member

gdalle commented Feb 28, 2021

I've been working on a PR but it's not as straightforward as I said above. @etienneINSA did you manage to make it work?

@simonschoelly
Copy link
Collaborator

Is there an advantage of writing a specalised methods for AbstractSimpleWeightedGraph? Wouldn't it be better to have a general method that uses the weights function for calculating the capacities? Then this functions would also work with other graph types that overload the weights function.

Also, we should make sure, that it is still possible to use a different capacity matrix with an AbstractSimpleWeightedGraph.

If we have to add a dependency on SimpleWeightedGraphs.jl, we might think about using Requires.jl to lazy load that extra code when needed.

@gdalle
Copy link
Member

gdalle commented Feb 28, 2021

Sounds like a good idea! However I'm not sure it is the only change necessary in LightGraphFlows.jl, I ran into some issues to build the residual graph from a SimpleWeightedDiGraph.
What is the procedure here, should I submit a buggy PR as a support for discussion?

@gdalle
Copy link
Member

gdalle commented Feb 28, 2021

(in case I can't debug it myself after a good night's sleep)

@matbesancon
Copy link
Member

indeed using weight makes more sense, no need to add SWG.

What is the procedure here, should I submit a buggy PR as support for discussion?

yes we can improve upon it

@gdalle gdalle mentioned this issue Mar 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants