Classes | Typedefs | Functions
operations_research Namespace Reference

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. More...

Classes

class  BaseKnapsackSolver
 --— BaseKnapsackSolver --— This is the base class for knapsack solvers. More...
 
class  DenseDoublyLinkedList
 Specialized doubly-linked list that initially holds [0..n-1] in an arbitrary (user-specified) and fixed order. More...
 
class  DynamicPartition
 Partition class that supports incremental splitting, with backtracking. More...
 
class  DynamicPermutation
 Maintains a 'partial' permutation of [0..n-1] onto itself, with a dynamic API allowing it to be built incrementally, and allowing some backtracking. More...
 
class  GraphSymmetryFinder
 
struct  KnapsackAssignment
 --— KnapsackAssignement --— KnapsackAssignement is a small struct used to pair an item with its assignment. More...
 
class  KnapsackCapacityPropagator
 --— KnapsackCapacityPropagator --— KnapsackCapacityPropagator is a KnapsackPropagator used to enforce a capacity constraint. More...
 
class  KnapsackGenericSolver
 --— KnapsackGenericSolver --— KnapsackGenericSolver is the multi-dimensional knapsack solver class. More...
 
struct  KnapsackItem
 --— KnapsackItem --— KnapsackItem is a small struct to pair an item weight with its corresponding profit. More...
 
class  KnapsackPropagator
 --— KnapsackPropagator --— KnapsackPropagator is the base class for modeling and propagating a constraint given an assignment. More...
 
class  KnapsackSearchNode
 --— KnapsackSearchNode --— KnapsackSearchNode is a class used to describe a decision in the decision search tree. More...
 
class  KnapsackSearchPath
 --— KnapsackSearchPath --— KnapsackSearchPath is a small class used to represent the path between a node to another node in the search tree. More...
 
class  KnapsackSolver
 
class  KnapsackState
 --— KnapsackState --— KnapsackState represents a partial solution to the knapsack problem. More...
 
class  MergingPartition
 Partition class that supports incremental merging, using the union-find algorithm (see http://en.wikipedia.org/wiki/Disjoint-set_data_structure). More...
 
class  SparsePermutation
 A compact representation for permutations of {0..N-1} that displaces few elements: it needs only O(K) memory for a permutation that displaces K elements. More...
 

Typedefs

typedef KnapsackItemKnapsackItemPtr
 

Functions

void MinimizeLinearAssignment (const std::vector< std::vector< double > > &cost, absl::flat_hash_map< int, int > *direct_assignment, absl::flat_hash_map< int, int > *reverse_assignment)
 See IMPORTANT NOTE at the top of the file. More...
 
void MaximizeLinearAssignment (const std::vector< std::vector< double > > &cost, absl::flat_hash_map< int, int > *direct_assignment, absl::flat_hash_map< int, int > *reverse_assignment)
 See IMPORTANT NOTE at the top of the file. More...
 
Select next search node to expand Select next item_i to assign (using master propagator) - Generate a new search node where item_i is in the knapsack - Check validity of this new partial solution(using propagators) - If valid
 The following code defines needed classes for the KnapsackGenericSolver class which is the entry point to extend knapsack with new constraints such as conflicts between items. More...
 
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution (using propagators) - If valid
 

Detailed Description

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.

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.

Todo:
(user,user): refine this toplevel comment when this file settles.

Two dynamic partition classes: one that incrementally splits a partition into more and more parts; one that incrementally merges a partition into less and less parts.

GLOSSARY: The partition classes maintain a partition of N integers 0..N-1 (aka "elements") into disjoint equivalence classes (aka "parts").

SAFETY: Like std::vector<int> crashes when used improperly, these classes are not "safe": most of their methods may crash if called with invalid arguments. The client code is responsible for using this class properly. A few DCHECKs() will help catch bugs, though.

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. This class solves the graph automorphism problem (https://en.wikipedia.org/wiki/Graph_automorphism), a variant of the famous graph isomorphism problem (https://en.wikipedia.org/wiki/Graph_isomorphism).

The algorithm is largely based on the following article, published in 2008: "Faster Symmetry Discovery using Sparsity of Symmetries" by Darga, Sakallah and Markov. http://web.eecs.umich.edu/~imarkov/pubs/conf/dac08-sym.pdf.

See the comments on the class below for more details.

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. IMPORTANT NOTE: we advise using the code in graph/linear_assignment.h whose complexity is usually much smaller.

Todo:
(user): base this code on LinearSumAssignment.

An O(n^4) implementation of the Kuhn-Munkres algorithm (a.k.a. the Hungarian algorithm) for solving the assignment problem. The assignment problem takes a set of agents, a set of tasks and a cost associated with assigning each agent to each task and produces an optimal (i.e., least cost) assignment of agents to tasks. The code also enables computing a maximum assignment by changing the input matrix.

This code is based on (read: translated from) the Java version (read: translated from) the Python version at http://www.clapper.org/software/python/munkres/.

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. This library solves knapsacks:

Given n items, each with a profit and a weight, given a knapsack of capacity c, the goal is to find a subset of items which fits inside c and maximizes the total profit. The knapsack problem can easily be extended from 1 to d dimensions. As an example, this can be useful to constrain the maximum number of items inside the knapsack. Without loss of generality, profits and weights are assumed to be positive.

From a mathematical point of view, the multi-dimensional knapsack problem can be modeled by d linear constraints: ForEach(j:1..d)(Sum(i:1..n)(weight_ij * item_i) <= c_j where item_i is a 0-1 integer variable. Then the goal is to maximize: Sum(i:1..n)(profit_i * item_i).

There are several ways to solve knapsack problems. One of the most efficient ways is based on dynamic programming (mainly when weights, profits and dimensions are small, the algorithm runs in pseudo polynomial time). Unfortunately when adding conflict constraints the problem becomes strongly NP-hard, i.e. there is no pseudo-polynomial algorithm to solve it. That's the reason why the most of the following code is based on branch and bound search.

For instance to solve a 2-dimensional knapsack problem with 9 items, one just has to feed a profit vector with the 9 profits, a vector of 2 vectors for weights, and a vector of capacities. E.g.: vector: profits = [1, 2, 3, 4, 5, 6, 7, 8, 9] vector of vector: weights = [ [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 1, 1, 1, 1, 1, 1, 1]] vector: capacities = [34, 4] And then: KnapsackSolver solver( KnapsackSolver::KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, "Multi-dimensional solver"); solver.Init(profits, weights, capacities); int64 profit = solver.Solve();

Currently four algorithms are implemented:

KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER: Limited to one dimension, this solver is based on a dynamic programming algorithm. The time and space complexity is O(capacity * number_of_items).

Typedef Documentation

◆ KnapsackItemPtr

Definition at line 249 of file knapsack_solver.h.

Function Documentation

◆ assign()

Select next search node to expand Select next item_i to operations_research::assign ( using master  propagator)
new

The following code defines needed classes for the KnapsackGenericSolver class which is the entry point to extend knapsack with new constraints such as conflicts between items.

Constraints are enforced using KnapsackPropagator objects, in the current code there is one propagator per dimension (KnapsackCapacityPropagator). One of those propagators, named master propagator, is used to guide the search, i.e. decides which item should be assigned next. Roughly speaking the search algorithm is:

  • While not optimal

◆ MaximizeLinearAssignment()

void operations_research::MaximizeLinearAssignment ( const std::vector< std::vector< double > > &  cost,
absl::flat_hash_map< int, int > *  direct_assignment,
absl::flat_hash_map< int, int > *  reverse_assignment 
)

See IMPORTANT NOTE at the top of the file.

◆ MinimizeLinearAssignment()

void operations_research::MinimizeLinearAssignment ( const std::vector< std::vector< double > > &  cost,
absl::flat_hash_map< int, int > *  direct_assignment,
absl::flat_hash_map< int, int > *  reverse_assignment 
)

See IMPORTANT NOTE at the top of the file.

◆ solution()

Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial operations_research::solution ( using  propagators)