# Maximum\_weight\_matching changes the symmetry of the original weight matrix?

**URL:** <https://discourse.julialang.org/t/maximum-weight-matching-changes-the-symmetry-of-the-original-weight-matrix/98005>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [April 27, 2023, 6:19pm UTC](https://discourse.julialang.org/t/maximum-weight-matching-changes-the-symmetry-of-the-original-weight-matrix/98005 "2023-04-27T18:19:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OliviaPhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oliviaphillips/32/49323_2.png) [@OliviaPhillips](https://discourse.julialang.org/u/OliviaPhillips)\
**Post date:** [April 27, 2023, 6:19pm UTC](https://discourse.julialang.org/t/maximum-weight-matching-changes-the-symmetry-of-the-original-weight-matrix/98005/1 "2023-04-27T18:19:19Z")

</div>

I noticed that the maximum\_weight\_matching function seems to alter the weight matrix utilized in the matching. When I try to use the original graph in future calculations, I’m getting errors because its adjacency matrix is apparently no longer symmetric. In the following example code, the first “issymetric” function returns `true` and the second returns `false`.

```julia
sources = [1:5;1:5]
destinations = rand(1:5,10)
weights = rand(1:10,10)
fake_graph = SimpleWeightedGraph(sources,destinations,weights)
issymmetric(fake_graph.weights)
match = maximum_weight_matching(SimpleGraph(fake_graph),Gurobi.Optimizer,fake_graph.weights)
issymmetric(fake_graph.weights)

```

Is there a way to use the maximum\_weight\_matching function without altering the original graph? The alternative I can think of is to make a copy of the original graph before the matching.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [April 27, 2023, 9:22pm UTC](https://discourse.julialang.org/t/maximum-weight-matching-changes-the-symmetry-of-the-original-weight-matrix/98005/2 "2023-04-27T21:22:46Z")

</div>

Hi @OliviaPhillips!  
Indeed it’s a very annoying behavior, thanks for spotting it. It is probably due to [GraphsMatching.jl/maximum\_weight\_matching.jl at 7d14c0b345eb701f86ff20236e26a8a050994932 · JuliaGraphs/GraphsMatching.jl · GitHub](https://github.com/JuliaGraphs/GraphsMatching.jl/blob/7d14c0b345eb701f86ff20236e26a8a050994932/src/maximum_weight_matching.jl#L32-L42)  
As a quick fix, I would suggest making a copy of the weights matrix before passing it to the function. In the long run, GraphsMatching.jl will be replaced by [GitHub - gdalle/GraphsOptim.jl: A package for graph-related optimization algorithms that rely on Linear Programming.](https://github.com/gdalle/GraphsOptim.jl), but I need to find some time to get it up and running

---

<div class="post-metadata">

**Author:** ![OliviaPhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oliviaphillips/32/49323_2.png) [@OliviaPhillips](https://discourse.julialang.org/u/OliviaPhillips)\
**Post date:** [April 28, 2023, 1:07am UTC](https://discourse.julialang.org/t/maximum-weight-matching-changes-the-symmetry-of-the-original-weight-matrix/98005/3 "2023-04-28T01:07:25Z")

</div>

Copying the weights first works great for now, thanks so much!
