Opened 2 years ago

Closed 2 years ago

# for graphs g1.union(g2) would better be weighted if both g1 and g2 are

Reported by: Owned by: vdelecroix major sage-8.1 graph theory dcoudert Vincent Delecroix David Coudert N/A 3590fb4 (Commits) 3590fb484e8b04516f643bf0ace430eb26d1b2e3

### Description

The following is wrong

```sage: g1 = Graph(weighted=True)
sage: g2 = Graph(weighted=True)
sage: g = g1.union(g2)
sage: g.weighted()
False
```

For both loops and multiedges the union takes an "or" (ie `g` allows loops if any of `g1` or `g2` allows loops). Though it is not clear that such rule should apply for weighted. Three possibilities

• make `g` weighted if any of `g1` or `g2` are
• make `g` weighted if both `g1` and `g2` are
• When `g1.weighted()` and `g2.weighted()` are different raise a `ValueError` and otherwise apply any of the two above rules.

### comment:1 Changed 2 years ago by dcoudert

I don't use weighted graph very often, so I don't know what is expected: number as label? dictionary with specific key? If we make the union weigthed if one of the graph is weighted, should we turn `None` to 0 ? what if one of the graph has `"bob"` for label ? should we check that weights are consistent ?

The easiest is certainly to raise an error.

### comment:2 Changed 2 years ago by vdelecroix

• Authors set to Vincent Delecroix
• Status changed from new to needs_review

Simpler version without errors: make it weighted if both are weighted.

### comment:3 Changed 2 years ago by vdelecroix

• Branch set to u/vdelecroix/23843
• Commit set to 3590fb484e8b04516f643bf0ace430eb26d1b2e3

### comment:4 Changed 2 years ago by dcoudert

• Reviewers set to David Coudert
• Status changed from needs_review to positive_review

Let's go for it. Passes all tests and doc build.

### comment:5 Changed 2 years ago by vbraun

• Branch changed from u/vdelecroix/23843 to 3590fb484e8b04516f643bf0ace430eb26d1b2e3
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.