OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::MaxFlowWithLowerBounds Struct Reference
Collaboration diagram for Slic3r::MaxFlowWithLowerBounds:

Public Member Functions

void add_edge (int from, int to, int capacity)
bool bfs ()
int dfs (int u, int f)
int solve (std::vector< int > &matching)

Public Attributes

std::vector< int > l_nodes
std::vector< int > r_nodes
std::vector< Edge > edges
std::vector< std::vector< int > > adj
std::vector< int > level
std::vector< int > it
int total_nodes { -1 }
int source_id { -1 }
int sink_id { -1 }

Detailed Description

Member Function Documentation

◆ add_edge()

void Slic3r::MaxFlowWithLowerBounds::add_edge ( int from,
int to,
int capacity )
48 {
49 adj[from].emplace_back(edges.size());
50 edges.emplace_back(from, to, capacity, 0);
51 // also add the reverse residual edge with zero capacity
52 adj[to].emplace_back(edges.size());
53 edges.emplace_back(to, from, 0, 0);
54 }
std::vector< Edge > edges
Definition ToolOrderUtils.cpp:37
std::vector< std::vector< int > > adj
Definition ToolOrderUtils.cpp:38

References adj, and edges.

◆ bfs()

bool Slic3r::MaxFlowWithLowerBounds::bfs ( )
56 {
57 level.assign(total_nodes, -1);
58 std::queue<int> q;
59 q.push(source_id);
60 level[source_id] = 0;
61
62 while (!q.empty()) {
63 int u = q.front(); q.pop();
64 for (int eid : adj[u]) {
65 Edge &e = edges[eid];
66 if (e.flow < e.capacity && level[e.to] == -1) {
67 level[e.to] = level[u] + 1;
68 q.push(e.to);
69 }
70 }
71 }
72 return level[sink_id] != -1;
73 }
@ Edge
Definition Measure.hpp:26
int source_id
Definition ToolOrderUtils.cpp:43
int sink_id
Definition ToolOrderUtils.cpp:44
int total_nodes
Definition ToolOrderUtils.cpp:42
std::vector< int > level
Definition ToolOrderUtils.cpp:39

References adj, Slic3r::Edge::capacity, edges, Slic3r::Edge::flow, level, sink_id, source_id, Slic3r::Edge::to, and total_nodes.

Referenced by solve().

Here is the caller graph for this function:

◆ dfs()

int Slic3r::MaxFlowWithLowerBounds::dfs ( int u,
int f )
75 {
76 if (u == sink_id) return f;
77 for (int &i = it[u]; i < (int)adj[u].size(); ++i) {
78 int eid = adj[u][i];
79 Edge &e = edges[eid];
80 if (e.flow < e.capacity && level[e.to] == level[u] + 1) {
81 int pushed = dfs(e.to, std::min(f, e.capacity - e.flow));
82 if (pushed > 0) {
83 e.flow += pushed;
84 edges[eid ^ 1].flow -= pushed;
85 return pushed;
86 }
87 }
88 }
89 return 0;
90 }
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124
std::vector< int > it
Definition ToolOrderUtils.cpp:40
int dfs(int u, int f)
Definition ToolOrderUtils.cpp:75

References adj, Slic3r::Edge::capacity, dfs(), edges, Slic3r::f(), Slic3r::Edge::flow, it, level, sink_id, and Slic3r::Edge::to.

Referenced by dfs(), and solve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solve()

int Slic3r::MaxFlowWithLowerBounds::solve ( std::vector< int > & matching)
92 {
93 int flow = 0;
94 while (bfs()) {
95 it.assign(total_nodes, 0);
96 while (int pushed = dfs(source_id, MaxFlowGraph::INF))
97 flow += pushed;
98 }
99
100 int L = l_nodes.size();
101 int R = r_nodes.size();
102 // collect l-r matches
103 matching.resize(l_nodes.size(), MaxFlowGraph::INVALID_ID);
104 for (int u = 0; u < L; ++u) {
105 for (int eid : adj[u]) {
106 Edge &e = edges[eid];
107 if (e.flow > 0 && e.to >= L && e.to < L + R) {
108 matching[e.from] = e.to - L;
109 }
110 }
111 }
112 return flow;
113 }
#define L(s)
Definition ExtrusionEntity.cpp:25
const int INF
Definition ToolOrderUtils.hpp:20
const int INVALID_ID
Definition ToolOrderUtils.hpp:21
std::vector< int > r_nodes
Definition ToolOrderUtils.cpp:36
bool bfs()
Definition ToolOrderUtils.cpp:56
std::vector< int > l_nodes
Definition ToolOrderUtils.cpp:35

References adj, bfs(), dfs(), edges, Slic3r::Edge::flow, Slic3r::Edge::from, Slic3r::MaxFlowGraph::INF, Slic3r::MaxFlowGraph::INVALID_ID, it, L, l_nodes, r_nodes, source_id, Slic3r::Edge::to, and total_nodes.

Here is the call graph for this function:

Member Data Documentation

◆ adj

std::vector<std::vector<int> > Slic3r::MaxFlowWithLowerBounds::adj

Referenced by add_edge(), bfs(), dfs(), and solve().

◆ edges

std::vector<Edge> Slic3r::MaxFlowWithLowerBounds::edges

Referenced by add_edge(), bfs(), dfs(), and solve().

◆ it

std::vector<int> Slic3r::MaxFlowWithLowerBounds::it

Referenced by dfs(), and solve().

◆ l_nodes

std::vector<int> Slic3r::MaxFlowWithLowerBounds::l_nodes

Referenced by solve().

◆ level

std::vector<int> Slic3r::MaxFlowWithLowerBounds::level

Referenced by bfs(), and dfs().

◆ r_nodes

std::vector<int> Slic3r::MaxFlowWithLowerBounds::r_nodes

Referenced by solve().

◆ sink_id

int Slic3r::MaxFlowWithLowerBounds::sink_id { -1 }
44{ -1 };

Referenced by bfs(), and dfs().

◆ source_id

int Slic3r::MaxFlowWithLowerBounds::source_id { -1 }
43{ -1 };

Referenced by bfs(), and solve().

◆ total_nodes

int Slic3r::MaxFlowWithLowerBounds::total_nodes { -1 }
42{ -1 };

Referenced by bfs(), and solve().


The documentation for this struct was generated from the following file: