sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.45k stars 481 forks source link

Meta-ticket: Unify the use of weights in graphs #13112

Open dkrenn opened 12 years ago

dkrenn commented 12 years ago

Consider the following example:

G = Graph([(1,2,0.1), (2,3,0.5), (1,3,0.3), (1,4,0.1)])  # whatever
G.min_spanning_tree(weight_function=lambda e:e[2])
w, L = T.longest_path(use_edge_labels=True)

In the last two lines, the functions are called differently, which is annoying, since one always has to look up the doc, to find out, which one is the correct.

Since both ways of calling are good (use_edge_labels simple and easy, weight_function more flexible), either should be possible for each function.

A first step is to unify the use of parameters by_weight, weight_function and check_weight

We also have to deprecate use_edge_labels and use instead by_weight, etc.

and check methods silently using if self.weighted()

CC: @sagetrac-brunellus @fchapoton @tscrim

Component: graph theory

Keywords: weight graph

Issue created by migration from https://trac.sagemath.org/ticket/13112

15606e31-f165-4fa5-94d5-bd9bfb0e1636 commented 12 years ago
comment:1

Moreover, there are arguments named "by_weight" in distance, shortest_path, shortest_path_length…

15606e31-f165-4fa5-94d5-bd9bfb0e1636 commented 12 years ago
comment:3

I would go for single argument "by_weight" with following semantics of its values:

I think this would be easy to remember. On the other side, it is quite a radical change that would require long transition period.

What do you think?

dcoudert commented 3 years ago
comment:8

I'm turning this ticket to a task since it requires a long transition period.

dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -9,4 +9,19 @@

 Since both ways of calling are good (`use_edge_labels` simple and easy, `weight_function` more flexible), either should be possible for each function.

-I would guess, that there are more functions, which are affected...
+
+
+A first step is to **unify the use of parameters `by_weight`, `weight_function` and `check_weight`**
+- #32723 Helper function to avoid duplicated code when using weights
+- 
+
+
+We also have to **deprecate `use_edge_labels`** and use instead `by_weight`, etc.
+- 
+- 
+
+
+and check methods silently using ìf self.weighted()` 
+-
+- 
+
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -13,6 +13,7 @@

 A first step is to **unify the use of parameters `by_weight`, `weight_function` and `check_weight`**
 - #32723 Helper function to avoid duplicated code when using weights
+- #32798 Clean the use of weights in `generic_graph.py` - part 1
 - 
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -14,7 +14,10 @@
 A first step is to **unify the use of parameters `by_weight`, `weight_function` and `check_weight`**
 - #32723 Helper function to avoid duplicated code when using weights
 - #32798 Clean the use of weights in `generic_graph.py` - part 1
-- 
+- #32800 Clean the use of weights in `generic_graph.py` - part 2
+- #32801 Clean the use of weights in `generic_graph.py` - part 3
+- #32802 Clean the use of weights in `graph.py`
+- #32803 Clean the use of weights in `digraph.py`

 We also have to **deprecate `use_edge_labels`** and use instead `by_weight`, etc.
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -18,6 +18,7 @@
 - #32801 Clean the use of weights in `generic_graph.py` - part 3
 - #32802 Clean the use of weights in `graph.py`
 - #32803 Clean the use of weights in `digraph.py`
+- #32804 Clean the use of weights in `path_enumeration.pyx `

 We also have to **deprecate `use_edge_labels`** and use instead `by_weight`, etc.
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -18,7 +18,8 @@
 - #32801 Clean the use of weights in `generic_graph.py` - part 3
 - #32802 Clean the use of weights in `graph.py`
 - #32803 Clean the use of weights in `digraph.py`
-- #32804 Clean the use of weights in `path_enumeration.pyx `
+- #32804 Clean the use of weights in `path_enumeration.pyx`
+- #32805 Clean the use of weights in `spanning_tree.pyx`

 We also have to **deprecate `use_edge_labels`** and use instead `by_weight`, etc.
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -20,6 +20,8 @@
 - #32803 Clean the use of weights in `digraph.py`
 - #32804 Clean the use of weights in `path_enumeration.pyx`
 - #32805 Clean the use of weights in `spanning_tree.pyx`
+- `c_graph.pyx` - depends on  #32798, #32800, #32801, #32802
+- `boost_graph.pyx` - depends on  #32798, #32800, #32801, #32802

 We also have to **deprecate `use_edge_labels`** and use instead `by_weight`, etc.
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -29,7 +29,7 @@
 - 

-and check methods silently using ìf self.weighted()` 
+and check methods silently using `if self.weighted()` 
 -
 - 
dcoudert commented 3 years ago

Description changed:

--- 
+++ 
@@ -19,7 +19,7 @@
 - #32802 Clean the use of weights in `graph.py`
 - #32803 Clean the use of weights in `digraph.py`
 - #32804 Clean the use of weights in `path_enumeration.pyx`
-- #32805 Clean the use of weights in `spanning_tree.pyx`
+- #32805 Clean the use of weights in `spanning_tree.pyx`. Method `random_spanning_tree` in #30566.
 - `c_graph.pyx` - depends on  #32798, #32800, #32801, #32802
 - `boost_graph.pyx` - depends on  #32798, #32800, #32801, #32802
dcoudert commented 2 years ago

Description changed:

--- 
+++ 
@@ -20,8 +20,8 @@
 - #32803 Clean the use of weights in `digraph.py`
 - #32804 Clean the use of weights in `path_enumeration.pyx`
 - #32805 Clean the use of weights in `spanning_tree.pyx`. Method `random_spanning_tree` in #30566.
-- `c_graph.pyx` - depends on  #32798, #32800, #32801, #32802
-- `boost_graph.pyx` - depends on  #32798, #32800, #32801, #32802
+- `c_graph.pyx` - depends on  other tickets
+- `boost_graph.pyx` - depends on  other tickets

 We also have to **deprecate `use_edge_labels`** and use instead `by_weight`, etc.
dcoudert commented 2 years ago
comment:16

Help is more than welcome for reviewing the open tickets listed in this meta-ticket.

dcoudert commented 2 years ago

Description changed:

--- 
+++ 
@@ -30,6 +30,6 @@

 and check methods silently using `if self.weighted()` 
--
+- #33562 Bad error message for weighted adjacency matrix
 - 
dcoudert commented 2 years ago

Description changed:

--- 
+++ 
@@ -31,5 +31,5 @@

 and check methods silently using `if self.weighted()` 
 - #33562 Bad error message for weighted adjacency matrix
-- 
+- `distance_graph` - requires to add parameters `by_weights`, ...