-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathmin_cost_flow.cc
69 lines (64 loc) · 3.23 KB
/
min_cost_flow.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ortools/graph/min_cost_flow.h"
#include "pybind11/numpy.h"
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"
using ::operations_research::MinCostFlowBase;
using ::operations_research::SimpleMinCostFlow;
using ::pybind11::arg;
PYBIND11_MODULE(min_cost_flow, m) {
pybind11::class_<SimpleMinCostFlow> smcf(m, "SimpleMinCostFlow");
smcf.def(pybind11::init<>());
smcf.def("add_arc_with_capacity_and_unit_cost",
&SimpleMinCostFlow::AddArcWithCapacityAndUnitCost, arg("tail"),
arg("head"), arg("capacity"), arg("unit_cost"));
smcf.def(
"add_arcs_with_capacity_and_unit_cost",
pybind11::vectorize(&SimpleMinCostFlow::AddArcWithCapacityAndUnitCost),
arg("tails"), arg("heads"), arg("capacities"), arg("unit_costs"));
smcf.def("set_arc_capacity", &SimpleMinCostFlow::SetArcCapacity, arg("arc"),
arg("capacity"));
smcf.def("set_arc_capacities",
pybind11::vectorize(&SimpleMinCostFlow::SetArcCapacity), arg("arcs"),
arg("capacities"));
smcf.def("set_node_supply", &SimpleMinCostFlow::SetNodeSupply, arg("node"),
arg("supply"));
smcf.def("set_nodes_supplies",
pybind11::vectorize(&SimpleMinCostFlow::SetNodeSupply), arg("nodes"),
arg("supplies"));
smcf.def("num_nodes", &SimpleMinCostFlow::NumNodes);
smcf.def("num_arcs", &SimpleMinCostFlow::NumArcs);
smcf.def("tail", &SimpleMinCostFlow::Tail, arg("arc"));
smcf.def("head", &SimpleMinCostFlow::Head, arg("arc"));
smcf.def("capacity", &SimpleMinCostFlow::Capacity, arg("arc"));
smcf.def("supply", &SimpleMinCostFlow::Supply, arg("node"));
smcf.def("unit_cost", &SimpleMinCostFlow::UnitCost, arg("arc"));
smcf.def("solve", &SimpleMinCostFlow::Solve);
smcf.def("solve_max_flow_with_min_cost",
&SimpleMinCostFlow::SolveMaxFlowWithMinCost);
smcf.def("optimal_cost", &SimpleMinCostFlow::OptimalCost);
smcf.def("maximum_flow", &SimpleMinCostFlow::MaximumFlow);
smcf.def("flow", &SimpleMinCostFlow::Flow, arg("arc"));
smcf.def("flows", pybind11::vectorize(&SimpleMinCostFlow::Flow), arg("arcs"));
pybind11::enum_<SimpleMinCostFlow::Status>(smcf, "Status")
.value("BAD_COST_RANGE", MinCostFlowBase::Status::BAD_COST_RANGE)
.value("BAD_CAPACITY_RANGE", MinCostFlowBase::Status::BAD_CAPACITY_RANGE)
.value("BAD_RESULT", MinCostFlowBase::Status::BAD_RESULT)
.value("FEASIBLE", MinCostFlowBase::Status::FEASIBLE)
.value("INFEASIBLE", MinCostFlowBase::Status::INFEASIBLE)
.value("NOT_SOLVED", MinCostFlowBase::Status::NOT_SOLVED)
.value("OPTIMAL", MinCostFlowBase::Status::OPTIMAL)
.value("UNBALANCED", MinCostFlowBase::Status::UNBALANCED)
.export_values();
}