Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
arc_flow_builder.h
Go to the documentation of this file.
1
// Copyright 2010-2025 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
// This code builds an arc-flow generator for vector-bin-packing problems.
15
// see https://people.math.gatech.edu/~tetali/PUBLIS/CKPT.pdf
16
// It implements a non-recursive version of algorithm 1 described in:
17
// http://www.dcc.fc.up.pt/~fdabrandao/papers/arcflow_manuscript.pdf
18
// And in (poster version):
19
// http://www.dcc.fc.up.pt/~fdabrandao/papers/arcflow_poster.pdf
20
// Available at:
21
// https://drive.google.com/open?id=1y-Vs1orv-QHO4lb2sjVWrZr9GQd5d2st
22
// https://drive.google.com/open?id=1fsWRqgNJ_3ClrhoKIeVc1EOd5s8Mj33i (poster)
23
// Some improvements are not yet implemented:
24
// - Lifted stated: when storing a state of the dynamic programming forward
25
// pass, one can lift a state. A lifted state of a state S is a maximal
26
// increase of S that does not lose any state in the forward pass.
27
// A simple example is the following:
28
// bin, 1 dimension, capacity 5
29
// 2 item of size 2.
30
// After adding item 1 in the DP pass, the state is (2).
31
// The lifted state is (3) that is (5) - (2) which is the maximal increase
32
// of (2) that does not loose any state.
33
// To limit time spent computing this, one can lift a state only if the
34
// remaining number of item is below a threshold.
35
// - Disable the backward pass (compress state towards the bin capacity).
36
// Although this reduces the graph a lot, this simplication is not valid
37
// when the cost is not the number of bins, but a function of the capacity
38
// used (useful for fair allocation).
39
40
#ifndef ORTOOLS_PACKING_ARC_FLOW_BUILDER_H_
41
#define ORTOOLS_PACKING_ARC_FLOW_BUILDER_H_
42
43
#include <cstdint>
44
#include <set>
45
#include <vector>
46
47
#include "absl/container/flat_hash_map.h"
48
#include "absl/types/span.h"
49
#include "
ortools/base/types.h
"
50
51
namespace
operations_research
{
52
namespace
packing
{
53
54
// Arc flow gragh built from a vector bin packing problem.
55
// The first node will always be the source. The last will always be the sink
56
// of the arc-flow graph.
57
struct
ArcFlowGraph
{
58
struct
Arc
{
59
int
source
;
60
int
destination
;
61
int
item_index
;
62
63
// Needed for std::set.
64
bool
operator<
(
const
Arc
& other)
const
;
65
};
66
67
std::vector<Arc>
arcs
;
68
// All the nodes explored during the DP phase.
69
// In the forward pass, these are the consumed capacity of the bin at this
70
// state. In the backward pass, this is pushed up towards the max capacity
71
// of the bin. In the final compression phase, this is pushed down towards
72
// the initial zero state.
73
std::vector<std::vector<int>>
nodes
;
74
// Debug info.
75
int64_t
num_dp_states
;
76
};
77
78
// Main method.
79
80
// Arc flow builder. The input must enforce the following constraints:
81
// - item_dimensions_by_type.size() == demand_by_type.size() == num types
82
// - for each type t:
83
// item_dimensions_by_type[t].size() == bin_dimensions.size() ==
84
// num_dimensions
85
ArcFlowGraph
BuildArcFlowGraph
(
86
const
std::vector<int>& bin_dimensions,
87
absl::Span<
const
std::vector<int>> item_dimensions_by_type,
88
absl::Span<const int> demand_by_type);
89
90
}
// namespace packing
91
}
// namespace operations_research
92
93
#endif
// ORTOOLS_PACKING_ARC_FLOW_BUILDER_H_
operations_research::packing
Definition
arc_flow_builder.cc:32
operations_research::packing::BuildArcFlowGraph
ArcFlowGraph BuildArcFlowGraph(const std::vector< int > &bin_dimensions, absl::Span< const std::vector< int > > item_dimensions_by_type, absl::Span< const int > demand_by_type)
Definition
arc_flow_builder.cc:403
operations_research
OR-Tools root namespace.
Definition
binary_indexed_tree.h:21
operations_research::packing::ArcFlowGraph::Arc
Definition
arc_flow_builder.h:58
operations_research::packing::ArcFlowGraph::Arc::item_index
int item_index
Definition
arc_flow_builder.h:61
operations_research::packing::ArcFlowGraph::Arc::source
int source
Definition
arc_flow_builder.h:59
operations_research::packing::ArcFlowGraph::Arc::operator<
bool operator<(const Arc &other) const
Definition
arc_flow_builder.cc:397
operations_research::packing::ArcFlowGraph::Arc::destination
int destination
Definition
arc_flow_builder.h:60
operations_research::packing::ArcFlowGraph
Definition
arc_flow_builder.h:57
operations_research::packing::ArcFlowGraph::arcs
std::vector< Arc > arcs
Definition
arc_flow_builder.h:67
operations_research::packing::ArcFlowGraph::num_dp_states
int64_t num_dp_states
Definition
arc_flow_builder.h:75
operations_research::packing::ArcFlowGraph::nodes
std::vector< std::vector< int > > nodes
Definition
arc_flow_builder.h:73
types.h
ortools
packing
arc_flow_builder.h
Generated by
1.15.0