polish/reindent graph python wrappers and samples

This commit is contained in:
Laurent Perron
2022-10-25 20:30:41 +02:00
parent 5a127cbf3f
commit 2caae2985c
6 changed files with 37 additions and 24 deletions

View File

@@ -15,9 +15,9 @@
# [START program]
"""Solve assignment problem using linear assignment solver."""
# [START import]
from ortools.graph.python import linear_sum_assignment
import numpy as np
from ortools.graph.python import linear_sum_assignment
# [END import]
@@ -35,8 +35,10 @@ def main():
[45, 110, 95, 115],
])
# Let's transform this into 3 parallel vectors (start_nodes, end_nodes, arc_costs)
end_nodes_unraveled, start_nodes_unraveled = np.meshgrid(np.arange(costs.shape[1]),np.arange(costs.shape[0]))
# Let's transform this into 3 parallel vectors (start_nodes, end_nodes,
# arc_costs)
end_nodes_unraveled, start_nodes_unraveled = np.meshgrid(
np.arange(costs.shape[1]), np.arange(costs.shape[0]))
start_nodes = start_nodes_unraveled.ravel()
end_nodes = end_nodes_unraveled.ravel()
arc_costs = costs.ravel()

View File

@@ -15,9 +15,9 @@
# [START program]
"""From Taha 'Introduction to Operations Research', example 6.4-2."""
# [START import]
from ortools.graph.python import max_flow
import numpy as np
from ortools.graph.python import max_flow
# [END import]

View File

@@ -15,9 +15,9 @@
# [START program]
"""From Bradley, Hax and Maganti, 'Applied Mathematical Programming', figure 8.1."""
# [START import]
from ortools.graph.python import min_cost_flow
import numpy as np
from ortools.graph.python import min_cost_flow
# [END import]